Skip to content

Commit

Permalink
First draft of a supervisor cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
bkonkle committed Dec 22, 2010
1 parent 68e5c0e commit c11c674
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 8 deletions.
5 changes: 5 additions & 0 deletions django/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
group node[:sites][:group]
mode node[:sites][:mode]
end

if node[:django][:app_server] == "gunicorn"
# Nginx can be used with Gunicorn without compiling a module
include_recipe "nginx"
end
16 changes: 8 additions & 8 deletions rails/definitions/rails_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
})
end

execute "install required gems" do
command "sudo rake gems:install RAILS_ENV=#{node[:rails][:environment]}"
cwd "#{path}/current"
action :nothing
ignore_failure true
end

deploy_revision path do
user params[:user]
group grp
Expand All @@ -41,13 +48,6 @@
params[:deploy_settings].each_pair do |func_name, param_value|
send(func_name, param_value)
end
notifies :run, "execute[installing required gems]"
end

execute "installing required gems" do
command "sudo rake gems:install RAILS_ENV=#{node[:rails][:environment]}"
cwd "#{path}/current"
action :nothing
ignore_failure true
notifies :run, resources(:execute => "install required gems")
end
end
40 changes: 40 additions & 0 deletions supervisor/definitions/supervisor_program.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
define :supervisor_program, :autostart => true, do
include_recipe "supervisor"

if params[:exitcodes]
exitcodes = params[:exitcodes].join(",")
else
exitcodes = nil
end

if params[:environment]
envsettings = []
params[:environment].each_pair do |key, value|
envsettings.push("#{key}=#{value}")
end
environment = envsettings.join(",")
else
environment = nil
end

template "/etc/supervisor/conf.d/#{params[:name].conf}" do
source "program.conf.erb"
user "root"
group "root"
mode "0644"
variables :name => params[:name],
:command => params[:command],
:directory => params[:directory],
:user => params[:user],
:autostart => params[:autostart],
:autorestart => params[:autorestart],
:exitcodes => exitcodes,
:startretries => params[:startretries],
:environment => environment,
:stdout_logfile => params[:stdout_logfile],
:stderr_logfile => params[:stderr_logfile],
:redirect_stderr => params[:redirect_stderr],
:stopsignal => params[:stopsignal]
notifies :reload, resources(:service => "supervisor")
end
end
28 changes: 28 additions & 0 deletions supervisor/files/default/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
; supervisor config file

[unix_http_server]
file=/var/run//supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run//supervisor.sock ; use a unix:// URL for a unix socket

; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.

[include]
files = /etc/supervisor/conf.d/*.conf
14 changes: 14 additions & 0 deletions supervisor/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package "supervisor"

cookbook_file "/etc/supervisor/supervisord.conf" do
source "supervisord.conf.erb"
owner "root"
group "root"
mode "0644"
end

service "supervisor" do
supports :status => true, :restart => true, :reload => true
reload_command "supervisorctl update"
action [:enable, :start]
end
13 changes: 13 additions & 0 deletions supervisor/templates/default/program.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[program:<%= @name %>]
command=<%= @command %>
<% if @directory %>directory=<%= @directory %><% end %>
<% if @user %>user=<%= @user %><% end %>
<% if not @autostart %>autostart=false<% end %>
<% if @autorestart %>autorestart=<%= @autorestart %><% end %>
<% if @exitcodes %>exitcodes=<%= @exitcodes %><% end %>
<% if @startretries %>startretries=<%= @startretries %><% end %>
<% if @environment %>environment=<%= @environment %><% end %>
<% if @stdout_logfile %>stdout_logfile=<%= @stdout_logfile %><% end %>
<% if @stderr_logfile %>stderr_logfile=<%= @stderr_logfile %><% end %>
<% if @redirect_stderr %>redirect_stderr=true<% end %>
<% if @stopsignal %>stopsignal=<%= @stopsignal %><% end %>

0 comments on commit c11c674

Please sign in to comment.