summaryrefslogtreecommitdiffstats
path: root/src/lib/Client/Tools/Upstart.py
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2012-03-24 11:20:07 -0500
committerSol Jerome <sol.jerome@gmail.com>2012-03-24 11:20:07 -0500
commitdab1d03d81c538966d03fb9318a4588a9e803b44 (patch)
treef51e27fa55887e9fb961766805fe43f0da56c5b9 /src/lib/Client/Tools/Upstart.py
parent5cd6238df496a3cea178e4596ecd87967cce1ce6 (diff)
downloadbcfg2-dab1d03d81c538966d03fb9318a4588a9e803b44.tar.gz
bcfg2-dab1d03d81c538966d03fb9318a4588a9e803b44.tar.bz2
bcfg2-dab1d03d81c538966d03fb9318a4588a9e803b44.zip
Allow to run directly from a git checkout (#1037)
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
Diffstat (limited to 'src/lib/Client/Tools/Upstart.py')
-rw-r--r--src/lib/Client/Tools/Upstart.py93
1 files changed, 0 insertions, 93 deletions
diff --git a/src/lib/Client/Tools/Upstart.py b/src/lib/Client/Tools/Upstart.py
deleted file mode 100644
index 7afc8edd7..000000000
--- a/src/lib/Client/Tools/Upstart.py
+++ /dev/null
@@ -1,93 +0,0 @@
-"""Upstart support for Bcfg2."""
-
-import glob
-import re
-
-import Bcfg2.Client.Tools
-import Bcfg2.Client.XML
-
-
-class Upstart(Bcfg2.Client.Tools.SvcTool):
- """Upstart service support for Bcfg2."""
- name = 'Upstart'
- __execs__ = ['/lib/init/upstart-job',
- '/sbin/initctl',
- '/usr/sbin/service']
- __handles__ = [('Service', 'upstart')]
- __req__ = {'Service': ['name', 'status']}
- svcre = re.compile("/etc/init/(?P<name>.*).conf")
-
- def get_svc_command(self, service, action):
- return "/usr/sbin/service %s %s" % (service.get('name'), action)
-
- def VerifyService(self, entry, _):
- """Verify Service status for entry
-
- Verifying whether or not the service is enabled can be done
- at the file level with upstart using the contents of
- /etc/init/servicename.conf. All we need to do is make sure
- the service is running when it should be.
- """
-
- if entry.get('status') == 'ignore':
- return True
-
- if entry.get('parameters'):
- params = entry.get('parameters')
- else:
- params = ''
-
- try:
- output = self.cmd.run('/usr/sbin/service %s status %s' % \
- ( entry.get('name'), params ))[1][0]
- except IndexError:
- self.logger.error("Service %s not an Upstart service" % \
- entry.get('name'))
- return False
-
- match = re.compile("%s( \(.*\))? (start|stop)/(running|waiting)" %entry.get('name') ).match( output )
- if match == None:
- # service does not exist
- entry.set('current_status', 'off')
- status = False
- elif match.group(3) == 'running':
- # service is running
- entry.set('current_status', 'on')
- if entry.get('status') == 'off':
- status = False
- else:
- status = True
- else:
- # service is not running
- entry.set('current_status', 'off')
- if entry.get('status') == 'on':
- status = False
- else:
- status = True
-
- return status
-
- def InstallService(self, entry):
- """Install Service for entry."""
- # don't take any actions for mode='manual'
- if entry.get('mode', 'default') == 'manual':
- self.logger.info("Service %s mode set to manual. Skipping "
- "installation." % (entry.get('name')))
- return False
- if entry.get('status') == 'on':
- pstatus = self.cmd.run(self.get_svc_command(entry, 'start'))[0]
- elif entry.get('status') == 'off':
- pstatus = self.cmd.run(self.get_svc_command(entry, 'stop'))[0]
- # pstatus is true if command failed
- return not pstatus
-
- def FindExtra(self):
- """Locate extra Upstart services."""
- specified = [entry.get('name') for entry in self.getSupportedEntries()]
- extra = []
- for name in [self.svcre.match(fname).group('name') for fname in
- glob.glob("/etc/init/*.conf") \
- if self.svcre.match(fname).group('name') not in specified]:
- extra.append(name)
- return [Bcfg2.Client.XML.Element('Service', type='upstart', name=name) \
- for name in extra]