Skip to content

Instantly share code, notes, and snippets.

@tow
Created September 2, 2011 18:08
Show Gist options
  • Select an option

  • Save tow/1189345 to your computer and use it in GitHub Desktop.

Select an option

Save tow/1189345 to your computer and use it in GitHub Desktop.
chef resource for a service running in /etc/service
define :etc_service, :action => :restart do
package "daemontools" do
action :install
end
path = params[:path] ? params[:path] : ("/etc/service/" + params[:name])
log_path = params[:log_path] ? params[:log_path] : ("/var/log/multilog/" + params[:name])
if params[:action] == :delete
directory path do
action :delete
recursive :true
end
else
directory "#{path}/log" do
action :create
recursive true
end
cookbook_file "#{path}/run" do
source params[:source]
mode "755"
end
directory log_path do
action :create
recursive true
owner "multilog"
group "multilog"
end
ruby "make_log_run" do
code <<-EOH
f = open "#{path}/log/run", 'w'
f.write "#!/bin/sh\nexec setuidgid multilog multilog t #{log_path}"
f.chmod 0755
f.close
EOH
end
if params[:action] == :start
execute "svc -u #{path}" do
end
elsif params[:action] == :restart
execute "svc -t #{path}; svc -u #{path}" do
end
elsif params[:action] == :stop
execute "svc -d #{path}" do
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment