runlevels.html (3837B)
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 2 <html> 3 <head> 4 <title>runit - runlevels</title> 5 </head> 6 <body> 7 <a href="http://smarden.org/pape/">G. Pape</a><br> 8 <a href="index.html">runit</a><br> 9 <hr> 10 <h1>runit - runlevels</h1> 11 <hr> 12 <a href="#prepare">Prepare runit for using runlevels</a><br> 13 <a href="#switch">Switching runlevels</a><br> 14 <a href="#create">Creating runlevels</a> 15 <hr> 16 <a name="prepare"><h3>Prepare runit</h3></a> 17 If not yet done, configure your system to use 18 <a href="runit.8.html">runit</a> as process no 1 by following the 19 <a href="replaceinit.html">instructions</a>. 20 <p> 21 Create the following directories and symbolic links: 22 <pre> 23 # mkdir -p /etc/runit/runsvdir/default 24 # mkdir -p /etc/runit/runsvdir/single 25 # ln -s /etc/sv/getty-5 /etc/runit/runsvdir/single/ 26 # ln -s default /etc/runit/runsvdir/current 27 </pre> 28 Copy the contents of <tt>/service/</tt> to 29 <tt>/etc/runit/runsvdir/current/</tt> and replace <tt>/service/</tt> 30 with a symbolic link: 31 <pre> 32 # cp -pR /service/* /etc/runit/runsvdir/current/ 33 # mv -f /service /service.old && \ 34 ln -s /etc/runit/runsvdir/current /service 35 </pre> 36 You have now created two runlevels: <tt>default</tt> and <tt>single</tt>. 37 The <tt>current</tt> runlevel is <tt>default</tt>. 38 It is safe to remove <tt>/service.old/</tt> if you don't need it anymore. 39 <p> 40 Finally edit <tt>/etc/runit/2</tt> to set the <tt>default</tt> runlevel when 41 stage 2 starts: 42 <pre> 43 $ cat /etc/runit/2 44 #!/bin/sh 45 PATH=/command:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin 46 47 <b>runsvchdir default >/dev/null</b> 48 49 exec env - PATH=$PATH \ 50 runsvdir /service 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................' 51 </pre> 52 <hr> 53 <a name="switch"><h3>Switching runlevels</h3></a> 54 Switching runlevels with <i>runit</i> is done by switching the directory the 55 <a href="runsvdir.8.html">runsvdir</a> program is running in. 56 This is done by the <a href="runsvchdir.8.html">runsvchdir</a> program, e.g. 57 to switch to the <tt>single</tt> user runlevel, do: 58 <pre> 59 # runsvchdir single 60 </pre> 61 To switch back to the <tt>default</tt> runlevel, do: 62 <pre> 63 # runsvchdir default 64 </pre> 65 See <a href="runsvdir.8.html">the runsvdir program</a> for a description of 66 what happens when <i>runsvdir</i> sees the directory changed. 67 Note that there is no guarantee that all services from the <tt>previous</tt> 68 runlevel will stop, the <a href="runsv.8.html">runsv</a> processes have sent 69 the service daemons a SIGTERM and wait for them to terminate. 70 You can check the status of the <tt>previous</tt> runlevel through 71 <tt>/etc/runit/runsvdir/previous/</tt>. 72 <hr> 73 <a name="create"><h3>Creating new runlevels</h3></a> 74 To create a new runlevel, simply create a new directory in 75 <tt>/etc/runit/runsvdir/</tt>. 76 The name of the directory is the name of the new runlevel. 77 The name must not start with a dot and must not be <tt>current</tt>, 78 <tt>current.new</tt>, or <tt>previous</tt>, e.g.: 79 <pre> 80 # mkdir /etc/runit/runsvdir/maintenance 81 </pre> 82 Add the services you want to run in the runlevel <tt>maintenance</tt> to the 83 newly created directory, e.g.: 84 <pre> 85 # ln -s /etc/sv/getty-5 /etc/runit/runsvdir/maintenance/ 86 # ln -s /etc/sv/ssh /etc/runit/runsvdir/maintenance/ 87 # ln -s /etc/sv/dnscache /etc/runit/runsvdir/maintenance/ 88 </pre> 89 If you want to switch to the runlevel <tt>maintenance</tt>, do: 90 <pre> 91 # runsvchdir maintenance 92 </pre> 93 <hr> 94 <address><a href="mailto:pape@smarden.org"> 95 Gerrit Pape <pape@smarden.org> 96 </a></address> 97 </body> 98 </html>