Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make chef recipes work at Engine Yard (Gentoo, chef 0.6) #2

Merged
merged 5 commits into from

2 participants

nicholas a. evans Nick Quaranto
nicholas a. evans

I have not tested to ensure that it still works with modern chef and Ubuntu, but it should (fingers crossed).

Additionally, many hardcoded values were replaced with attributes, the daikon user no longer has a login shell, the daikon user uses the log directory for their home directory, and notifications will restart the service if configs change.

Because I'm using start-stop-daemon, this will not work on Redhat or CentOS. With some minor tweaks to the daikon gem so it can easily the standard locations for pidfiles and logfiles, we can switch to using the daemons gem helpers (i.e. stop using daikon run) and use daikon [start|stop|restart|...] instead, and we can make the init.d script work for those OSes as well.

nicholas a. evans nevans 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).
c97afdf
nicholas a. evans

should be members [node[:daikon][:user]]

Nick Quaranto qrush merged commit 9b44ea4 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 14, 2011
  1. nicholas a. evans

    Many changes to daikon recipe

    nevans authored
     * 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).
  2. nicholas a. evans
Commits on Jun 15, 2011
  1. nicholas a. evans
  2. nicholas a. evans
  3. nicholas a. evans
This page is out of date. Refresh to see the latest.
14 cookbooks/daikon/attributes/default.rb
View
@@ -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
+
6 cookbooks/daikon/files/default/daikon
View
@@ -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
67 cookbooks/daikon/recipes/default.rb
View
@@ -3,37 +3,60 @@
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
- members ['daikon']
+group node[:daikon][:group] do
+ members [node[:daikon][:user]]
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"
+# HACK: to make chef 0.6 happy
+service "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"
+ notifies :restart, resources(:service => "daikon")
+ end
+else
+ template "/etc/init.d/daikon" do
+ owner "root"
+ group "root"
+ mode 0755
+ action :create
+ source "daikon.initd.erb"
+ variables :node => node # HACK: to support chef 0.6
+ notifies :restart, resources(:service => "daikon")
+ 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
48 cookbooks/daikon/templates/default/daikon.initd.erb
View
@@ -0,0 +1,48 @@
+#!/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"
+# using non-standard pidfile location, until daikon gem is updated
+pidfile="${log_dir}/daikon.pid"
+run_as_user="<%= @node[:daikon][:user] %>"
+sleep_time_during_restart=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)
+ # need this hack to ensure logfile location, until daikon gem is updated
+ /usr/bin/daikon run -- -k "${password}" >> "${logfile}" 2>&1 &
+ ;;
+ start)
+ start-stop-daemon --start --pidfile ${pidfile} \
+ --chuid ${run_as_user} --chdir ${log_dir} \
+ --oknodo --startas $0 -- run-with-log
+ ;;
+ stop)
+ start-stop-daemon --stop --pidfile ${pidfile}
+ ;;
+ restart)
+ $0 stop
+ sleep ${sleep_time_during_restart}
+ $0 start
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart}"
+ exit 1
+ ;;
+esac
+
+# vim:ft=sh
6 cookbooks/daikon/templates/default/daikon.upstart.erb
View
@@ -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
6 node.json
View
@@ -1,4 +1,6 @@
{
- "run_list": [ "recipe[daikon]" ]
+ "run_list": [ "recipe[daikon]" ],
+ "daikon": {
+ "password": "0123456789abcdef"
+ }
}
-
Something went wrong with that request. Please try again.