{"action":"created","issue":{"url":"https://api.github.com/repos/kardianos/service/issues/57","repository_url":"https://api.github.com/repos/kardianos/service","labels_url":"https://api.github.com/repos/kardianos/service/issues/57/labels{/name}","comments_url":"https://api.github.com/repos/kardianos/service/issues/57/comments","events_url":"https://api.github.com/repos/kardianos/service/issues/57/events","html_url":"https://github.com/kardianos/service/issues/57","id":140226181,"number":57,"title":"Log message in function Stop","user":{"login":"kless","id":16563,"avatar_url":"https://avatars.githubusercontent.com/u/16563?v=3","gravatar_id":"","url":"https://api.github.com/users/kless","html_url":"https://github.com/kless","followers_url":"https://api.github.com/users/kless/followers","following_url":"https://api.github.com/users/kless/following{/other_user}","gists_url":"https://api.github.com/users/kless/gists{/gist_id}","starred_url":"https://api.github.com/users/kless/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kless/subscriptions","organizations_url":"https://api.github.com/users/kless/orgs","repos_url":"https://api.github.com/users/kless/repos","events_url":"https://api.github.com/users/kless/events{/privacy}","received_events_url":"https://api.github.com/users/kless/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-11T16:18:04Z","updated_at":"2016-03-11T16:46:34Z","closed_at":null,"body":"I don't know if this issue is a bug, but when I stop the service, it does not logs the messages in function 'Stop' (quit 3). In addition, it should log other messages like \"quit 1\" and \"quit 2\".\r\nI don't know if it's a problem due to my code.\r\n\r\n```\r\npackage main\r\n\r\nimport (\r\n\t\"flag\"\r\n\t\"os\"\r\n\t\"time\"\r\n\r\n\tlog \"github.com/Sirupsen/logrus\"\r\n\t\"github.com/kardianos/service\"\r\n)\r\n\r\nvar (\r\n\tFlagInstall   = flag.Bool(\"install\", false, \"install setups up the service in the OS\")\r\n\tFlagUninstall = flag.Bool(\"uninstall\", false, \"uninstall removes the service from the OS\")\r\n)\r\n\r\nfunc main() {\r\n\tflag.Parse()\r\n\r\n\tserviceConfig := &service.Config{\r\n\t\tName:        \"foo\",\r\n\t\tDisplayName: \"Foo daemon\",\r\n\t\tDescription: \"tester of daemon\",\r\n\t\tUserName:    \"ubuntu\",\r\n\t\t//Arguments:   []string{},\r\n\t}\r\n\r\n\tserv, err := service.New(Program{}, serviceConfig)\r\n\tif err != nil {\r\n\t\tlog.Fatal(err)\r\n\t}\r\n\tserviceManager := service.ChosenSystem()\r\n\r\n\tif *FlagInstall {\r\n\t\tif !serviceManager.Detect() {\r\n\t\t\tlog.Fatal(\"the service manager of this system is not available\")\r\n\t\t}\r\n\t\tif err = serv.Install(); err != nil {\r\n\t\t\tlog.Fatal(err)\r\n\t\t}\r\n\t\tos.Exit(0)\r\n\t} else if *FlagUninstall {\r\n\t\tif err = serv.Uninstall(); err != nil {\r\n\t\t\tlog.Fatal(err)\r\n\t\t}\r\n\t\tos.Exit(0)\r\n\t}\r\n\r\n\tif err = serv.Run(); err != nil {\r\n\t\tlog.Fatal(err)\r\n\t}\r\n}\r\n\r\ntype Program struct {\r\n\tservice service.Service\r\n\t//cron    *cron.Cron\r\n\r\n\tIsRunning bool\r\n\tquit      chan bool\r\n}\r\n\r\nfunc (p Program) Start(s service.Service) error {\r\n\tp.service = s\r\n\tp.quit = make(chan bool)\r\n\r\n\tticker := time.NewTicker(20*time.Second)\r\n\tfor {\r\n\t\tselect {\r\n\t\tcase <-ticker.C:\r\n\t\t\tif p.IsRunning {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tp.IsRunning = true\r\n\t\t\tlog.Info(\"+\") // function to run for a long time\r\n\t\t\tp.IsRunning = false\r\n\r\n\t\tcase <-p.quit:\r\n\t\t\tlog.Info(\"quit 1\")\r\n\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\r\n\tlog.Info(\"quit 2\")\r\n\tticker.Stop()\r\n\tclose(p.quit)\r\n\r\n\treturn nil\r\n}\r\n\r\nfunc (p Program) Stop(s service.Service) error {\r\n\tfor i := 0; i < 6; i++ {\r\n\t\tif p.IsRunning {\r\n\t\t\ttime.Sleep(5*time.Second)\r\n\t\t\tcontinue\r\n\t\t} else {\r\n\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\r\n\tp.quit <- true\r\n\tlog.Info(\"quit 3\")\r\n\r\n\treturn nil\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/kardianos/service/issues/comments/195446699","html_url":"https://github.com/kardianos/service/issues/57#issuecomment-195446699","issue_url":"https://api.github.com/repos/kardianos/service/issues/57","id":195446699,"user":{"login":"kardianos","id":755121,"avatar_url":"https://avatars.githubusercontent.com/u/755121?v=3","gravatar_id":"","url":"https://api.github.com/users/kardianos","html_url":"https://github.com/kardianos","followers_url":"https://api.github.com/users/kardianos/followers","following_url":"https://api.github.com/users/kardianos/following{/other_user}","gists_url":"https://api.github.com/users/kardianos/gists{/gist_id}","starred_url":"https://api.github.com/users/kardianos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kardianos/subscriptions","organizations_url":"https://api.github.com/users/kardianos/orgs","repos_url":"https://api.github.com/users/kardianos/repos","events_url":"https://api.github.com/users/kardianos/events{/privacy}","received_events_url":"https://api.github.com/users/kardianos/received_events","type":"User","site_admin":false},"created_at":"2016-03-11T16:46:34Z","updated_at":"2016-03-11T16:46:34Z","body":"The content of p.Start should quickly do any operations it needs to do that might need to return an error and cause a failure to start. After that is should launch a go-routine for your blocking stuff.\r\n\r\nPut the for {select{}} in a go-routine.\r\n"}}