| 298 | } |
| 299 | |
| 300 | func (h *handler) Execute(_ []string, r <-chan svc.ChangeRequest, s chan<- svc.Status) (bool, uint32) { |
| 301 | s <- svc.Status{State: svc.StartPending, Accepts: 0} |
| 302 | // Unblock initService() |
| 303 | h.fromsvc <- nil |
| 304 | |
| 305 | // Wait for initialization to complete. |
| 306 | failed := <-h.tosvc |
| 307 | if failed { |
| 308 | log.G(context.TODO()).Debug("Aborting service start due to failure during initialization") |
| 309 | return true, 1 |
| 310 | } |
| 311 | |
| 312 | s <- svc.Status{State: svc.Running, Accepts: svc.AcceptStop | svc.AcceptShutdown | svc.AcceptParamChange} |
| 313 | log.G(context.TODO()).Debug("Service running") |
| 314 | Loop: |
| 315 | for { |
| 316 | select { |
| 317 | case failed = <-h.tosvc: |
| 318 | break Loop |
| 319 | case c := <-r: |
| 320 | switch c.Cmd { |
| 321 | case svc.ParamChange: |
| 322 | h.daemonCLI.reloadConfig() |
| 323 | case svc.Interrogate: |
| 324 | s <- c.CurrentStatus |
| 325 | case svc.Stop, svc.Shutdown: |
| 326 | s <- svc.Status{State: svc.StopPending, Accepts: 0} |
| 327 | h.daemonCLI.stop() |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | removePanicFile() |
| 333 | if failed { |
| 334 | return true, 1 |
| 335 | } |
| 336 | return false, 0 |
| 337 | } |
| 338 | |
| 339 | func initPanicFile(path string) error { |
| 340 | var err error |