Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Many changes to daikon recipe

 * using attributes instead of hardcoded values
 * using template for upstart recipe
 * switch between upstart or init.d script based on platform
 * compatible with chef 0.6 (creaky ancient version used by Engine Yard)
 * no login shell for daikon user

*Should* still be compatible with Ubuntu and modern chef (needs testing).
  • Loading branch information...
commit c97afdfb8fb9ee12651747d0975306236c50a2d4 1 parent fec7fd9
@nevans nevans authored
View
14 cookbooks/daikon/attributes/default.rb
@@ -0,0 +1,14 @@
+if Chef::VERSION =~ /^0.6/
+ Chef::Log.info "work around chef 0.6 (for Engine Yard)"
+ daikon(:user => "daikon",
+ :group => "daikon",
+ :home_dir => "/var/log/daikon",
+ :password => "??????")
+else
+ # using modern chef
+ default[:daikon][:user] = "daikon"
+ default[:daikon][:group] = "daikon"
+ default[:daikon][:home_dir] = "/var/log/daikon"
+ default[:daikon][:password] = "??????"
+end
+
View
6 cookbooks/daikon/files/default/daikon
@@ -1,6 +0,0 @@
-start on runlevel [2345]
-respawn
-respawn limit 10 90
-script
- /bin/su - daikon -c '/usr/bin/daikon run -- -k abc >> /home/daikon/daikon.log 2>&1'
-end script
View
60 cookbooks/daikon/recipes/default.rb
@@ -3,37 +3,55 @@
gem_package "daikon" do
end
-user "daikon" do
+user node[:daikon][:user] do
comment "Daikon User"
- system true
- shell "/bin/sh"
- home "/home/daikon"
+ system true unless Chef::VERSION =~ /^0.6/
+ shell "/bin/false"
+ home node[:daikon][:home_dir]
end
-group "daikon" do
+group node[:daikon][:group] do
members ['daikon']
end
-directory "/home/daikon" do
- mode 0775
- owner "daikon"
- group "daikon"
- action :create
+[
+ node[:daikon][:home_dir],
+ "/var/run/daikon",
+].each do |d|
+ directory d do
+ mode 0775
+ owner node[:daikon][:user]
+ group node[:daikon][:group]
+ action :create
+ end
end
-cookbook_file "/etc/init/daikon.conf" do
- owner "root"
- group "root"
- mode 0644
- action :create
- backup false
- source "daikon"
+case node[:platform]
+when "ubuntu", "debian"
+ template "/etc/init/daikon.conf" do
+ owner "root"
+ group "root"
+ mode 0644
+ action :create
+ backup false
+ source "daikon.upstart.erb"
+ end
+else
+ template "/etc/init.d/daikon" do
+ owner "root"
+ group "root"
+ mode 0755
+ action :create
+ source "daikon.initd.erb"
+ variables :node => node # to support chef 0.6
+ end
end
service "daikon" do
- provider Chef::Provider::Service::Upstart
- action :start
- enabled true
- running true
+ case node[:platform]
+ when "ubuntu", "debian"
+ provider Chef::Provider::Service::Upstart
+ end
supports :restart => true, :reload => true, :status => true
+ action [:enable, :start]
end
View
46 cookbooks/daikon/templates/default/daikon.initd.erb
@@ -0,0 +1,46 @@
+#!/bin/sh -e
+
+### BEGIN INIT INFO
+# Provides: daikon
+# Required-Start: $local_fs $remote_fs $network
+# Required-Stop: $local_fs $remote_fs $network
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Daikon init script
+# Description: Daikon connects to radishapp.com
+### END INIT INFO
+
+password="<%= @node[:daikon][:password] %>"
+log_dir="<%= @node[:daikon][:home_dir] %>"
+logfile="${log_dir}/daikon.log"
+pidfile="/var/run/daikon/daikon.pid"
+run_as_user="<%= @node[:daikon][:user] %>"
+sleep_time_during_restart=5
+stop_schedule="QUIT/30/INT/10/KILL/5"
+
+# override above values, or set any other env variables you need
+[ -f /etc/default/daikon ] && . /etc/default/daikon
+
+case "$1" in
+ run-with-log-and-pid)
+ /usr/bin/daikon run -- -k "${password}" >> "${logfile}" 2>&1 &
+ echo $! > ${pidfile}
+ ;;
+ start)
+ start-stop-daemon --start --pidfile ${pidfile} \
+ --chuid ${run_as_user} --chdir ${log_dir} \
+ --startas $0 -- run-with-log-and-pid
+ ;;
+ stop)
+ start-stop-daemon --stop --pidfile ${pidfile} --retry=${stop_schedule}
+ ;;
+ restart)
+ $0 stop
+ sleep ${sleep_time_during_restart}
+ $0 start
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart}"
+ exit 1
+ ;;
+esac
View
6 cookbooks/daikon/templates/default/daikon.upstart.erb
@@ -0,0 +1,6 @@
+start on runlevel [2345]
+respawn
+respawn limit 10 90
+script
+ /bin/su - <%=node[:daikon][:user]%> -c '/usr/bin/daikon run -- -k <%=node[:daikon][:password]%> >> <%=node[:daikon][:home_dir]/daikon.log 2>&1'
+end script
Please sign in to comment.
Something went wrong with that request. Please try again.