Skip to content

Instantly share code, notes, and snippets.

@bdha
Created January 5, 2012 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdha/1564314 to your computer and use it in GitHub Desktop.
Save bdha/1564314 to your computer and use it in GitHub Desktop.
# Determine which init system we're using and load daemontools for it.
init_system = File.readlink("/proc/1/exe")
case init_system
when /upstart/
log "Using upstart"
cookbook_file "/etc/init/svscanboot.conf" do
source "upstart.svc"
owner "root"
group "root"
mode "0644"
end
execute "start_svscanboot" do
command "/sbin/initctl start svscanboot"
not_if "/sbin/initctl status svscanboot | /bin/grep running"
action :run
end
when /systemd/
log "Using systemd"
cookbook_file "/etc/systemd/system/svscanboot.service" do
source "systemd.svc"
owner "root"
group "root"
mode "0755"
end
execute "start_svscanboot" do
command "/bin/systemctl start svscanboot.service"
not_if "/bin/systemctl status svscanboot.service | grep 'Active: active'"
action :run
end
when "/sbin/init"
log "Using init like a beard."
execute "add_svscanboot_inittab" do
command "/bin/echo SV:123456:respawn:/usr/local/bin/svscanboot >> /etc/inittab ; /sbin/telinit q"
not_if "/bin/grep 'SV:123456:respawn:/usr/local/bin/svscanboot' /etc/inittab"
action :run
end
else
log("No idea what init system we're using. That's not good.") { level :error }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment