Skip to content

Commit

Permalink
Add service state file
Browse files Browse the repository at this point in the history
  • Loading branch information
thatch45 committed May 18, 2011
1 parent aaff058 commit a12b2b5
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions salt/states/service.py
@@ -0,0 +1,44 @@
'''
State enforcing for packages
'''

def running(name, sig=None):
'''
Verify that the package is installed, return the packages changed in the
operation and a bool if the job was sucessfull
'''
if __salt__['service.status'](name):
return {'name': name,
'changes': {},
'result': True,
'comment': 'The service is already running'}
changes = __salt__['service.start'](name)
if not changes:
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):
return {'name': name,
'changes': {},
'result': True,
'comment': 'Service ' + name + ' is already dead'}
changes = __salt__['service.stop'](name)
if not changes:
return {'name': name,
'changes': changes,
'result': False,
'comment': 'Service ' + name + ' failed to stop'}
return {'name': name,
'changes': changes,
'result': True,
'comment': 'Service ' + name + ' killed'}

0 comments on commit a12b2b5

Please sign in to comment.