Guest User

Untitled

a guest
Apr 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. # Manage Red Hat services. Start/stop is the same as InitSvc, but enable/disable
  2. # is special.
  3. Puppet::Type.type(:service).provide :redhat, :parent => :init do
  4. desc "Red Hat's (and probably many others) form of ``init``-style service
  5. management; uses ``chkconfig`` for service enabling and disabling."
  6.  
  7. commands :chkconfig => "/sbin/chkconfig", :srv => "/sbin/service"
  8.  
  9. defaultfor :operatingsystem => [:redhat, :fedora, :suse, :centos]
  10.  
  11. def self.defpath
  12. superclass.defpath
  13. end
  14.  
  15. # Remove the symlinks
  16. def disable
  17. begin
  18. output = chkconfig(@resource[:name], :off)
  19. output += chkconfig("--del", @resource[:name])
  20. rescue Puppet::ExecutionFailure
  21. raise Puppet::Error, "Could not disable %s: %s" %
  22. [self.name, output]
  23. end
  24. end
  25.  
  26. def enabled?
  27. begin
  28. output = chkconfig(@resource[:name])
  29. rescue Puppet::ExecutionFailure
  30. return :false
  31. end
  32.  
  33. # If it's disabled on SuSE, then it will print output showing "off"
  34. # at the end
  35. if output =~ /.* off$/
  36. return :false
  37. end
  38.  
  39. return :true
  40. end
  41.  
  42. # Don't support them specifying runlevels; always use the runlevels
  43. # in the init scripts.
  44. def enable
  45. begin
  46. output = chkconfig("--add", @resource[:name])
  47. output += chkconfig(@resource[:name], :on)
  48. rescue Puppet::ExecutionFailure => detail
  49. raise Puppet::Error, "Could not enable %s: %s" %
  50. [self.name, detail]
  51. end
  52. end
  53.  
  54. def restart
  55. srv @resource[:name], "restart"
  56. end
  57.  
  58. def startcmd
  59. srv @resource[:name], "start"
  60. end
  61.  
  62. def statuscmd
  63. if @resource[:hasstatus] == :true
  64. srv @resource[:name], "status"
  65. else
  66. return false
  67. end
  68. end
  69.  
  70. def stopcmd
  71. srv @resource[:name], "stop"
  72. end
  73. end
Add Comment
Please, Sign In to add comment