summaryrefslogtreecommitdiffstats
path: root/src/lib/Client/Tools/FreeBSDInit.py
blob: 8e13e7981924292fb169a9eb458db272a7004868 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'''FreeBSD Init Support for Bcfg2'''
__revision__ = '$Rev$'

# TODO
# - hardcoded path to ports rc.d
# - doesn't know about /etc/rc.d/

import Bcfg2.Client.Tools

class FreeBSDInit(Bcfg2.Client.Tools.SvcTool):
    '''FreeBSD Service Support for Bcfg2'''
    __name__ = 'FreeBSDInit'
    __handles__ = [('Service', 'freebsd')]
    __req__ = {'Service': ['name', 'status']}
    __svcrestart__ = 'restart'

    def VerifyService(self, entry, _):
        return True

    def BundleUpdated(self, bundle, states):
        '''The Bundle has been updated'''
        for entry in bundle:
            if self.handlesEntry(entry):
                command = "/usr/local/etc/rc.d/%s" % entry.get('name')
                if entry.get('status') == 'on' and not self.setup['build']:
                    self.logger.debug('Restarting service %s' % entry.get('name'))
                    rc = self.cmd.run('%s %s' % (command, \
                        entry.get('reload', self.__svcrestart__)))[0]
                else:
                    self.logger.debug('Stopping service %s' % entry.get('name'))
                    rc = self.cmd.run('%s stop' %  command)[0]
                if rc:
                    self.logger.error("Failed to restart service %s" % (entry.get('name')))