Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First draft of a supervisor cookbook

  • Loading branch information...
commit c11c6743949f2d774ffc082749a3feee48fe2268 1 parent 68e5c0e
bkonkle authored
View
5 django/recipes/default.rb
@@ -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
View
16 rails/definitions/rails_app.rb
@@ -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
@@ -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
View
40 supervisor/definitions/supervisor_program.rb
@@ -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
View
28 supervisor/files/default/supervisord.conf
@@ -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
View
14 supervisor/recipes/default.rb
@@ -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
View
13 supervisor/templates/default/program.conf.erb
@@ -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 %>
Please sign in to comment.
Something went wrong with that request. Please try again.