-
Notifications
You must be signed in to change notification settings - Fork 1
/
entry.go
84 lines (75 loc) · 1.72 KB
/
entry.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
package main
import (
"fmt"
"github.com/oliveagle/ole_tryout_daemon/config"
"github.com/oliveagle/ole_tryout_daemon/servicelib"
// "github.com/spf13/viper"
"log"
"os"
"strings"
)
const (
version = "v0.0.1"
svcName = "oleservice"
svcDesc = "ole service description"
port = ":9977"
)
func usage(errmsg string) {
fmt.Fprintf(os.Stderr,
"%s\n\n"+
"usage: %s <command>\n"+
" where <command> is one of\n"+
" install, remove, status, start, stop, pause or continue.\n",
errmsg, os.Args[0])
os.Exit(2)
}
func main() {
// - log --------------------
f, err := os.OpenFile(getLogFilePath(), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
fmt.Printf("error opening file: %v \n", err)
}
defer f.Close()
log.SetOutput(f)
// -------------------- log -
config.SetDefault()
srv := servicelib.NewService(svcName, svcDesc)
if len(os.Args) >= 2 {
log.Println("new func main\r\n")
cmd := strings.ToLower(os.Args[1])
switch cmd {
case "install":
err = srv.InstallService()
case "remove":
err = srv.RemoveService()
case "start":
err = srv.StartService()
case "stop":
err = srv.StopService()
case "pause":
err = srv.PauseService()
case "continue":
err = srv.ContinueService()
case "status":
err = srv.Status()
case "config":
err = srv.Config()
default:
usage(fmt.Sprintf("invalid command %s", cmd))
}
if err != nil {
log.Fatalf("failed to %s %s: %v", cmd, svcName, err)
}
} else {
isIntSess, err := srv.IsAnInteractiveSession()
if err != nil {
log.Fatalf("failed to determine if we are running in an interactive session: %v", err)
}
if !isIntSess {
runService(svcName, false)
return
}
// runService(svcName, false)
}
return
}