From 1ee0a783ae1b2a9b1966323c4377eede079d8e28 Mon Sep 17 00:00:00 2001 From: Michael Hale Date: Thu, 26 Aug 2010 15:38:26 -0400 Subject: [PATCH] Add gentoo support to runit cookbook. Authors: Darrin Eden, Michael Hale --- attributes/default.rb | 4 ++++ definitions/runit_service.rb | 6 ++++-- metadata.rb | 2 +- recipes/default.rb | 16 +++++++++++---- templates/gentoo/runit-start.sh.erb | 32 +++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 templates/gentoo/runit-start.sh.erb diff --git a/attributes/default.rb b/attributes/default.rb index 0d5bc56..c5b655f 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -23,4 +23,8 @@ set[:runit][:chpst_bin] = "/usr/bin/chpst" set[:runit][:service_dir] = "/etc/service" set[:runit][:sv_dir] = "/etc/sv" +when "gentoo" + set[:runit][:sv_bin] = "/usr/bin/sv" + set[:runit][:service_dir] = "/etc/service" + set[:runit][:sv_dir] = "/var/service" end diff --git a/definitions/runit_service.rb b/definitions/runit_service.rb index 4f5c203..c2811c9 100644 --- a/definitions/runit_service.rb +++ b/definitions/runit_service.rb @@ -111,8 +111,10 @@ end end - link service_dir_name do - to sv_dir_name + unless node[:platform] == "gentoo" + link service_dir_name do + to sv_dir_name + end end ruby_block "supervise_#{params[:name]}_sleep" do diff --git a/metadata.rb b/metadata.rb index 3f5c291..cae74c0 100644 --- a/metadata.rb +++ b/metadata.rb @@ -6,7 +6,7 @@ recipe "runit", "Installs and configures runit" -%w{ ubuntu debian }.each do |os| +%w{ ubuntu debian gentoo }.each do |os| supports os end diff --git a/recipes/default.rb b/recipes/default.rb index 670d9eb..d0ccff0 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -18,11 +18,12 @@ # case node[:platform] -when "debian","ubuntu" +when "debian","ubuntu", "gentoo" execute "start-runsvdir" do command value_for_platform( "debian" => { "default" => "runsvdir-start" }, - "ubuntu" => { "default" => "start runsvdir" } + "ubuntu" => { "default" => "start runsvdir" }, + "gentoo" => { "default" => "/etc/init.d/runit-start start" } ) action :nothing end @@ -33,6 +34,13 @@ action :nothing end + if platform? "gentoo" + template "/etc/init.d/runit-start" do + source "runit-start.sh.erb" + mode 0755 + end + end + package "runit" do action :install if platform?("ubuntu", "debian") @@ -44,8 +52,8 @@ "default" => :nothing, "9.04" => :run, "8.10" => :run, - "8.04" => :run - } + "8.04" => :run }, + "gentoo" => { "default" => :run } ), resources(:execute => "start-runsvdir"), :immediately notifies value_for_platform( "debian" => { "squeeze/sid" => :run, "default" => :nothing }, diff --git a/templates/gentoo/runit-start.sh.erb b/templates/gentoo/runit-start.sh.erb new file mode 100644 index 0000000..a6c11b3 --- /dev/null +++ b/templates/gentoo/runit-start.sh.erb @@ -0,0 +1,32 @@ +#!/sbin/runscript +# Copyright 1999-2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +depend() { + after net +} + +start() { + ebegin "Starting runsvdir" + start-stop-daemon --start --exec /usr/bin/runsvdir \ + --background --make-pidfile \ + --pidfile /var/run/runsvdir.pid -- <%= node.runit.sv_dir %> + eend $? +} + +stop() { + local ret1 ret2 + ebegin "Stopping runsvdir" + start-stop-daemon --stop --oknodo --pidfile /var/run/runsvdir.pid + ret1=$? + eend ${ret1} + + ebegin "Stopping services and logging" + sv shutdown -w 10 <%= node.runit.sv_dir %>/* + ret2=$? + eend ${ret2} + + return $((ret1+ret2)) +} +