Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back-port #24741 to 2015.5 #24790

Merged
merged 3 commits into from
Jun 19, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 22 additions & 4 deletions salt/modules/upstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
# Import python libs
import glob
import os
import re
import itertools

# Import salt libs
import salt.utils
Expand Down Expand Up @@ -170,7 +172,12 @@ def _upstart_is_disabled(name):
NOTE: An Upstart service can also be disabled by placing "manual"
in /etc/init/[name].conf.
'''
return os.access('/etc/init/{0}.override'.format(name), os.R_OK)
files = ['/etc/init/{0}.conf'.format(name), '/etc/init/{0}.override'.format(name)]
for file_name in itertools.ifilter(os.path.isfile, files):
with salt.utils.fopen(file_name) as fp_:
if re.search(r'^\s*manual', fp_.read(), re.MULTILINE):
return True
return False


def _upstart_is_enabled(name):
Expand Down Expand Up @@ -436,18 +443,29 @@ def _upstart_disable(name):
'''
Disable an Upstart service.
'''
if _upstart_is_disabled(name):
return _upstart_is_disabled(name)
override = '/etc/init/{0}.override'.format(name)
with salt.utils.fopen(override, 'w') as ofile:
ofile.write('manual')
with salt.utils.fopen(override, 'a') as ofile:
ofile.write('manual\n')
return _upstart_is_disabled(name)


def _upstart_enable(name):
'''
Enable an Upstart service.
'''
if _upstart_is_enabled(name):
return _upstart_is_enabled(name)
override = '/etc/init/{0}.override'.format(name)
if os.access(override, os.R_OK):
files = ['/etc/init/{0}.conf'.format(name), override]
for file_name in itertools.ifilter(os.path.isfile, files):
with salt.utils.fopen(file_name, 'r+') as fp_:
new_text = re.sub(r'^\s*manual\n?', '', fp_.read(), 0, re.MULTILINE)
fp_.seek(0)
fp_.write(new_text)
fp_.truncate()
if os.access(override, os.R_OK) and os.path.getsize(override) == 0:
os.unlink(override)
return _upstart_is_enabled(name)

Expand Down