-
Notifications
You must be signed in to change notification settings - Fork 0
/
gosuvctr.go
87 lines (78 loc) · 1.57 KB
/
gosuvctr.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"encoding/base64"
"log"
"os"
"path/filepath"
"github.com/urfave/cli"
)
var (
version string
config Configuration
key string
remoteURL string
)
func init() {
log.SetFlags(log.LstdFlags | log.Llongfile)
version = "master"
}
func main() {
defaultConfigPath := filepath.Join(DefaultCtrDir(), "conf/config.json")
app := cli.NewApp()
app.Name = "gosuv controller"
app.Usage = "Controller for gosuv administrator"
app.Version = version
app.Before = func(c *cli.Context) error {
var err error
configPath := c.GlobalString("conf")
config, err = readConfig(configPath)
if err != nil {
log.Fatal(err)
}
getKey()
remoteURL = "http://" + config.RemoteAddr + ":" + config.RemotePort
return nil
}
app.Authors = []cli.Author{
cli.Author{
Name: "Gavin",
},
}
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "conf, c",
Usage: "config file",
Value: defaultConfigPath,
},
}
app.Commands = []cli.Command{
{
Name: "shutdown",
Usage: "Shutdown the remote gosuv",
Action: shutdownGosuv,
},
{
Name: "status",
Usage: "Check remote gosuv status",
Action: statusGosuv,
},
{
Name: "start",
Usage: "Start remote gosuv program",
Action: startProgram,
},
{
Name: "stop",
Usage: "Stop remote gosuv program",
Action: stopProgram,
},
}
if err := app.Run(os.Args); err != nil {
os.Exit(1)
}
}
func getKey() {
plainKey := config.Admin.Username + ":" + config.Admin.Password
cryptoKey := base64.StdEncoding.EncodeToString([]byte(plainKey))
key = "Basic " + cryptoKey
}