Last active
August 29, 2015 13:56
-
-
Save stantonk/9236700 to your computer and use it in GitHub Desktop.
Reliable way to determine if a process on a remote host is running or not using Python and Fabric. Tested on CentOs 5.10 and Ubuntu 12.04
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
# NOTE: the hide('warnings', 'running', 'stdout', 'stderr') quiets the | |
# dumping of the commands fabric runs and its responses, which I find | |
# rather annoying. | |
def is_running(pidfile, pidpath): | |
with cd(pidpath): | |
if exists(pidfile): | |
with settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True): | |
return run('ps -p $(cat %s) --no-header' % pidfile).succeeded | |
else: | |
# assume it isn't running if no pidfile is available | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment