{"action":"created","issue":{"url":"https://api.github.com/repos/Supervisor/supervisor/issues/24","labels_url":"https://api.github.com/repos/Supervisor/supervisor/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/Supervisor/supervisor/issues/24/comments","events_url":"https://api.github.com/repos/Supervisor/supervisor/issues/24/events","html_url":"https://github.com/Supervisor/supervisor/issues/24","id":1117416,"number":24,"title":"exit code allway zero","user":{"login":"ramary","id":876884,"avatar_url":"https://avatars.githubusercontent.com/u/876884?v=3","gravatar_id":"","url":"https://api.github.com/users/ramary","html_url":"https://github.com/ramary","followers_url":"https://api.github.com/users/ramary/followers","following_url":"https://api.github.com/users/ramary/following{/other_user}","gists_url":"https://api.github.com/users/ramary/gists{/gist_id}","starred_url":"https://api.github.com/users/ramary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramary/subscriptions","organizations_url":"https://api.github.com/users/ramary/orgs","repos_url":"https://api.github.com/users/ramary/repos","events_url":"https://api.github.com/users/ramary/events{/privacy}","received_events_url":"https://api.github.com/users/ramary/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Supervisor/supervisor/labels/supervisorctl","name":"supervisorctl","color":"bfdadc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":22,"created_at":"2011-06-26T15:41:35Z","updated_at":"2015-07-16T16:51:41Z","closed_at":null,"body":"I want to use the exit code for nagios but it's allways 0.\r\n\r\necample 1:\r\nzope@plone:~> ./bin/supervisorctl status\r\nhttp://127.0.0.1:9001 refused connection\r\nzope@plone:~> echo $?\r\n0\r\n\r\nCould you change exit LSB conform ?\r\nhttp://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html\r\n\r\nexample 2:\r\n./bin/supervisorctl status\r\nbalancer                         RUNNING    pid 23753, uptime 0:00:50\r\ninstance0                        RUNNING    pid 23751, uptime 0:00:50\r\ninstance1                        EXITED     Jun 26 05:40 PM\r\nvarnish                          RUNNING    pid 23754, uptime 0:00:50\r\nzeo                              RUNNING    pid 23750, uptime 0:00:50\r\nzope@plone:~> echo $?\r\n0\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Supervisor/supervisor/issues/comments/122019334","html_url":"https://github.com/Supervisor/supervisor/issues/24#issuecomment-122019334","issue_url":"https://api.github.com/repos/Supervisor/supervisor/issues/24","id":122019334,"user":{"login":"lukeweber","id":195363,"avatar_url":"https://avatars.githubusercontent.com/u/195363?v=3","gravatar_id":"","url":"https://api.github.com/users/lukeweber","html_url":"https://github.com/lukeweber","followers_url":"https://api.github.com/users/lukeweber/followers","following_url":"https://api.github.com/users/lukeweber/following{/other_user}","gists_url":"https://api.github.com/users/lukeweber/gists{/gist_id}","starred_url":"https://api.github.com/users/lukeweber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukeweber/subscriptions","organizations_url":"https://api.github.com/users/lukeweber/orgs","repos_url":"https://api.github.com/users/lukeweber/repos","events_url":"https://api.github.com/users/lukeweber/events{/privacy}","received_events_url":"https://api.github.com/users/lukeweber/received_events","type":"User","site_admin":false},"created_at":"2015-07-16T16:51:41Z","updated_at":"2015-07-16T16:51:41Z","body":"@mnaberez -  \r\n1. Is supervisorctl.py code used for anything besides single commands or interactive mode(two states), or is it reused in libraries (third state - not interactive, raise exceptions and don't exit on errors)?\r\n\r\nImplementation could be the following that I think would work for both:\r\n\r\n1. implement handle_error(message=None, fatal=False)\r\n1. Wrap any output that contains \"Error\" or \"ERROR\" in supervisorctl.py with a handle_error(message=...) method.\r\n1. Wrap any blank \"raise\" with handle_error(fatal=True)\r\n1. Add an option exit_on_error in main() in  supervisorctl.py defined as !interactive\r\n1. Create duplicate tests for all tests that check for different Exceptions in test_supervisorctl.py to check for SystemExit when options.exit_on_error = True\r\n\r\nHandle error example code:\r\n   ```python\r\n    def handle_error(self, message=None, fatal=False):\r\n        if message:\r\n            self.ctl.output(message)\r\n\r\n        if self.ctl.options.exit_on_error:\r\n            raise SystemExit(2)\r\n        elif fatal:\r\n            raise\r\n   ```\r\n\r\n\r\n\r\n\r\n"}}