forked from elysium-suite/aeacus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phocus_windows.go
82 lines (71 loc) · 1.63 KB
/
phocus_windows.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
// +build phocus
package main
import (
"flag"
"fmt"
"log"
"os"
"sync"
"time"
"github.com/elysium-suite/aeacus/cmd"
"github.com/judwhite/go-svc"
)
func phocusStart(quit chan struct{}) {
app := cmd.GenPhocusApp()
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
// idgui is set using the flag package in order to grab its value before
// the Windows service is initialized.
var idgui *bool = flag.Bool("i", false, "Spawn TeamID gui")
// Program implements svc.Service, for Windows Services.
type program struct {
wg sync.WaitGroup
quit chan struct{}
}
// main for phocus_windows.go will
func main() {
flag.Parse()
prg := &program{}
if err := svc.Run(prg); err != nil {
log.Fatal(err)
}
}
// Init for our windows service *program will prevent people from running
// the production binary outside of the Windows service.
func (p *program) Init(env svc.Environment) error {
if !env.IsWindowsService() && !*idgui {
fmt.Println("Sorry! Don't run this binary yourself. It's probably already running as a Windows service (CSSClient).")
time.Sleep(5 * time.Second)
os.Exit(1)
}
return nil
}
func (p *program) Start() error {
p.quit = make(chan struct{})
p.wg.Add(1)
if *idgui {
go launchIDPromptWrapper(p.quit)
} else {
go phocusStart(p.quit)
}
return nil
}
func (p *program) Stop() error {
log.Println("Stopping...")
close(p.quit)
os.Exit(1)
/*
Causes windows service stopping error (but it works)
Quit struct doesn't work... todo
p.wg.Wait()
log.Println("Stopped.")
*/
return nil
}
func launchIDPromptWrapper(quit chan struct{}) {
cmd.LaunchIDPrompt()
os.Exit(0) // This is temporary solution
}