summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/service/debian.rb
blob: 1f95d66f7e603efa74d3f3774d2191e7c349cbe6 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Manage debian services.  Start/stop is the same as InitSvc, but enable/disable
# is special.
Puppet::Type.type(:service).provide :debian, :parent => :init do
    desc "Debian's form of ``init``-style management.

    The only difference is that this supports service enabling and disabling
    via ``update-rc.d`` and determines enabled status via ``invoke-rc.d``.

    "

    commands :update_rc => "/usr/sbin/update-rc.d"
    # note this isn't being used as a command until
    # http://projects.reductivelabs.com/issues/2538
    # is resolved.
    commands :invoke_rc => "/usr/sbin/invoke-rc.d"

    defaultfor :operatingsystem => [:debian, :ubuntu]

    def self.defpath
        superclass.defpath
    end

    # Remove the symlinks
    def disable
        update_rc "-f", @resource[:name], "remove"
        update_rc @resource[:name], "stop", "00", "1", "2", "3", "4", "5", "6", "."
    end

    def enabled?
        # TODO: Replace system() call when Puppet::Util.execute gives us a way
        # to determine exit status.  http://projects.reductivelabs.com/issues/2538
        system("/usr/sbin/invoke-rc.d", "--quiet", "--query", @resource[:name], "start")

        # 104 is the exit status when you query start an enabled service.
        # 106 is the exit status when the policy layer supplies a fallback action
        # See x-man-page://invoke-rc.d
        if [104, 106].include?($CHILD_STATUS.exitstatus)
            return :true
        else
            return :false
        end
    end

    def enable
        update_rc "-f", @resource[:name], "remove"
        update_rc @resource[:name], "defaults"
    end
end