summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2015-05-09 16:22:37 -0500
committerWilliam Hubbs <w.d.hubbs@gmail.com>2015-10-29 09:31:32 -0500
commit1133e238cb69f5700878f92183e0b43d5a3624ff (patch)
tree55679ead63bddd7517aa98e48dc27c302bab9f65
parentee944553a9ea35622046bd1ab5657fd416a7019a (diff)
Add support for runitgithub/runit
-rw-r--r--runit-guide.md47
-rw-r--r--sh/Makefile3
-rw-r--r--sh/openrc-run.sh.in4
-rw-r--r--sh/runit.sh30
4 files changed, 83 insertions, 1 deletions
diff --git a/runit-guide.md b/runit-guide.md
new file mode 100644
index 00000000..23ef6971
--- /dev/null
+++ b/runit-guide.md
@@ -0,0 +1,47 @@
+# Using runit with OpenRC
+
+Beginning with OpenRC-0.18, we support using runit [1] in place of
+start-stop-daemon for monitoring and restarting daemons.
+
+## Setup
+
+Documenting runit in detail is beyond the scope of this guide. It will
+document how to set up OpenRC services to communicate with runit.
+
+### Use Default start, stop and status functions
+
+If you write your own start, stop and status functions in your service
+script, none of this will work. You must allow OpenRC to use the default
+functions.
+
+### Dependencies
+
+All OpenRC service scripts that want their daemons monitored by runit
+should have the following line added to their dependencies to make sure
+the runit scan directory is being monitored.
+
+need s6-svscan
+
+### Variable Settings
+
+The most important setting is the supervisor variable. At the top of
+your service script, you should set this variable as follows:
+
+supervisor=runit
+
+Several other variables affect runit services. They are documented on the
+openrc-run man page, but I will list them here for convenience:
+
+runit_service_path - the path to the runit service directory. The default is
+/etc/sv/$RC_SVCNAME.
+
+s6_svwait_options_start - the options to pass to s6-svwait when starting
+the service. If this is not set, s6-svwait will not be called.
+
+s6_service_timeout_stop - the amount of time, in milliseconds, s6-svc
+should wait for a service to go down when stopping.
+
+This is very early support, so feel free to file bugs if you have
+issues.
+
+[1] http://www.smarden.org/runit
diff --git a/sh/Makefile b/sh/Makefile
index b9b9fb33..9767ad93 100644
--- a/sh/Makefile
+++ b/sh/Makefile
@@ -1,7 +1,8 @@
DIR= ${LIBEXECDIR}/sh
SRCS= init.sh.in functions.sh.in gendepends.sh.in \
openrc-run.sh.in rc-functions.sh.in tmpfiles.sh.in ${SRCS-${OS}}
-INC= rc-mount.sh functions.sh rc-functions.sh s6.sh start-stop-daemon.sh
+INC= rc-mount.sh functions.sh rc-functions.sh runit.sh s6.sh \
+ start-stop-daemon.sh
BIN= gendepends.sh init.sh openrc-run.sh tmpfiles.sh ${BIN-${OS}}
INSTALLAFTER= _installafter
diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index 8aba4e0e..5854231e 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -132,6 +132,7 @@ start()
{
local func=ssd_start
case "$supervisor" in
+ runit) func=runit_start ;;
s6) func=s6_start ;;
?*)
ewarn "Invalid supervisor, \"$supervisor\", using start-stop-daemon"
@@ -144,6 +145,7 @@ stop()
{
local func=ssd_stop
case "$supervisor" in
+ runit) func=runit_stop ;;
s6) func=s6_stop ;;
?*)
ewarn "Invalid supervisor, \"$supervisor\", using start-stop-daemon"
@@ -156,6 +158,7 @@ status()
{
local func=ssd_status
case "$supervisor" in
+ runit) func=runit_status ;;
s6) func=s6_status ;;
?*)
ewarn "Invalid supervisor, \"$supervisor\", using start-stop-daemon"
@@ -186,6 +189,7 @@ unset _conf_d
sourcex -e "@SYSCONFDIR@/rc.conf"
# load service supervisor functions
+sourcex "@LIBEXECDIR@/sh/runit.sh"
sourcex "@LIBEXECDIR@/sh/s6.sh"
sourcex "@LIBEXECDIR@/sh/start-stop-daemon.sh"
diff --git a/sh/runit.sh b/sh/runit.sh
new file mode 100644
index 00000000..ae4ad776
--- /dev/null
+++ b/sh/runit.sh
@@ -0,0 +1,30 @@
+# Copyright (c) 2014 Benda Xu <heroxbd@gentoo.org>
+# Released under the 2-clause BSD license.
+
+runit_start()
+{
+ local service_dir runit_service
+ service_dir="${runit_service_dir:-/etc/sv}
+ runit_service="${service_dir}/${RC_SVCNAME}"
+ if [ ! -d "${runit_service}" ]; then
+ eerror "Runit service ${runit_service} not found"
+ return 1
+ fi
+ ebegin "Starting ${name:-$RC_SVCNAME}"
+ ln -snf "${runit_service}" "${RC_SVCDIR}/runit/$RC_SVCNAME" &&
+ sv check up "${RC_SVCDIR}/runit/$RC_SVCNAME"
+ eend $? "Failed to start $RC_SVCNAME"
+}
+
+runit_stop()
+{
+ ebegin "Stopping ${name:-$RC_SVCNAME}"
+ sv down "${RC_SVCDIR}/runit/${RC_SVCNAME}" &&
+ rm "${RC_SVCDIR}/runit/${RC_SVCNAME}"
+ eend $? "Failed to stop $RC_SVCNAME"
+}
+
+runit_status()
+{
+ sv status "${RC_SVCDIR}/runit/${RC_SVCNAME}"
+}