def is_running(service): """ Check if a service is running. :: import fabtools if fabtools.service.is_running('foo'): print "Service foo is running!" """ with settings(hide('running', 'stdout', 'stderr', 'warnings'), warn_only=True): if using_systemd(): return systemd.is_running(service) else: if distrib_family() != "gentoo": test_upstart = run_as_root('test -f /etc/init/%s.conf' % service) status = _service(service, 'status') if test_upstart.succeeded: return 'running' in status else: return status.succeeded else: # gentoo status = _service(service, 'status') return ' started' in status
def restarted(service): """ Require a service to be restarted. :: from fabtools import require require.service.restarted('foo') """ if is_running(service): if using_systemd(): systemd.restart(service) else: restart(service) else: if using_systemd(): systemd.start(service) else: start(service)
def is_running(service): """ Check if a service is running. :: import fabtools if fabtools.service.is_running('foo'): print "Service foo is running!" """ with settings(hide('running', 'stdout', 'stderr', 'warnings'), warn_only=True): if using_systemd(): return systemd.is_running(service) else: test_upstart = run_as_root('test -f /etc/init/%s.conf' % service) status = run_as_root('service %(service)s status' % locals()) if test_upstart.succeeded: return 'running' in status else: return status.succeeded