about summary refs log tree commit diff
path: root/doc/s6-svlisten.html
blob: 96d3f74f88f6acf6467c5cbe4091a8827c8253ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-Language" content="en" />
    <title>s6: the s6-svlisten program</title>
    <meta name="Description" content="s6: the s6-svlisten program" />
    <meta name="Keywords" content="s6 command s6-svlisten notification service waiting" />
    <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> -->
  </head>
<body>

<p>
<a href="index.html">s6</a><br />
<a href="//skarnet.org/software/">Software</a><br />
<a href="//skarnet.org/">skarnet.org</a>
</p>

<h1> The s6-svlisten program </h1>

<p>
 s6-svlisten runs a program while listening on notifications from
a collection of supervised services, and blocks until they all go up, or down.
</p>

<p>
 s6-svlisten only waits for notifications; it never polls.
</p>

<h2> Interface </h2>

<p>
 In an execline script:
</p>

<pre>
     s6-svlisten [ -U | -u | -D | -d | -r | -R ] [ -a | -o ] [ -t <em>timeout</em> ] { <em>servicedir</em> <em>servicedir...</em> } <em>prog...</em>
</pre>

<p>
 Outside of an execline script:
</p>

<pre>
     s6-svlisten [ -U | -u | -D | -d | -r | -R ] [ -a | -o ] [ -t <em>timeout</em> ] <em>servicedir</em> <em>servicedir...</em> "" <em>prog...</em>
</pre>

<ul>
 <li> s6-svlisten checks the state of one or more <a href="servicedir.html">service
directories</a> given as arguments in the first block and monitor
their state changes. </li>
 <li> It spawns <em>prog...</em> as a child right after getting the
initial state of all the monitored services. </li>
 <li> It then blocks until the wanted state happens. </li>
 <li> If no service directories are listed (the block is empty), then
instead of doing all that, it immediately execs into <em>prog...</em>.
</ul>

<h2> Exit codes </h2>

<ul>
 <li> 0: success, the wanted state has been reached </li>
 <li> 99: timed out </li>
 <li> 100: wrong usage </li>
 <li> 102: the <a href="s6-supervise.html">s6-supervise</a> process monitoring the service died </li>
 <li> 111: system call failed </li>
 <li> <em>n</em>: services were expected to come up, but <em>n</em> of them
reported permanent failure </li>
</ul>

<h2> Options </h2>

<ul>
 <li> <tt>-u</tt>&nbsp;: up. s6-svlisten will wait until the services are up, as
reported by s6-supervise.
This is the default; it is not reliable, but it does not depend on specific
support in the service programs. See <a href="notifywhenup.html">this page</a>
for details. </li>
 <li> <tt>-U</tt>&nbsp;: really up. s6-svlisten will wait until the services are
up <em>and</em> ready as reported by the services themselves. This requires
specific support in the service programs, and the use of the
<tt>notification-fd</tt> file in the
<a href="servicedir.html">service directory</a>.
See the explanation on <a href="notifywhenup.html">this page</a>. </li>
 <li> <tt>-d</tt>&nbsp;: down. s6-svlisten will wait until the services are down. </li>
 <li> <tt>-D</tt>&nbsp;: really down. s6-svlisten will wait until the
services are down and the cleanup scripts in <tt><em>servicedir</em>/finish</tt>
for every <em>servicedir</em>
have finished executing (or have timed out and been killed). </li>
 <li> <tt>-r</tt>&nbsp;: restart. s6-svlisten will wait until all
the services have been started or restarted, i.e. they have been in
the down state, then the up state. </li>
 <li> <tt>-R</tt>&nbsp;: restart and ready. s6-svlisten will wait until
all the services have been started or restarted and have notified
readiness. </li>
 <li> <tt>-o</tt>&nbsp;: or. s6-svlisten will wait until <em>one</em> of the
given services comes up or down. </li>
 <li> <tt>-a</tt>&nbsp;: and. s6-svlisten will wait until <em>all</em> of the
given services come up or down. This is the default. </li>
 <li> <tt>-t&nbsp;<em>timeout</em></tt>&nbsp;: if the requested events have not
happened after <em>timeout</em> milliseconds, s6-svlisten will print a message
to stderr and exit 99. By default, <em>timeout</em> is 0, which means no time
limit. </li>
</ul>

<h2> Notes </h2>

<ul>
 <li> s6-svlisten is the service-specific version of
<a href="s6-ftrig-listen.html">s6-ftrig-listen</a>. The point of s6-svlisten
is to use it to spawn a program such as <a href="s6-svc.html">s6-svc</a>,
in order to send signals to services while making sure to catch their
state changes - thus avoiding the race condition that occurs when running
<a href="s6-svc.html">s6-svc</a> then <a href="s6-svwait.html">s6-svwait</a>
sequentially. </li>
 <li> s6-svlisten needs to handle a variable length list of service directories.
For that, it uses an encoding provided by
<a href="//skarnet.org/software/execline/">execline</a>, so it's best
to only use it in execline scripts (only the execline syntax is guaranteed
not to change). There is a variant of s6-svlisten that does not use execline
syntax, but only handles one service directory:
<a href="s6-svlisten1.html">s6-svlisten1</a>. </li>
 <li> The <tt>-R</tt> or <tt>-r</tt> options imply the <tt>-a</tt> option.
It is not possible to wait for one of the listed services to restart. </li>
</ul>

</body>
</html>