Created
December 13, 2012 02:31
-
-
Save monkeymantra/4273546 to your computer and use it in GitHub Desktop.
First attempt at a supervisord provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Manage services using Supervisor. Start/stop uses /sbin/service and enable/disable uses chkconfig | |
Puppet::Type.type(:service).provide :supervisor, :parent => :base do | |
desc "Supervisor: A daemontools-like service monitor written in python | |
" | |
commands :supervisord => "/usr/bin/supervisord", | |
:supervisorctl => "/usr/bin/supervisorctl" | |
def self.instances | |
# this exclude list is all from /sbin/service (5.x), but I did not exclude kudzu | |
[] | |
end | |
def enable | |
output = supervisorctl(:add, @resource[:name]) | |
rescue Puppet::ExecutionFailure => detail | |
raise Puppet::Error, "Could not enable #{self.name}: #{detail}" | |
end | |
def disable | |
self.stopcmd | |
output = supervisorctl(:remove, @resource[:name]) | |
rescue Puppet::ExecutionFailure | |
raise Puppet::Error, "Could not disable #{self.name}: #{output}" | |
end | |
def status | |
begin | |
output = supervisorctl(:status, @resource[:name]) | |
rescue Puppet::ExecutionFailure | |
return :false | |
end | |
# If it's enabled it will print output showing "RUNNING" | |
# at the end | |
if output =~ /.* RUNNING.*$/ | |
return :true | |
end | |
:false | |
end | |
# use hasstatus=>true when its set for the provider. | |
def statuscmd | |
((@resource.provider.get(:hasstatus) == true) || (@resource[:hasstatus] == :true)) && [command(:supervisorctl), "status", @resource[:name]] | |
end | |
def restartcmd | |
(@resource[:hasrestart] == :true) && [command(:service), "restart", @resource[:name]] | |
end | |
def startcmd | |
[command(:service), "start", @resource[:name]] | |
end | |
def stopcmd | |
[command(:service), "stop", @resource[:name]] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment