s6-svscan-not-1.html (4879B)
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: How to run s6-svscan under another init process</title> 7 <meta name="Description" content="s6: s6-svscan as not-init" /> 8 <meta name="Keywords" content="s6 supervision svscan s6-svscan init process boot" /> 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> How to run s6-svscan under another init process </h1> 20 21 <p> 22 You can have a reliable supervision tree even if s6-svscan is not your process 1. 23 The supervision tree just has to be <em>rooted</em> in process 1: that means that 24 your process 1 will have to supervise your s6-svscan process somehow. That way, 25 if s6-svscan dies, it will be restarted, and your set of services will always 26 be maintained. 27 </p> 28 29 <p> 30 Be aware, though, that pipes between services and loggers are maintained 31 by the s6-svscan process; if this process dies, the pipes will be closed and 32 some logs may be lost. 33 </p> 34 35 <a name="log"> 36 <h2> Logging the supervision tree's output </h2> 37 </a> 38 39 <p> 40 s6-svscan and the various s6-supervise processes might produce error or 41 warning messages; those messages are written to s6-svscan's stderr (which 42 is inherited by the s6-supervise processes). To log these messages: 43 </p> 44 45 <ul> 46 <li> You can use your init system's logging tools, and make your init 47 system launch s6-svscan as is; its stderr should already be taken care 48 of by the logging tools. </li> 49 <li> You can use a trick similar to the <a href="s6-svscan-1.html#log">process 50 1 output logging trick</a> so the supervision tree's messages are logged via 51 a service that's maintained by the supervision tree itself. Then your init 52 system should not launch s6-svscan directly, but a wrapper script that performs 53 the proper redirections. The 54 <tt>examples/s6-svscanboot</tt> file in the s6 distribution gives an example of 55 such a script. Make sure that your initial <a href="scandir.html">scan 56 directory</a> contains a <a href="servicedir.html">service directory</a> for your 57 initial logging service, that must read on the logging FIFO. </li> 58 </ul> 59 60 <p> 61 In some of the following examples, we'll assume that <tt>/command/s6-svscanboot</tt> 62 is the name of the script you are using to start s6-svscan. We will also assume 63 that all of the s6 executables are available through the <tt>/command</tt> path. 64 Adjust this accordingly. 65 </p> 66 67 <a name="sysv"> 68 <h2> System V init </h2> 69 </a> 70 71 <p> 72 Put an appropriate line in your <tt>/etc/inittab</tt> file, then reload this 73 config file with <tt>telinit q</tt>. 74 </p> 75 76 <h3> Example </h3> 77 78 <pre> SV:123456:respawn:/command/s6-svscanboot </pre> 79 80 81 <a name="upstart"> 82 <h2> Upstart </h2> 83 </a> 84 85 <p> 86 Put an appropriate configuration file in the <tt>/etc/init</tt> folder, 87 for instance <tt>/etc/init/s6-svscan.conf</tt>, then start the service 88 with <tt>start s6-svscan</tt>. 89 </p> 90 91 <h3> Example </h3> 92 93 <pre># s6-svscan 94 start on runlevel [2345] 95 stop on runlevel [!2345] 96 97 oom never 98 respawn 99 exec /command/s6-svscanboot 100 </pre> 101 102 <a name="systemd"> 103 <h2> systemd </h2> 104 </a> 105 106 <p> 107 Put an appropriate unit file in the <tt>/etc/systemd/system</tt> folder, 108 for instance <tt>/etc/systemd/system/s6.service</tt>. It will be picked 109 up by systemd at boot time. 110 </p> 111 112 <h3> Example </h3> 113 114 <pre>[Unit] 115 Description=s6 supervision tree 116 Documentation=https://skarnet.org/software/s6/ 117 118 [Install] 119 WantedBy=multi-user.target 120 121 [Service] 122 Type=simple 123 ExecStart=/command/s6-svscan /run/service 124 ExecReload=/command/s6-svscanctl -an /run/service 125 Restart=always 126 RestartSec=1 127 KillMode=mixed 128 </pre> 129 130 <p> 131 Please note that, among other things, systemd performs process supervision, 132 so depending on the level of integration with your distribution that you 133 wish to achieve, you may be better off using systemd to directly manage 134 your daemons. Please also note that systemd is a 135 <a href="//skarnet.org/software/systemd.html">terrible piece of software engineering</a>, and 136 if at all possible, you should try and switch to a distribution that does 137 not use it. 138 </p> 139 140 <a name="bsd"> 141 <h2> BSD init </h2> 142 </a> 143 144 <p> 145 Put an appropriate line in your <tt>/etc/ttys</tt> file, then reload this 146 file with <tt>kill -s HUP 1</tt>. 147 </p> 148 149 <h3> Example </h3> 150 151 <pre> sv /command/s6-svscanboot "" on </pre> 152 153 <a name="launchd"> 154 <h2> MacOS launchd </h2> 155 </a> 156 157 <p> 158 Like systemd, launchd comes with its own 159 <a href="https://developer.apple.com/library/mac/documentation/macosx/conceptual/bpsystemstartup/chapters/CreatingLaunchdJobs.html">way 160 of supervising services</a>; if you are a launchd user, you probably do 161 not need s6. 162 </p> 163 164 165 </body> 166 </html>