Skip to content

Instantly share code, notes, and snippets.

@stantonk
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stantonk/9236700 to your computer and use it in GitHub Desktop.
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
# 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