'''
State enforcing for packages
'''

def running(name, sig=None):
    '''
    Verify that the service is running
    '''
    if __salt__['service.status'](name, sig):
        return {'name': name,
                'changes': {},
                'result': True,
                'comment': 'The service is already running'}
    changes = {name: __salt__['service.start'](name)}
    if not changes[name]:
        return {'name': name,
                'changes': changes,
                'result': False,
                'comment': 'Service ' + name + ' failed to start'}
    return {'name': name,
            'changes': changes,
            'result': True,
            'comment': 'Service ' + name + ' installed'}

def dead(name, sig=None):
    '''
    Ensure that the named service is dead
    '''
    if not __salt__['service.status'](name, sig):
        return {'name': name,
                'changes': {},
                'result': True,
                'comment': 'Service ' + name + ' is already dead'}
    changes = {name: __salt__['service.stop'](name)}
    if not changes[name]:
        return {'name': name,
                'changes': changes,
                'result': False,
                'comment': 'Service ' + name + ' failed to stop'}
    return {'name': name,
            'changes': changes,
            'result': True,
            'comment': 'Service ' + name + ' killed'}

def watcher(name, sig=None):
    '''
    The service watcher, called to invoke the watch command. 
    '''
    if __salt__['service.status'](name, sig):
        changes = {name: __salt__['service.restart'](name)}
        return {'name': name,
                'changes': changes,
                'result': True,
                'comment': 'Service restarted'}
    return {'name': name,
            'changes': {},
            'result': True,
            'comment': 'Service ' + name + ' installed'}


@@ -2,116 +2,500 @@
 ''%0AS
-tate enforcing for packages%0A'''%0A%0Adef running(name, sig=None):%0A    '''%0A    Verify that the service is running
+ervice Management%0A==================%0AServices are defined as system daemons typically started with system init or%0Arc scripts, services can be defined as running or dead.%0A%0A.. code-block:: yaml%0A    httpd:%0A      service:%0A        - running%0A'''%0A%0Adef running(name, sig=None):%0A    '''%0A    Verify that the service is running%0A%0A    name%0A    ~~~~%0A    The name of the init or rc script used to manage the service%0A%0A    sig%0A    ~~~~%0A    The string to search for when looking for the service process with ps
 %0A   
@@ -1165,16 +1165,196 @@
 is dead%0A
+    %0A    name%0A    ~~~~%0A    The name of the init or rc script used to manage the service%0A%0A    sig%0A    ~~~~%0A    The string to search for when looking for the service process with ps%0A
     '''%0A
@@ -2046,16 +2046,192 @@
 ommand. 
+%0A%0A    name%0A    ~~~~%0A    The name of the init or rc script used to manage the service%0A%0A    sig%0A    ~~~~%0A    The string to search for when looking for the service process with ps
 %0A    '''

update docstrings for the service state