replaceinit.html (9362B)
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 2 <html> 3 <head> 4 <title>runit - replacing init</title> 5 </head> 6 <body> 7 <a href="http://smarden.org/pape/">G. Pape</a><br> 8 <a href="index.html">runit</a> 9 <hr> 10 <h1>runit - replacing init</h1> 11 <hr> 12 <a href="#sysv">How to replace sysvinit on GNU/Linux</a><br> 13 <a href="#bsd">How to replace init on *BSD</a><br> 14 <a href="#macosx">How to replace init on MacOSX</a><br> 15 <a href="#solaris">How to replace init on Solaris</a> 16 <hr> 17 <a name="sysv"><h2>Replacing sysvinit (GNU/Linux)</h2></a> 18 Follow these steps to migrate from <i>sysvinit</i> to <i>runit</i> on 19 <a href="http://www.debian.org/releases/woody/">Debian GNU/Linux (woody)</a>. 20 The <tt>/sbin/init</tt> binary is not replaced until step 6, <i>runit</i> is 21 the default Unix process no 1 after step 7. 22 <p> 23 If you have installed the precompiled Debian package, start at step 3. 24 <h3>Step 1: The three stages</h3> 25 <i>runit</i> looks for the three stages implementing the system's 26 <i>booting</i>, <i>running</i> and <i>shutdown</i> in <tt>/etc/runit/1</tt>, 27 <tt>/etc/runit/2</tt> and <tt>/etc/runit/3</tt>, create the files now: 28 <pre> 29 # mkdir -p /etc/runit 30 # cp -p /package/admin/runit/etc/debian/[123] /etc/runit/ 31 </pre> 32 Create also a getty service directory: 33 <pre> 34 # mkdir -p /etc/sv/getty-5 35 # cp -p /package/admin/runit/etc/debian/getty-tty5/run /etc/sv/getty-5/ 36 # cp -p /package/admin/runit/etc/debian/getty-tty5/finish /etc/sv/getty-5/ 37 </pre> 38 If you want <i>runit</i> to handle the ctrl-alt-del keyboard request, do: 39 <pre> 40 # cp -p /package/admin/runit/etc/debian/ctrlaltdel /etc/runit/ 41 </pre> 42 <h3>Step 2: The runit programs</h3> 43 The <i>runit</i> programs must reside on the root partition, copy them to 44 <tt>/sbin</tt>: 45 <pre> 46 # cp -p /package/admin/runit/command/runit* /sbin/ 47 </pre> 48 <h3>Step 3: The getties</h3> 49 At least one getty must run in stage 2 so that you are able to login. 50 Choose a free <tt>tty</tt>, say <tt>tty5</tt>, where <i>sysvinit</i> is not 51 running any getty (edit <tt>/etc/inittab</tt> and <tt>kill -HUP 1</tt> if 52 needed), and tell <a href="runsvdir.8.html">runsvdir</a> about the getty-5 53 <i>service</i>: 54 <pre> 55 # mkdir -p /service 56 # ln -s /etc/sv/getty-5 /service/ 57 </pre> 58 Start <i>runit</i>'s stage 2 for testing: 59 <pre> 60 # /etc/runit/2 & 61 </pre> 62 And check that the getty is running. 63 <h3>Step 4: Reboot into runit for testing</h3> 64 Boot your system with <i>runit</i> for the first time. 65 This does not change the default boot behavior of your system, <i>lilo</i> 66 will be told to use <i>runit</i> just once: 67 <ul> 68 <li>reboot the system 69 <li>enter the following on the lilo prompt:<br> 70 <tt>init=/sbin/runit-init</tt> 71 <li>watch the console output while <i>runit</i> boots up the system 72 <li>switch to <tt>tty5</tt> when stage 2 is reached, a <tt>getty</tt> 73 should run there, you are able to login. 74 </ul> 75 If you are not using <i>lilo</i> as boot loader, refer to the documentation 76 of your boot loader on how to pass <tt>init=/sbin/runit-init</tt> to the 77 kernel. 78 <h3>Step 5: Service migration</h3> 79 The goal is to migrate all services from <i>sysvinit</i> scheme to the 80 <i>runit</i> service supervision design; take a look at these 81 <a href="runscripts.html">run scripts</a> for popular services. 82 The migration can be done smoothly. 83 For those services that are not migrated to use <tt>run</tt> scripts yet, 84 add the corresponding <tt>init</tt>-script startup to <tt>/etc/runit/1</tt>, 85 e.g.: 86 <pre> 87 #!/bin/sh 88 # one time tasks 89 90 /etc/init.d/kerneld start 91 /etc/init.d/rmnologin 92 93 touch /etc/runit/stopit 94 chmod 0 /etc/runit/stopit 95 </pre> 96 It is possible to just add <tt>/etc/init.d/rc 2</tt> for having all services 97 from the former runlevel 2 started as one time tasks, but keep the goal above 98 in mind, supervising services has great advantages. 99 <p> 100 To migrate a service, 101 <a href="faq.html#create">create a service directory</a>, disable the service 102 if it is running, disable the service in <tt>/etc/rc.conf</tt> or remove the 103 service startup from the <tt>/etc/rc.*</tt> scripts and 104 <a href="faq.html#tell">tell runsvdir</a> about the new service. 105 <p> 106 Repeat step 4 and 5, using <tt><b>/sbin/runit-init 6</b></tt> to reboot the 107 system, until you are satisfied with your services startup. 108 If anything goes wrong, reboot the system into the default <i>sysvinit</i> 109 <tt>/sbin/init</tt> and repair the <i>runit</i> stages, then start again at 110 step 4. 111 <h3>Step 6: Replace /sbin/init</h3> 112 Now it is time to replace the <i>sysvinit</i> <tt>/sbin/init</tt> binary: 113 <pre> 114 # mv /sbin/init /sbin/init.sysv 115 # ln -s runit-init /sbin/init 116 </pre> 117 <h3>Step 7: Final reboot</h3> 118 The last step is to do the final reboot to boot the system with the new 119 default Unix process no 1 <i>runit</i>. 120 <pre> 121 # init 6 122 </pre> 123 To report success: 124 <pre> 125 # ( uname -a ; cat /etc/runit/[123] ) |mail pape-runit-2.1.2@smarden.org 126 </pre> 127 <hr> 128 129 <a name="bsd"><h2>Replacing init (*BSD)</h2></a> 130 Follow these steps to migrate from <i>init</i> to <i>runit</i> on 131 <a href="http://www.openbsd.org/">OpenBSD 2.9</a> or 132 <a href="http://www.freebsd.org/">FreeBSD 4.4</a>. 133 The <tt>/sbin/init</tt> binary is not replaced until step 4. 134 <h3>Step 1: The three stages</h3> 135 <i>runit</i> looks for the three stages implementing the system's 136 <i>booting</i>, <i>running</i> and <i>shutdown</i> in <tt>/etc/runit/1</tt>, 137 <tt>/etc/runit/2</tt> and <tt>/etc/runit/3</tt> respectively. 138 Create the scripts now: 139 <pre> 140 # mkdir -p /etc/runit 141 142 OpenBSD 2.9: 143 # cp -p /package/admin/runit/etc/openbsd/[123] /etc/runit/ 144 145 FreeBSD 4.4: 146 # cp -p /package/admin/runit/etc/freebsd/[123] /etc/runit/ 147 </pre> 148 Remove the <tt>svscanboot</tt> startup from <tt>/etc/rc.local</tt> by 149 deleting the line <tt>csh -cf '/command/svscanboot &'</tt> (this normally 150 is the last one); <i>runit</i> will start 151 <a href="runsvdir.8.html">runsvdir</a> in stage 2 after running 152 <tt>rc.local</tt> in stage 1. 153 <pre> 154 # vi /etc/rc.local 155 </pre> 156 <h3>Step 2: The runit programs</h3> 157 The <i>runit</i> programs must reside on the root partition, install them 158 into <tt>/sbin</tt>: 159 <pre> 160 # install -m0500 /package/admin/runit/command/runit* /sbin/ 161 </pre> 162 <h3>Step 3: The getties</h3> 163 At least one getty must run in stage 2 so that you are able to login. 164 To have it run on the virtual console no 5, create the getty-5 service 165 directory: 166 <pre> 167 # mkdir -p /etc/sv/getty-5 168 169 OpenBSD 2.9: 170 # cp -p /package/admin/runit/etc/openbsd/getty-ttyC4/run /etc/sv/getty-5/ 171 # cp -p /package/admin/runit/etc/openbsd/getty-ttyC4/finish /etc/sv/getty-5/ 172 173 FreeBSD 4.4: 174 # cp -p /package/admin/runit/etc/freebsd/getty-ttyv4/run /etc/sv/getty-5/ 175 # cp -p /package/admin/runit/etc/freebsd/getty-ttyv4/finish /etc/sv/getty-5/ 176 </pre> 177 and tell <a href="runsvdir.8.html">runsvdir</a> about the <tt>getty-5</tt> 178 <i>service</i>: 179 <pre> 180 # mkdir -p /service 181 # ln -s /etc/sv/getty-5 /service/ 182 </pre> 183 Start <i>runit</i>'s stage 2 for testing: 184 <pre> 185 # /etc/runit/2 & 186 </pre> 187 And check that the getty is running. 188 <h3>Step 4: Replace the <tt>/sbin/init</tt> binary</h3> 189 Before replacing the <tt>init</tt> binary, make sure that you are able 190 to boot your system alternatively, e.g. with a boot floppy, to restore the 191 former <tt>/sbin/init</tt> if anything goes wrong. 192 <p> 193 Make a backup copy of the current <tt>/sbin/init</tt> program and replace 194 it with <tt>/sbin/runit-init</tt>: 195 <pre> 196 # cp -p /sbin/init /sbin/init.bsd 197 # install /sbin/runit-init /sbin/init 198 </pre> 199 Boot your system with <i>runit</i> for the first time: 200 <pre> 201 # reboot 202 </pre> 203 Watch the console output while <i>runit</i> boots up the system. 204 Switch to the virtual console 5 (CTRL-ALT-F5) when stage 2 is reached, a 205 getty should run there, you are able to login. 206 <p> 207 Use <b>init 6</b> to reboot and <b>init 0</b> to halt a system that runs 208 <i>runit</i>. 209 This will cause <i>runit</i> to enter stage 3 which runs 210 <tt>/sbin/reboot</tt> or <tt>/sbin/halt</tt> as last command. 211 <p> 212 To report success: 213 <pre> 214 # ( uname -a ; cat /etc/runit/[123] ) |mail pape-runit-2.1.2@smarden.org 215 </pre> 216 <h3>Step 5: Service migration</h3> 217 The goal is to migrate all services from <i>/etc/rc.*</i> scheme to the 218 <i>runit</i> service supervision design; take a look at these 219 <a href="runscripts.html">run scripts</a> for popular services. 220 The migration can be done smoothly. 221 By default <i>runit</i> runs the <tt>/etc/rc</tt> scripts in stage 1 as a 222 one time task, so the services are started automatically: 223 <pre> 224 #!/bin/sh 225 # system one time tasks 226 227 /bin/sh /etc/rc autoboot 228 229 touch /etc/runit/stopit 230 chmod 0 /etc/runit/stopit 231 </pre> 232 To migrate a service, 233 <a href="faq.html#create">create a service directory</a>, disable the service 234 if it is running, disable the service in <tt>/etc/rc.conf</tt> or remove the 235 service startup from the <tt>/etc/rc.*</tt> scripts and 236 <a href="faq.html#tell">tell runsvdir</a> about the new service. 237 <hr> 238 239 <a name="macosx"><h2>Replacing init on MacOSX</h2></a> 240 Replacing init on MacOSX is not yet supported. 241 Please refer to the <a href="useinit.html">instructions</a> on how to use 242 <i>runit</i> service supervision with the MacOSX init scheme. 243 <hr> 244 245 <a name="solaris"><h2>Replacing init on Solaris</h2></a> 246 Replacing init on Solaris is not yet supported. 247 Please refer to the <a href="useinit.html">instructions</a> on how to use 248 <i>runit</i> service supervision with the Solaris sysvinit scheme. 249 <hr> 250 <address><a href="mailto:pape@smarden.org"> 251 Gerrit Pape <pape@smarden.org> 252 </a></address> 253 </body> 254 </html>