Last active
May 4, 2018 05:03
-
-
Save dnephin/f61646745bd004afba8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A supervisorctl plugin which returns the status of a process and exits with a | |
proper exit code. | |
This is a workaround for `https://github.com/Supervisor/supervisor/issues/24`_ | |
Configuration | |
------------- | |
Add this section to your supervisord.conf. You may need to adjust the path. | |
[ctlplugin:status_with_exit] | |
supervisor.ctl_factory = supervisor_status_with_exit:StatusWithExitCodePlugin | |
""" | |
from supervisor.supervisorctl import ControllerPluginBase | |
class StatusWithExitCodePlugin(ControllerPluginBase): | |
def do_status_with_exit(self, arg): | |
action_name = 'status_with_exit' | |
names = arg.strip().split() | |
if not names: | |
raise ValueError("A process name is required for " + action_name) | |
if len(names) > 1: | |
raise ValueError("Only a single process name is supported for " + | |
action_name) | |
name = names[0] | |
supervisor = self.ctl.get_supervisor() | |
info = supervisor.getProcessInfo(name) | |
if info['statename'] not in ('RUNNING', 'RESTARTING', 'STARTING'): | |
raise SystemExit('{name} {statename} {description}'.format(**info)) | |
self.ctl.output(info['statename']) | |
def help_status_with_exit(self): | |
self.ctl.output('status_with_exit <name> ' | |
'Get process status and exit.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment