s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

socket-activation.html (5050B)


      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: socket activation</title>
      7     <meta name="Description" content="s6: socket activation" />
      8     <meta name="Keywords" content="s6 socket activation fd-holding client server socket fd passing" />
      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 do I perform socket activation with s6&nbsp;? </h1>
     20 
     21 <p>
     22  First, it's important to realize that you don't <em>need</em>
     23 socket activation. It's a marketing word used by systemd
     24 advocates that mixes a couple useful architecture concepts and several
     25 horrible ideas, for a very minor speed benefit. Read
     26 <a href="//skarnet.org/lists/supervision/0422.html">this mail</a> and
     27 <a href="https://forums.gentoo.org/viewtopic-t-994548-postdays-0-postorder-asc-start-25.html#7581522">this
     28 post</a> for details.
     29 </p>
     30 
     31 <ul>
     32  <li> s6 <em>will not</em> help you implement super-servers in process 1,
     33 because doing so is bad engineering.
     34 However, it <em>will</em> help you set up super-servers. The
     35 <a href="s6-ipcserver.html">s6-ipcserver</a>
     36 program, for Unix domain sockets, as well as the
     37 <a href="//skarnet.org/software/s6-networking/s6-tcpserver.html">s6-tcpserver</a>
     38 program, for TCP INET domain sockets (available in the
     39 <a href="//skarnet.org/software/s6-networking/">s6-networking</a>
     40 package) are super-servers you can use to
     41 your heart's content. They are even wrappers around simpler programs,
     42 and you can use their components in the way you choose: bind sockets,
     43 drop privileges, accept connections from clients, it's all about what you
     44 write in your command line. Super-servers are a good thing; using process 1
     45 to act as a super-server is not. s6 provides you with the tools to get
     46 the good without the bad. </li>
     47  <li> s6 <em>will not</em> help you run all your services before their
     48 dependencies are met, because doing so is <em>very</em> bad engineering.
     49 However, it <em>will</em> provide you with:
     50  <ul>
     51   <li> a reliable logging infrastructure, that makes sure your services
     52 never lose logs:
     53 <a href="s6-log.html">s6-log</a>, in conjunction with
     54 <a href="s6-supervise.html">s6-supervise</a> and
     55 <a href="s6-svscan.html">s6-svscan</a>. </li>
     56   <li> ways to open your sockets and bind them as early as you want in
     57 your boot process, and make them accept client connections later:
     58 <a href="s6-ipcserver-socketbinder.html">s6-ipcserver-socketbinder</a> and
     59 <a href="//skarnet.org/software/s6-networking/s6-tcpserver-socketbinder.html">s6-tcpserver-socketbinder</a>.
     60  </li>
     61  <li> A supervision infrastructure that can start as many services in parallel
     62 as you want:
     63 <a href="s6-supervise.html">s6-supervise</a> and
     64 <a href="s6-svscan.html">s6-svscan</a>. </li>
     65  </ul> </li>
     66  <li> s6 <em>will not</em> help you centralize all your socket information
     67 in process 1, because doing so is contrary to modularity and independence
     68 of services. However, s6
     69 <em>will</em> provide you with a way to store your open sockets and
     70 retrieve them when you want, which it calls "fd holding":
     71 <a href="s6-fdholder-daemon.html">s6-fdholder-daemon</a>. </li>
     72 </ul>
     73 
     74 <h2> So, how do I open all my sockets first, store them, and dispatch them
     75 to daemons later&nbsp;? </h2>
     76 
     77 <p>
     78  Again, it's not necessary to do that: you'll be fine, and quite speedy,
     79 just starting your
     80 daemons in their good time. You <em>will not</em> reap any noticeable
     81 benefit from performing "socket activation". But if you really want to:
     82 </p>
     83 
     84 <ol>
     85  <li> Make sure you have an early supervision infrastructure running.
     86 Ideally, you would <a href="s6-svscan-1.html">make s6-svscan your
     87 process 1</a>. </li>
     88  <li> Start an early <a href="s6-fdholder-daemon.html">fd-holding
     89 service</a>. Let's say the fd-holding daemon is listening on socket
     90 <tt>/service/fdholder/s</tt>. </li>
     91  <li> For every Unix domain socket <em>/my/socket</em> you need to open, run
     92 <tt>s6-ipcserver-socketbinder /my/socket s6-fdholder-store /service/fdholder/s
     93 unix:/my/socket</tt>. You can do the same with INET domain sockets. </li>
     94  <li> Proceed to your initialization. </li>
     95  <li> When you want to run a daemon <em>myserverd</em> that accepts clients
     96 connecting to <em>/my/socket</em>, run <tt>s6-fdholder-retrieve
     97 /service/fdholder/s unix:/my/socket myserverd</tt>. <em>myserverd</em>
     98 will be executed with <em>/my/socket</em> as its standard input. </li>
     99  <li> The descriptors remain safely stored in the fd-holding daemon and you
    100 can retrieve them again whenever you want, for instance when your service
    101 crashes and is restarted. </li>
    102 </ol>
    103 
    104 <p>
    105  That is all there is to it. You don't have to use specific libraries
    106 or write complex unit files, you just need to understand how a command
    107 line works. This is Unix.
    108 </p>
    109 
    110 </body>
    111 </html>