summary refs log tree commit diff
path: root/doc/replaceinit.html
blob: 4d2828a5a537125d612e4bcde5143e38ea479837 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>runit - replacing init</title>
</head>
<body>
<a href="http://smarden.org/pape/">G. Pape</a><br>
<a href="index.html">runit</a>
<hr>
<h1>runit - replacing init</h1>
<hr>
<a href="#sysvinit">How to replace sysvinit on GNU/Linux</a><br>
<a href="#bsdinit">How to replace init on *BSD</a>
<hr>
<a name="sysvinit"><h2>Replacing sysvinit (GNU/Linux)</h2></a>
Follow these steps to migrate from <i>sysvinit</i> to <i>runit</i> on
<a href="http://www.debian.org/releases/woody/">Debian GNU/Linux (woody)</a>.
The <tt>/sbin/init</tt> binary is not replaced until step 6, <i>runit</i> is
the default Unix process no 1 after step 7.
<p>
If you have installed the precompiled Debian package, start at step 3.
<h3>Step 1: The three stages</h3>
<i>runit</i> looks for the three stages implementing the system's
<i>booting</i>, <i>running</i> and <i>shutdown</i> in <tt>/etc/runit/1</tt>,
<tt>/etc/runit/2</tt> and <tt>/etc/runit/3</tt>, create the files now:
<pre>
  # mkdir -p /etc/runit
  # cp -p /package/admin/runit/etc/debian/[123] /etc/runit/
</pre>
Create also a getty service directory:
<pre>
  # mkdir -p /etc/runit/getty-5
  # cp -p /package/admin/runit/etc/debian/getty-tty5/run /etc/runit/getty-5/
</pre>
If you want <i>runit</i> to handle the ctrl-alt-del keyboard request, do:
<pre>
  # cp -p /package/admin/runit/etc/debian/ctrlaltdel /etc/runit/
</pre>
<h3>Step 2: The runit programs</h3>
The <i>runit</i> programs must reside on the root partition, copy them to
<tt>/sbin</tt>:
<pre>
  # cp -p /package/admin/runit/command/runit* /sbin/
</pre>
<h3>Step 3: The getties</h3>
At least one getty must run in stage 2 so you are able to login, choose a
free <tt>tty</tt>, say <tt>tty5</tt>, where <i>sysvinit</i> is not running
any getty (edit <tt>/etc/inittab</tt> and <tt>kill -HUP 1</tt> if
needed) and tell <a href="http://cr.yp.to/daemontools/svscan.html">svscan</a>
about the getty-5 <i>service</i>:
<pre>
  # ln -s /etc/runit/getty-5 /service/
</pre>
Check if the getty is running.
<h3>Step 4: Reboot into runit for testing</h3>
Boot your system with <i>runit</i> for the first time. This does not change
the default boot behavior of your system, <i>lilo</i> will be told to use
<i>runit</i> just once:
<ul>
  <li>reboot the system
  <li>enter the following on the lilo prompt:<br>
  <tt>init=/sbin/runit-init</tt>
  <li>watch the console output while <i>runit</i> boots up the system
  <li>switch to <tt>tty5</tt> when stage 2 is reached, a <tt>getty</tt>
  should run there, you are able to login.
</ul>
If you are not using <i>lilo</i> as boot loader, refer to the documentation
of your boot loader on how to pass <tt>init=/sbin/runit-init</tt> to the
kernel.
<h3>Step 5: Service migration</h3>
The goal is to migrate all services from <i>sysvinit</i> scheme to the
<a href="http://cr.yp.to/daemontools.html">daemontools</a> design; take a
look at these <a href="runscripts.html">run scripts</a> for popular
services. The migration can be done smoothly. For those services that are
not migrated to use <tt>run</tt> scripts yet, add the corresponding
<tt>init</tt>-script startup to <tt>/etc/runit/1</tt>, e.g.:
<pre>
  #!/bin/sh
  # one time tasks
  rm -f /etc/runit/stopit
  /etc/init.d/rcS

  /etc/init.d/kerneld start
  /etc/init.d/rmnologin

  exit 0
</pre>
It is possible to just add <tt>/etc/init.d/rc 2</tt> for having all services
from the former runlevel 2 started as one time tasks, but keep the goal above
in mind, supervising services has great advantages.
<p>
Repeat step 4 and 5, using <tt><b>/sbin/runit-init 6</b></tt> to reboot the
system, until you are satisfied with your services startup. If anything goes
wrong, reboot the system into the default <i>sysvinit</i> <tt>/sbin/init</tt>
and repair the <i>runit</i> stages, then start again at step 4.
<h3>Step 6: Replace /sbin/init</h3>
Now it is time to replace the <i>sysvinit</i> <tt>/sbin/init</tt> binary:
<pre>
  # mv /sbin/init /sbin/init.sysv
  # ln -s runit-init /sbin/init
</pre>
<h3>Step 7: Final reboot</h3>
The last step is to do the final reboot to boot the system with the new
default Unix process no 1 <i>runit</i>.
<pre>
  # shutdown -r now
</pre>
To report success:
<pre>
  # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.9.1@smarden.org
</pre>
<hr>

<a name="bsdinit"><h2>Replacing init (*BSD)</h2></a>
Follow these steps to migrate from <i>init</i> to <i>runit</i> on
<a href="http://www.openbsd.org/">OpenBSD 2.9</a> or
<a href="http://www.freebsd.org/">FreeBSD 4.4</a>. The
<tt>/sbin/init</tt> binary is not replaced until step 4.
<h3>Step 1: The three stages</h3>
<i>runit</i> looks for the three stages implementing the system's
<i>booting</i>, <i>running</i> and <i>shutdown</i> in <tt>/etc/runit/1</tt>,
<tt>/etc/runit/2</tt> and <tt>/etc/runit/3</tt>, create the files now:
<pre>
  # mkdir -p /etc/runit

OpenBSD 2.9:
  # cp -p /package/admin/runit/etc/openbsd/[123] /etc/runit/

FreeBSD 4.4:
  # cp -p /package/admin/runit/etc/freebsd/[123] /etc/runit/
</pre>
Remove the <tt>svscanboot</tt> startup from <tt>/etc/rc.local</tt> by
deleting the line <tt>csh -cf '/command/svscanboot &'</tt> (this normally
is the last one); <i>runit</i> will start
<a href="runsvdir.8.html">runsvdir</a> in stage 2 after running
<tt>rc.local</tt> in stage 1.
<pre>
  # vi /etc/rc.local
</pre>
<h3>Step 2: The runit programs</h3>
The <i>runit</i> programs must reside on the root partition, install them
into <tt>/sbin</tt>:
<pre>
  # install -m0500 /package/admin/runit/command/runit* /sbin/
</pre>
<h3>Step 3: The getties</h3>
At least one getty must run in stage 2 so you are able to login. To have it
run on the virtual console no 5, create the getty-5 service directory:
<pre>
  # mkdir -p /etc/runit/getty-5

OpenBSD 2.9:
  # cp -p /package/admin/runit/etc/openbsd/getty-ttyC4/run \
      /etc/runit/getty-5/

FreeBSD 4.4:
  # cp -p /package/admin/runit/etc/freebsd/getty-ttyv4/run \
      /etc/runit/getty-5/
</pre>
and tell
<a href="http://cr.yp.to/daemontools/svscan.html">svscan</a>
about the <tt>getty-5</tt> <i>service</i>:
<pre>
  # ln -s /etc/runit/getty-5 /service/
</pre>
<h3>Step 4: Replace the <tt>/sbin/init</tt> binary</h3>
Before replacing the <tt>init</tt> binary, make sure that you are able
to boot your system alternatively, e.g. with a boot floppy, to restore the
former <tt>/sbin/init</tt> if anything goes wrong.
<p>
Make a backup copy of the current <tt>/sbin/init</tt> program and replace
it with <tt>/sbin/runit-init</tt>:
<pre>
  # cp -p /sbin/init /sbin/init.bsd
  # install /sbin/runit-init /sbin/init
</pre>
Boot your system with <i>runit</i> for the first time:
<pre>
  # reboot
</pre>
Watch the console output while <i>runit</i> boots up the system. Switch
to the virtual console 5 (CTRL-ALT-F5) when stage 2 is reached, a getty
should run there, you are able to login.
<p>
Use <b>init 6</b> to reboot and <b>init 0</b> to halt a system that runs
<i>runit</i>. This will cause <i>runit</i> to enter stage 3 which runs
<tt>/sbin/reboot</tt> or <tt>/sbin/halt</tt> as last command.
<p>
To report success:
<pre>
  # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.9.1@smarden.org
</pre>
<h3>Step 5: Service migration</h3>
The goal is to migrate all services from <i>/etc/rc.*</i> scheme to the
<a href="http://cr.yp.to/daemontools.html">daemontools</a> design; take a
look at these <a href="runscripts.html">run scripts</a> for popular
services. The migration can be done smoothly. By default <i>runit</i>
runs the <tt>/etc/rc</tt> scripts in stage 1 as a one time task, so the
services are started automatically:
<pre>
  #!/bin/sh
  # system one time tasks
  rm -f /etc/runit/stopit

  /bin/sh /etc/rc autoboot

  exit 0
</pre>
To migrate a service, create a service directory, disable the service if
it is running, disable the service in <tt>/etc/rc.conf</tt> or remove the
service startup from the <tt>/etc/rc.*</tt> scripts and tell
<a href="runsvdir.8.html">runsvdir</a> about the new service.
<hr>
<address><a href="mailto:pape@smarden.org">
Gerrit Pape &lt;pape@smarden.org&gt;
</a></address>
<small>$Id$</small>
</body>
</html>