1 |
commit: f62253b8334a85dac4671e42817b96a3bedd1881 |
2 |
Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com> |
3 |
AuthorDate: Wed Jul 27 21:26:26 2016 +0000 |
4 |
Commit: William Hubbs <williamh <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Jul 27 21:26:26 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=f62253b8 |
7 |
|
8 |
Add support for runit |
9 |
|
10 |
X-Gentoo-Bug: 501364 |
11 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=501364 |
12 |
|
13 |
init.d/Makefile | 3 ++- |
14 |
init.d/runsvdir.in | 20 ++++++++++++++++++++ |
15 |
runit-guide.md | 41 +++++++++++++++++++++++++++++++++++++++++ |
16 |
sh/Makefile | 4 ++-- |
17 |
sh/openrc-run.sh.in | 4 ++++ |
18 |
sh/runit.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 |
6 files changed, 121 insertions(+), 3 deletions(-) |
20 |
|
21 |
diff --git a/init.d/Makefile b/init.d/Makefile |
22 |
index a44c4e6..a1d2ec7 100644 |
23 |
--- a/init.d/Makefile |
24 |
+++ b/init.d/Makefile |
25 |
@@ -3,7 +3,8 @@ include ../mk/net.mk |
26 |
DIR= ${INITDIR} |
27 |
SRCS= bootmisc.in fsck.in hostname.in local.in localmount.in loopback.in \ |
28 |
netmount.in osclock.in root.in savecache.in swap.in swapfiles.in \ |
29 |
- tmpfiles.setup.in swclock.in sysctl.in urandom.in s6-svscan.in ${SRCS-${OS}} |
30 |
+ tmpfiles.setup.in swclock.in sysctl.in runsvdir.in urandom.in \ |
31 |
+ s6-svscan.in ${SRCS-${OS}} |
32 |
BIN= ${OBJS} |
33 |
|
34 |
# Are we installing our network scripts? |
35 |
|
36 |
diff --git a/init.d/runsvdir.in b/init.d/runsvdir.in |
37 |
new file mode 100644 |
38 |
index 0000000..9b5d974 |
39 |
--- /dev/null |
40 |
+++ b/init.d/runsvdir.in |
41 |
@@ -0,0 +1,20 @@ |
42 |
+#!@SBINDIR@/openrc-run |
43 |
+# Copyright (c) 2016 The OpenRC Authors. |
44 |
+# See the Authors file at the top-level directory of this distribution and |
45 |
+# https://github.com/OpenRC/openrc/blob/master/AUTHORS |
46 |
+# |
47 |
+# This file is part of OpenRC. It is subject to the license terms in |
48 |
+# the LICENSE file found in the top-level directory of this |
49 |
+# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE |
50 |
+# This file may not be copied, modified, propagated, or distributed |
51 |
+# except according to the terms contained in the LICENSE file. |
52 |
+ |
53 |
+command=/usr/bin/runsvdir |
54 |
+command_background=yes |
55 |
+pidfile=/var/run/runsvdir.pid |
56 |
+command_args="-P $RC_SVCDIR/sv 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'" |
57 |
+ |
58 |
+start_pre() |
59 |
+{ |
60 |
+ checkpath -m 0755 -o root:root -d ${RC_SVCDIR}/sv |
61 |
+} |
62 |
|
63 |
diff --git a/runit-guide.md b/runit-guide.md |
64 |
new file mode 100644 |
65 |
index 0000000..93a3eec |
66 |
--- /dev/null |
67 |
+++ b/runit-guide.md |
68 |
@@ -0,0 +1,41 @@ |
69 |
+# Using runit with OpenRC |
70 |
+ |
71 |
+Beginning with OpenRC-0.21, we support using runit [1] in place of |
72 |
+start-stop-daemon for monitoring and restarting daemons. |
73 |
+ |
74 |
+## Setup |
75 |
+ |
76 |
+Documenting runit in detail is beyond the scope of this guide. It will |
77 |
+document how to set up OpenRC services to communicate with runit. |
78 |
+ |
79 |
+### Use Default start, stop and status functions |
80 |
+ |
81 |
+If you write your own start, stop and status functions in your service |
82 |
+script, none of this will work. You must allow OpenRC to use the default |
83 |
+functions. |
84 |
+ |
85 |
+### Dependencies |
86 |
+ |
87 |
+All OpenRC service scripts that want their daemons monitored by runit |
88 |
+should have the following line added to their dependencies to make sure |
89 |
+the runit scan directory is being monitored. |
90 |
+ |
91 |
+need runsvdir |
92 |
+ |
93 |
+### Variable Settings |
94 |
+ |
95 |
+The most important setting is the supervisor variable. At the top of |
96 |
+your service script, you should set this variable as follows: |
97 |
+ |
98 |
+supervisor=runit |
99 |
+ |
100 |
+The second variable you need is runit_service. This is the path to the |
101 |
+runit service you wish to control via OpenRC. The default is |
102 |
+/etc/sv/${RC_SVCNAME}. This means that for an OpenRC service |
103 |
+/etc/init.d/foo, you will need to create the same runit service in |
104 |
+/etc/sv/foo. |
105 |
+ |
106 |
+This is very early support, so feel free to file bugs if you have |
107 |
+issues. |
108 |
+ |
109 |
+[1] http://www.smarden.org/runit |
110 |
|
111 |
diff --git a/sh/Makefile b/sh/Makefile |
112 |
index 24c2315..1af23ec 100644 |
113 |
--- a/sh/Makefile |
114 |
+++ b/sh/Makefile |
115 |
@@ -1,8 +1,8 @@ |
116 |
DIR= ${LIBEXECDIR}/sh |
117 |
SRCS= init.sh.in functions.sh.in gendepends.sh.in \ |
118 |
openrc-run.sh.in rc-functions.sh.in tmpfiles.sh.in ${SRCS-${OS}} |
119 |
-INC= functions.sh rc-mount.sh rc-functions.sh s6.sh start-stop-daemon.sh \ |
120 |
- supervise-daemon.sh |
121 |
+INC= rc-mount.sh functions.sh rc-functions.sh runit.sh s6.sh \ |
122 |
+ start-stop-daemon.sh supervise-daemon.sh |
123 |
BIN= gendepends.sh init.sh openrc-run.sh tmpfiles.sh ${BIN-${OS}} |
124 |
|
125 |
INSTALLAFTER= _installafter |
126 |
|
127 |
diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in |
128 |
index 36bc366..ce5432f 100644 |
129 |
--- a/sh/openrc-run.sh.in |
130 |
+++ b/sh/openrc-run.sh.in |
131 |
@@ -153,6 +153,7 @@ start() |
132 |
{ |
133 |
local func=ssd_start |
134 |
case "$supervisor" in |
135 |
+ runit) func=runit_start ;; |
136 |
s6) func=s6_start ;; |
137 |
supervise-daemon) func=supervise_start ;; |
138 |
?*) |
139 |
@@ -166,6 +167,7 @@ stop() |
140 |
{ |
141 |
local func=ssd_stop |
142 |
case "$supervisor" in |
143 |
+ runit) func=runit_stop ;; |
144 |
s6) func=s6_stop ;; |
145 |
supervise-daemon) func=supervise_stop ;; |
146 |
?*) |
147 |
@@ -179,6 +181,7 @@ status() |
148 |
{ |
149 |
local func=ssd_status |
150 |
case "$supervisor" in |
151 |
+ runit) func=runit_status ;; |
152 |
s6) func=s6_status ;; |
153 |
supervise-daemon) func=supervise_status ;; |
154 |
?*) |
155 |
@@ -216,6 +219,7 @@ fi |
156 |
|
157 |
|
158 |
# load service supervisor functions |
159 |
+sourcex "@LIBEXECDIR@/sh/runit.sh" |
160 |
sourcex "@LIBEXECDIR@/sh/s6.sh" |
161 |
sourcex "@LIBEXECDIR@/sh/start-stop-daemon.sh" |
162 |
sourcex "@LIBEXECDIR@/sh/supervise-daemon.sh" |
163 |
|
164 |
diff --git a/sh/runit.sh b/sh/runit.sh |
165 |
new file mode 100644 |
166 |
index 0000000..e9c1d22 |
167 |
--- /dev/null |
168 |
+++ b/sh/runit.sh |
169 |
@@ -0,0 +1,52 @@ |
170 |
+# Copyright (c) 2016 The OpenRC Authors. |
171 |
+# See the Authors file at the top-level directory of this distribution and |
172 |
+# https://github.com/OpenRC/openrc/blob/master/AUTHORS |
173 |
+# |
174 |
+# This file is part of OpenRC. It is subject to the license terms in |
175 |
+# the LICENSE file found in the top-level directory of this |
176 |
+# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE |
177 |
+# This file may not be copied, modified, propagated, or distributed |
178 |
+# except according to the terms contained in the LICENSE file. |
179 |
+# Released under the 2-clause BSD license. |
180 |
+ |
181 |
+runit_start() |
182 |
+{ |
183 |
+ local service_path service_link |
184 |
+ service_path="${runit_service:-/etc/sv/${RC_SVCNAME}}" |
185 |
+ if [ ! -d "${service_path}" ]; then |
186 |
+ eerror "Runit service ${service_path} not found" |
187 |
+ return 1 |
188 |
+ fi |
189 |
+ service_link="${RC_SVCDIR}/sv/${service_path##*/}" |
190 |
+ ebegin "Starting ${name:-$RC_SVCNAME}" |
191 |
+ ln -snf "${service_path}" "${service_link}" |
192 |
+ sv start "${service_link}" > /dev/null 2>&1 |
193 |
+ eend $? "Failed to start $RC_SVCNAME" |
194 |
+} |
195 |
+ |
196 |
+runit_stop() |
197 |
+{ |
198 |
+ local service_path service_link |
199 |
+ service_path="${runit_service:-/etc/sv/${RC_SVCNAME}}" |
200 |
+ if [ ! -d "${service_path}" ]; then |
201 |
+ eerror "Runit service ${service_path} not found" |
202 |
+ return 1 |
203 |
+ fi |
204 |
+ service_link="${RC_SVCDIR}/sv/${service_path##*/}" |
205 |
+ ebegin "Stopping ${name:-$RC_SVCNAME}" |
206 |
+ sv stop "${service_link}" > /dev/null 2>&1 && |
207 |
+ rm "${service_link}" |
208 |
+ eend $? "Failed to stop $RC_SVCNAME" |
209 |
+} |
210 |
+ |
211 |
+runit_status() |
212 |
+{ |
213 |
+ local service_path service_link |
214 |
+ service_path="${runit_service:-/etc/sv/${RC_SVCNAME}}" |
215 |
+ if [ ! -d "${service_path}" ]; then |
216 |
+ eerror "Runit service ${service_path} not found" |
217 |
+ return 1 |
218 |
+ fi |
219 |
+ service_link="${RC_SVCDIR}/sv/${service_path##*/}" |
220 |
+ sv status "${service_link}" |
221 |
+} |