/
service.go
41 lines (34 loc) · 1008 Bytes
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"os"
"time"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/fernandezvara/nomadpanel/api"
"github.com/fernandezvara/nomadpanel/usage"
nomadapi "github.com/hashicorp/nomad/api"
)
func cliStart(c *cli.Context) {
config := nomadapi.DefaultConfig()
config.Address = c.GlobalString("nomad-address")
config.Region = c.GlobalString("nomad-region")
config.WaitTime = time.Duration(c.GlobalInt("wait-time")) * time.Second
client, err := nomadapi.NewClient(config)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
log := logrus.New()
level, err := logrus.ParseLevel(c.GlobalString("log-level"))
if err != nil {
fmt.Println("incorrect log-level")
os.Exit(2)
}
log.Out = os.Stderr
log.Level = level
usage := usage.NewUsage(client, time.Duration(c.GlobalInt("wait-time"))*time.Second, log)
usage.Loop()
context := api.NewContext(c.GlobalString("api-addr"), serviceVersion, usage, log, client)
log.Fatal(api.ListenAndServe(context))
}