Example #1
0
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
Example #2
0
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