scandir.html (6147B)
1 <html> 2 <head> 3 <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 5 <meta http-equiv="Content-Language" content="en" /> 6 <title>s6: scan directories</title> 7 <meta name="Description" content="s6: scan directory" /> 8 <meta name="Keywords" content="s6 scandir supervision svscan s6-svscan scan directory servicedir" /> 9 <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> --> 10 </head> 11 <body> 12 13 <p> 14 <a href="index.html">s6</a><br /> 15 <a href="//skarnet.org/software/">Software</a><br /> 16 <a href="//skarnet.org/">skarnet.org</a> 17 </p> 18 19 <h1> Scan directories </h1> 20 21 <p> 22 A <em>scan directory</em> is a directory containing a list of 23 <a href="servicedir.html">service directories</a>, or symbolic links 24 pointing to service directories. 25 </p> 26 27 <p> 28 A scan directory represents a list of services that are supposed to 29 be supervised. Running <a href="s6-svscan.html">s6-svscan</a> on this 30 scan directory launches a <em>supervision tree</em>: every service 31 listed in the scan directory will be supervised. 32 </p> 33 34 <p> 35 There is normally only one scan directory per system, although nothing 36 prevents a system administrator from having more. 37 <a href="https://cr.yp.to/daemontools.html">daemontools</a> traditionally 38 uses <tt>/service</tt>, and <a href="http://smarden.org/runit/">runit</a> 39 traditionally uses <tt>/etc/service</tt>. s6 does not care where your 40 scan directory is, but I would advise <tt>/service</tt> for compatibility 41 with daemontools. Depending on your installation, <tt>/service</tt> could 42 be a symbolic link and point to a place either in a RAM filesystem or in 43 <tt>/var</tt>. 44 </p> 45 46 <a name="where"> 47 <h2> Where and how to build a scan directory </h2> 48 </a> 49 50 <p> 51 Opinions and practices differ. 52 </p> 53 54 <p> 55 It is generally accepted that the place where you store all your 56 service directories (your "service repository") should <em>not</em> be 57 used as a scan directory - for a simple reason: you might want to have 58 service directories for more services than what you want to start at 59 any given time. In other words, your scan directory will be a <em>subset</em> 60 of your service repository, so you cannot just run s6-svscan on every 61 service you have a service directory for. So, the first thing is to 62 separate your <em>service repository</em>, which is just a storage place 63 for all the services you might want to manage someday, and your <em>scan 64 directory</em>, which is a directory representing all the services that 65 you are <em>currently</em> managing. 66 </p> 67 68 <h3> Service repository </h3> 69 70 <p> 71 Where to store your service repository is purely a matter of personal 72 preference. You just have to be aware that <a href="s6-supervise.html"> 73 s6-supervise</a> needs writable <tt>supervise</tt> and <tt>event</tt> 74 subdirectories in a service directory it monitors. 75 </p> 76 77 <h3> Scan directory </h3> 78 79 <p> 80 Where and how to build your scan directory depends heavily on your boot 81 system - and on your personal preference too. 82 </p> 83 84 <p> 85 Standard <a href="https://cr.yp.to/daemontools.html">daemontools</a> and 86 <a href="http://smarden.org/runit/">runit</a> installations like to have 87 a fixed scan directory containing symlinks to service directories located 88 in the service repository. In other words, the service repository contains 89 the real <em>working copies</em> of the service directories. This works, 90 as long as: 91 </p> 92 93 <ul> 94 <li> It is possible to create writable <tt>supervise</tt> and <tt>event</tt> 95 subdirectories in every managed service directory. This can be achieved for 96 instance via symlinks, or by having the service repository stored on a writable 97 filesystem. </li> 98 <li> The scan program (<a href="s6-svscan.html">s6-svscan</a>, 99 <a href="https://cr.yp.to/daemontools/svscan.html">svscan</a>, 100 <a href="http://smarden.org/runit/runsvdir.8.html">runsvdir</a>...) is 101 started late enough for all the necessary filesystems to be mounted. </li> 102 </ul> 103 104 <p> 105 My own recommendation would be to have working copies of the service 106 directories <em>entirely separate</em> from the service repository. The 107 service repository can be safely stored on the root filesystem, and the 108 needed directories copied to a RAM filesystem at boot time. The scan 109 directory can be either the place where the working copies are written, 110 or another directory containing symlinks to those working copies. (The 111 latter is useful if you are using the <tt>-t</tt> option to 112 <a href="s6-svscan.html">s6-svscan</a> with a nonzero argument: copying a 113 directory is not atomic, but making a symlink is, so there is no risk 114 of your scanner finding a directory while it is being copied - which 115 could result in <a href="s6-supervise.html">s6-supervise</a> getting 116 the wrong information and not managing the service properly.) 117 </p> 118 119 <p> 120 An example: 121 </p> 122 123 <ul> 124 <li> Have your service repository in <tt>/img/services</tt>, i.e. have 125 service directories in <tt>/img/services/ftpd</tt>, <tt>/img/services/httpd</tt>, 126 <tt>/img/services/sshd</tt>, etc. </li> 127 <li> When booting, make <tt>/tmp</tt> a RAM filesystem, and create the 128 directories <tt>/tmp/services</tt> and <tt>/tmp/service</tt>. </li> 129 <li> Have s6-svscan run on <tt>/tmp/service</tt>, as early as possible in your 130 boot sequence. This is possible whether you want to run s6-svscan 131 <a href="s6-svscan-1.html">as process 1</a> or <a href="s6-svscan-not-1.html">not</a>. </li> 132 <li> During the boot sequence, populate <tt>/tmp/services</tt> with copies of the 133 service directories you need: for instance, 134 <ul> 135 <li> <tt>cp -a /img/services/sshd /tmp/services/sshd</tt> </li> 136 <li> <tt>cp -a /img/services/ftpd /tmp/services/ftpd</tt> </li> 137 <li> etc. </li> 138 </ul> </li> 139 <li> When you are ready to start a service, make a symlink in the 140 <tt>/tmp/service</tt> <em>scan directory</em> pointing to the working copy of 141 the service directory you need in <tt>/tmp/services</tt>, then notify s6-svscan. 142 For instance, to start ftpd and httpd together: 143 <pre> ln -s ../services/ftpd /tmp/service 144 ln -s ../services/httpd /tmp/service 145 s6-svscanctl -a /tmp/service</pre> </li> 146 </ul> 147 148 </body> 149 </html>