jamtur01 / puppet
- Source
- Commits
- Network (8)
- Issues (0)
- Downloads (71)
- Wiki (1)
- Graphs
-
Branch:
0.24.x
Bryan Kearney (author)
Thu Apr 09 06:59:15 -0700 2009
| b2a3db94 » | jamtur01 | 2008-04-24 | 1 | # Manage Red Hat services. Start/stop uses /sbin/service and enable/disable uses chkconfig | |
| 2 | |||||
| 12452ee9 » | luke | 2006-08-13 | 3 | Puppet::Type.type(:service).provide :redhat, :parent => :init do | |
| 6d5a1295 » | jamtur01 | 2008-12-13 | 4 | desc "Red Hat's (and probably many others) form of ``init``-style service management: | |
| 5 | |||||
| 6 | Uses ``chkconfig`` for service enabling and disabling. | ||||
| 7 | |||||
| 8 | " | ||||
| 12452ee9 » | luke | 2006-08-13 | 9 | ||
| b2a3db94 » | jamtur01 | 2008-04-24 | 10 | commands :chkconfig => "/sbin/chkconfig", :service => "/sbin/service" | |
| 11 | |||||
| 2218611f » | jamtur01 | 2009-02-12 | 12 | defaultfor :operatingsystem => [:redhat, :fedora, :suse, :centos, :sles, :oel, :ovm] | |
| 12452ee9 » | luke | 2006-08-13 | 13 | ||
| 8be0d33b » | lutter | 2006-12-14 | 14 | def self.defpath | |
| 15 | superclass.defpath | ||||
| 16 | end | ||||
| 17 | |||||
| 2dffbee3 » | luke | 2006-02-24 | 18 | # Remove the symlinks | |
| 19 | def disable | ||||
| fd8e0807 » | luke | 2006-06-13 | 20 | begin | |
| 1d23013a » | luke | 2007-05-09 | 21 | output = chkconfig(@resource[:name], :off) | |
| fd8e0807 » | luke | 2006-06-13 | 22 | rescue Puppet::ExecutionFailure | |
| 2dffbee3 » | luke | 2006-02-24 | 23 | raise Puppet::Error, "Could not disable %s: %s" % | |
| 24 | [self.name, output] | ||||
| 25 | end | ||||
| 26 | end | ||||
| 27 | |||||
| 28 | def enabled? | ||||
| fd8e0807 » | luke | 2006-06-13 | 29 | begin | |
| 1d23013a » | luke | 2007-05-09 | 30 | output = chkconfig(@resource[:name]) | |
| fd8e0807 » | luke | 2006-06-13 | 31 | rescue Puppet::ExecutionFailure | |
| 2dffbee3 » | luke | 2006-02-24 | 32 | return :false | |
| 33 | end | ||||
| fd8e0807 » | luke | 2006-06-13 | 34 | ||
| 2cb2e030 » | luke | 2006-09-02 | 35 | # If it's disabled on SuSE, then it will print output showing "off" | |
| 36 | # at the end | ||||
| 37 | if output =~ /.* off$/ | ||||
| 38 | return :false | ||||
| 39 | end | ||||
| 40 | |||||
| fd8e0807 » | luke | 2006-06-13 | 41 | return :true | |
| 2dffbee3 » | luke | 2006-02-24 | 42 | end | |
| 43 | |||||
| 44 | # Don't support them specifying runlevels; always use the runlevels | ||||
| 45 | # in the init scripts. | ||||
| 46 | def enable | ||||
| fd8e0807 » | luke | 2006-06-13 | 47 | begin | |
| 83ef1b0c » | jamtur01 | 2008-05-15 | 48 | output = chkconfig(@resource[:name], :on) | |
| 65298225 » | luke | 2006-12-28 | 49 | rescue Puppet::ExecutionFailure => detail | |
| 2dffbee3 » | luke | 2006-02-24 | 50 | raise Puppet::Error, "Could not enable %s: %s" % | |
| 65298225 » | luke | 2006-12-28 | 51 | [self.name, detail] | |
| 2dffbee3 » | luke | 2006-02-24 | 52 | end | |
| 53 | end | ||||
| b2a3db94 » | jamtur01 | 2008-04-24 | 54 | ||
| 55 | def restart | ||||
| de6aec6e » | jamtur01 | 2008-07-16 | 56 | if @resource[:hasrestart] == :true | |
| b2a3db94 » | jamtur01 | 2008-04-24 | 57 | service(@resource[:name], "restart") | |
| 58 | else | ||||
| de6aec6e » | jamtur01 | 2008-07-16 | 59 | super | |
| 60 | end | ||||
| 61 | end | ||||
| 62 | |||||
| 63 | def status | ||||
| 64 | if @resource[:hasstatus] == :true | ||||
| bfcd6263 » | jamtur01 | 2008-07-21 | 65 | begin | |
| 66 | service(@resource[:name], "status") | ||||
| 67 | return :running | ||||
| 68 | rescue | ||||
| 69 | return :stopped | ||||
| 70 | end | ||||
| de6aec6e » | jamtur01 | 2008-07-16 | 71 | else | |
| 72 | super | ||||
| b2a3db94 » | jamtur01 | 2008-04-24 | 73 | end | |
| 74 | end | ||||
| 75 | |||||
| 67fc394d » | jamtur01 | 2009-03-06 | 76 | def startcmd | |
| 77 | [command(:service), @resource[:name], "start"] | ||||
| b2a3db94 » | jamtur01 | 2008-04-24 | 78 | end | |
| 79 | |||||
| 67fc394d » | jamtur01 | 2009-03-06 | 80 | def stopcmd | |
| 81 | [command(:service), @resource[:name], "stop"] | ||||
| b2a3db94 » | jamtur01 | 2008-04-24 | 82 | end | |
| 83 | |||||
| 2dffbee3 » | luke | 2006-02-24 | 84 | end | |
| 12452ee9 » | luke | 2006-08-13 | 85 | ||
