summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/service/redhat.rb
blob: fe2c98ba997b5ef3f4c6672404f49b10ce53fbdd (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Manage Red Hat services.  Start/stop uses /sbin/service and enable/disable uses chkconfig

Puppet::Type.type(:service).provide :redhat, :parent => :init do
    desc "Red Hat's (and probably many others) form of ``init``-style service management:

    Uses ``chkconfig`` for service enabling and disabling.

    "

    commands :chkconfig => "/sbin/chkconfig", :service => "/sbin/service"

    defaultfor :operatingsystem => [:redhat, :fedora, :suse, :centos, :sles, :oel, :ovm]

    def self.defpath
        superclass.defpath
    end

    # Remove the symlinks
    def disable
        begin
            output = chkconfig(@resource[:name], :off)
        rescue Puppet::ExecutionFailure
            raise Puppet::Error, "Could not disable %s: %s" %
                [self.name, output]
        end
    end

    def enabled?
        begin
            output = chkconfig(@resource[:name])
        rescue Puppet::ExecutionFailure
            return :false
        end

        # If it's disabled on SuSE, then it will print output showing "off"
        # at the end
        if output =~ /.* off$/
            return :false
        end

        return :true
    end

    # Don't support them specifying runlevels; always use the runlevels
    # in the init scripts.
    def enable
        begin
            output = chkconfig(@resource[:name], :on)
        rescue Puppet::ExecutionFailure => detail
            raise Puppet::Error, "Could not enable %s: %s" %
                [self.name, detail]
        end
    end

    def restartcmd
        if @resource[:hasrestart] == :true
           [command(:service), @resource[:name], "restart"]
        else
            super
        end
    end

    def statuscmd
        if @resource[:hasstatus] == :true
            begin
                [command(:service), @resource[:name], "status"]
                return :running
            rescue
                return :stopped
            end
        else
            super
        end
    end

    def startcmd
        [command(:service), @resource[:name], "start"]
    end

    def stopcmd
        [command(:service), @resource[:name], "stop"]
    end

end