File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 "fmt"
88 "math/rand"
99 "os"
10+ "os/signal"
1011 "runtime"
11- "sync "
12+ "syscall "
1213
1314 "github.com/jedisct1/dlog"
1415 "github.com/kardianos/service"
@@ -20,8 +21,7 @@ const (
2021)
2122
2223type App struct {
23- wg sync.WaitGroup
24- quit chan struct {}
24+ quit chan os.Signal
2525 proxy * Proxy
2626 flags * ConfigFlags
2727}
@@ -120,18 +120,17 @@ func main() {
120120 dlog .Fatal (err )
121121 }
122122 } else {
123- app .Start (nil )
123+ app .quit = make (chan os.Signal , 1 )
124+ signal .Notify (app .quit , os .Interrupt , syscall .SIGTERM )
125+ // Possible to exit while initializing
126+ go app .AppMain ()
127+ <- app .quit
128+ dlog .Notice ("Quit signal received..." )
124129 }
125130}
126131
127132func (app * App ) Start (service service.Service ) error {
128- if service != nil {
129- go func () {
130- app .AppMain ()
131- }()
132- } else {
133- app .AppMain ()
134- }
133+ go app .AppMain ()
135134 return nil
136135}
137136
@@ -149,13 +148,8 @@ func (app *App) AppMain() {
149148 if err := app .proxy .InitHotReload (); err != nil {
150149 dlog .Warnf ("Failed to initialize hot-reloading: %v" , err )
151150 }
152- app .quit = make (chan struct {})
153- app .wg .Add (1 )
154151 app .proxy .StartProxy ()
155152 runtime .GC ()
156- <- app .quit
157- dlog .Notice ("Quit signal received..." )
158- app .wg .Done ()
159153}
160154
161155func (app * App ) Stop (service service.Service ) error {
You can’t perform that action at this time.
0 commit comments