aboutsummaryrefslogtreecommitdiff
path: root/riemann.fmi.uni-sofia.bg/ninit/files.html
blob: b819cf6e6a90bab324afcaa301846b103dbf401d (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<html>
<link rel="stylesheet" type="text/css" href="style.css">
<title>files</title>
<body>

<div class="top">
<ul class="nav">
  <li><a href="all.html">All files</a>
</ul>
<div class="endtop"></div>
</div>


<h2>/etc/ninit/ global special files</h2>
<table>
<td><ul><li><a href=#Gin>~/in</a><li></ul>
<td><ul><li><a href=#Gin>~/out</a><li></ul>
<td><ul><li><a href=#Grun>~/sys/</a><li></ul>
<td><ul><li><a href=#Gbin>~/bin/</a><li></ul>
</td>
</table>

<h2>Special files in a service directory</h2>


<table>
<td>
<ul>
<li><a href="#In">in</a></li>
<li><a href="#Out">out</a></li>
<li><a href="#Run">run</a></li>
<li><a href="#Log">log/</a></li>
</ul>

<td>
<ul>
<li><a href="#Depends">depends</a></li>
<li><a href="#Params">params</a></li>
<li><a href="#Respawn">respawn</a></li>
<li><a href="#Sync">sync</a></li>
</ul>


<td>
<ul>
<li><a href="#Environ">environ</a></li>
<li><a href="#Softlimit">softlimit</a></li>
<li><a href="#End">end</a></li>
<li><a href="#Uid">uid</a></li>
</ul>

<td>
<ul>
<!-- <li><a href="#Gid">gid</a></li> -->
<li><a href="#Nice">nice</a></li>
<li><a href="#Sleep">sleep</a></li>
<li><a href="#Alarm">alarm</a></li>
<li><a href="#Pidfile">pidfile</a></li>
<td>


<td>
<ul>
<li><a href="#Wait">wait</a></li>
<li><a href="#Maxwait">maixwait</a></li>
<li><a href="#Pause">pause</a></li>
<li><a href="#Pause">pause-wait</a></li>
</ul>
</td>

<td>
<ul>
<li><a href="#Cron">cron</a></li>
<li><a href="#Setup">setup</a></li>
<li><a href="#Rsetup">rsetup</a></li>
<li><a href="#Sys-rsetup">sys-rsetup</a></li>
</ul>
</td>
</table>



<h2><a name=Gin>~/{in|out}</a></h2>
<tt>in</tt> and <tt>out</tt> 
are the FIFOs ninit communicates with its helper programs.
Those have to exist before ninit is started and 
they should be owned by root and have mode 600.
<pre>
~$ ls -l /etc/ninit/in /etc/ninit/out 
prw-------    1 root     root        0 Jan 15 11:14 /etc/ninit/in|
prw-------    1 root     root        0 Jan 15 11:14 /etc/ninit/out|
</pre>

<h2><a name=Grun>~/sys/</a></h2>
This is the default home for ninit helpers.
<pre>
~$ ls -lf /etc/ninit/sys
-rwxr-xr-x    1 root     root     2340 Jan 12 22:28 procfs*
-rwxr-xr-x    1 root     root     1688 Jan 12 22:28 remove*
-rwxr-xr-x    1 root     root     3796 Jan 12 22:28 run*
-rwxr-xr-x    1 root     root     4428 Jan 12 22:28 run-wait*
-rwxr-xr-x    1 root     root     1924 Jan 12 22:28 update*
</pre>
The most important program here is <b>run</b>.  It start a service
checking different files in the service subdirectory.
Never start these files!  
Please, 
<b><font color=magenta>don't remove/rename/replace</font></b>
the files here, unless you know what are you doing!
They are helpers for 
<b>ninit</b>
and
<b>nsvc</b>.

<!--
Helper program - it's ninit's right-hand.  
<font size=+1 color=red>Never remove it !!!</font>
You can replace it with a test version using:
<pre>
	install /path/to/run.test /etc/ninit/run
</pre>
-->

<h2><a name=Gbin>~/bin/</a></h2>
Here I put some programs which are useful for something.
Ninit daemons don't need to start any of them.  
If you dislike this directory, simply 
<b><font color=magenta>remove</font></b> it!

One <b>good idea</b>
is to make a symbolic link:
<pre>
ln -s /bin/dash /etc/ninit/bin/sh
</pre>
Then in all shell scripts in /etc/ninit/ three use on the first
line 
<pre>
#!/etc/ninit/bin/sh
...
</pre>
You can replace also <b>dash</b> with <b>bash</b> or <b>sh</b>
above.  
Since your scripts in <b>/etc/ninit/</b> are simple (I suppose),
any fast, small, non-interactive shell is welcome.
One such candidate is the original Steve Bourne 
<b>sh</b> from 1978.
A new port is available 
<a href=/sh/>here</a>.
Install it under the name <b>bsh</b> in /bin/.
I recommend to build it using 
<a href=http://www.fefe.de/dietlibc/>dietlibc</a>.

<p> Why I suggest the symbolic link above?  I suppose that
in the future someone can write a better shell.  Then
we will update only the link - there is no need to edit each 
script.

<p>
<hr>
<p>

Below all files <tt>{in|out}</tt>
are differnt from <tt>/etc/ninit/{in|out}</tt>
repectively.

<h2><a name="Depends">depends</a></h2>
    A plain text file containing a service name per line.
    Example: <tt>/etc/ninit/dnscache/depends</tt> 
    could contain <tt>tinydns</tt>.
    Each of these services will be started before this service is
    started.  If you need to wait for static initializations to
    complete, use the 
    <a href=#Sync>sync</a> flag.  
    See also the 
    <a href=#Wait>wait</a> 
    flag.

<h2><a name="Run">run (service's executable)</a></h2>

    A symbolic link to the program name.  No hard link, because 
    <tt>argv[0]</tt>
    for the programs is created by extracting the part after the last
    slash in the contents of the symbolic link.
    <br>
    Example: <tt>/usr/bin/sshd</tt> 
    would be run with <tt>argv[0]=sshd</tt>.

<h2><a name="Params">params</a></h2>

    A plain text file containing command line parameters for the
    service, one parameter per line.  No shell expansion is done.  If
    you need shell expansion, have run point to a shell script instead
    of the real daemon.  Note: Have the shell script exec the daemon
    instead of simply running it to save system resources.


<h2><a name="Environ">environ</a></h2>
    Similar to depends.  The helper
    <tt>/etc/ninit/run</tt> adds 
    the contents of this file
    to the system's environ.  Example:
<pre>
TERM=linux
PATH=/bin:/usr/bin:/usr/local/bin
UID=321
GID=432
BOOT_IMAGE
</pre>
Since BOOT_IMAGE does not have "<b>=</b>" this variable is removed.
If the first line is empty then the system's environ is deleted first.


<h2><a name="Wait">wait</a></h2>
    Similar to depends.  
    The helper <tt>/etc/inint/run</tt> 
    waits for services included in 
    this file to finish and after that start a current service.
    Include wait services also in depends.  
    <p>
    This is different from 
    <a href=#Sync>sync</a> flag.
    Let the service B must be started after the service A finish.
    One can sync A.  This will block all other services.
    In this case it's better to use wait instead of sync.
    <p>
    It's possible to set wait parameters 
    (see <a href=#Maxwait>maxwait</a>) at the end of
    each entry.  Example: 
<pre>
some_service:180:3</tt>
other_service:300:5</tt>
</pre>

<h2><a name="Maxwait">maxwait</a></h2>

    A plain text file containing the values n1[:n2].  Wait no more
    than n1 sec the services to finish.  See also
    <a href="#Wait">wait</a>.  Default is 600 sec.  The value n1=0
    means - wait until the service finish.

<h2><a name="Alarm">alarm</a></h2>

    A plain text file containing the value n.
    Execs alarm(n) before starting the child.  It's timeout like.
    Don't use this for services which catch SIGALRM signal.

<h2><a name="Softlimit">softlimit</a></h2>
    Similar to depends.
    See Daniel Bernstein 
    <a href=http://cr.yp.to/daemontools/softlimit.html>softlimit</a>
    program.  
    <br>
    Lines  with the same options as 
    <a href=http://cr.yp.to/daemontools/softlimit.html>softlimit</a>
    (skip leading '-').
    Example:
<pre>
	echo m3000000 > softlimit
	echo o30 >> softlimit
	echo f200000 >> softlimit
</pre>
The helper 
<tt>/etc/ninit/run</tt> execs the service with this restrictions.

<h2><a name="Respawn">respawn</a></h2>

    Touch this file to make ninit respawn the process when it dies.
    This should be touched for getty and network servers.

<h2><a name="Sync">sync</a></h2>

    Touch this file to make ninit wait until the service ends.  sync is
    mutually exclusive with 
    <a href=#Respawn>respawn</a>.  This is meant for static
    initializations like <tt>ifconfig</tt>.  See also 
    <a href="#Wait">wait</a>.
<!--
    If sync contains a nonzero number n ninit will wait max n sec
    the service to finish.  If it does not ends until n secs then 
    ninit continues to start the other services.
-->

<h2><a name="Log">log/</a></h2>

    If this directory exists, it is taken as service and ninit creates
    a FIFO <tt>log/in</tt> and soft link of 
    <tt>log/in</tt> to <tt>out</tt>.  It's equivalent to:
<pre>
    test -d log  && mkfifo -m 600 log/in  && ln -s log/in out    
</pre>
    If the log 
    service can not be started, the service will block if it writes 
    to stdout.  See also 
    <a href="subdirs.html#Log">log</a>.

<h2><a name="Nice">nice</a></h2>

    A plain text file containing the value to add to the nice level
    via the nice system call.

<h2><a name="Sleep">sleep</a></h2>

    A plain text file containing the value n.  Sleep n secs after fork
    before running child.  Useful if respawning is very fast.

<h2><a name="In">in</a> (service's input)</h2>

    This file (named pipe) is used for stdin.

<h2><a name="Out">out</a> (service's output)</h2>

    This file (named pipe) is used for stdout and stderr.
    e.g. a symlink to /dev/null
<p>
It's possible to send the output of many services to one logger.
Let for example create one service with:
<pre>
	cd /etc/ninit
	mkdir logger && cd logger
	mkfifo logger/in
	ln -s /path/to/multilog run
	echo -n 721 > uid
	# setup: params, softlimit, depends, environ, uid, ...
</pre>
Then in other service dir we can do:
<pre>
	echo logger >> depends
	cd /path/to/sevirce-dir
	ln -s ../logger/in out
</pre>

<!--
</pre>
<h2><a name="Gid">gid</a></h2>
    
    A plain text file containing a number.
    Exec the program with this GID.  
-->

<h2><a name="Uid">uid</a></h2>
    A plain text file containing a number.
    Exec the program with this UID.  It's possible to write
    also UID:GID.  It's better to use UID, GID smaller than 65530.
 It is possible to write here also the supplementary groups.
    For example:
<pre>
	echo 23:99:240:320:100 > uid 
</pre>
    start the service with:
    UID=23, GID=99, GROUPS=99,240,320,100.

<h2><a name="End">end (service's executable)</a></h2>

    Similar to <a href=#Run>run</a>.  
    After the service finish "end" will be executed.
    The helper does not set environ, softlimit, uid restrictions.
    You can put there for example:
<pre>
	#!/bin/sh
	exec /bin/nsvc -C+3 service_name
</pre>
    Use this option instead of 
    <a href=#Sync>sync</a> or
    <a href=#Wait>wait</a> mode.  Let for example
    services B,C,D must be started after A finish.  There are two
    possible solutions:
<br>
<font color=red>Bad</font>: &nbsp; start A in sync mode
<br>
<font color=green>Good</font>: start A i normal mode and put in "end"
<pre>
	#!/bin/sh
	exec /bin/nsvc -o B C D
</pre>
<b>end</b> is started with arguments:
<pre>
	$1=service_name  $2=ninit_home  $3=ninit_sysdir
</pre>
Example:
<pre>
	#!/bin/sh
	x=`echo $1 | tr '/' ':'`
	rm -f /var/run/ninit-$x.pid 
</pre>

<h2><a name="Setup">setup</a></h2>

    If this file exist it is started just before 
    <tt>/etc/ninit/service/run</tt> in 
    sync mode.
    If 
    <a href="#Uid">uid</a>
    or 
    <a href="#Softlimit">softlimit</a> exist they are applied first and 
    after that setup is executed. Example:
<pre>
	#!/bin/sh
	PATH=/bin:/usr/bin
	id; env
</pre>
    <b>setup</b> is started with arguments:
<pre>
	$1=service_name  $2=ninit_home  $3=ninit_sysdir  $4=service_pid
</pre>
  
<h2><a name="Rsetup">rsetup</a></h2>
    Similar to 
    <a href="#Setup">setup</a>.  It is executed before setup as root and
    not softlimit, uid, in/out restrictions.  
    <br>
    If you want
    to modify some special files see the flag 
    <a href="#Sys-rsetup">sys-rsetup</a>.  Next create pidfile
    before the service start.  Remove the pidfile with
    <a href=#End>end</a> after it finish.
<pre>
	#!/bin/sh
	x=`echo $1 | tr '/' ':'`
	echo $4 > /var/run/ninit-$x.pid 
</pre>    
I really don't know why we need such 
<font color=magenta>nonsense</font> in <i>/var/run/</i>.
In my opinion pids in <i>/var/run/</i> are outdated and 
unreliable thinks!


<h2><a name="Sys-rsetup">sys-rsetup</a></h2>
    Similar to 
    <a href="#Setup">setup</a>.  
    It is executed first (before rsetup and setup) as root.
<br>
    It can even modify special files like
    params, depends, wait, uid...
<br> Example:
<pre>
	#!/bin/sh
	
	export PATH=/bin:/usr/bin
	umask 022
	
	if test -f "uid-gid" ; then
	   a=`read name < uid-gid` 
	   echo -n `id -u $name` > uid
	   echo -n :`id -g $name` >> uid
	fi
</pre>

<h2><a name="Pidfile">pidfile</a></h2>
    This is an easy method to setup a service which run in background.
    Prepare it as ordinary service and write only
    the name of the pidfile.  Don't use links for pidfile!
    Example:
<pre>
	cd /etc/ninit/gpm 
	echo -n /var/run/gpm.pid > pidfile
</pre>
    See also the helper
    <a href=man/pidfile.man>ninit-pidfile</a>.

<h2><a name="Pause">pause</a></h2>
   If this file exist then <tt>/etc/ninit/sys/run</tt>
   wait for SIGCONT before starting the service's run.

<h2><a name="Pause-wait">pause-wait</a></h2>
   If this file exist then <tt>/etc/ninit/sys/run-wait</tt>
   helper wait for SIGCONT before starting the service's run.
   Example:
<pre>
x=/tmp/__test;  mkdir $x;  cd $x
ln -s `which date` run
touch pause;   touch pause-wait
nsvc -o $x

nsvc $s;  sleep 3;   nsvc -c $x
nsvc $x;  sleep 3;   nsvc -c $x
nsvc $x
</pre>

<h2><a name="Cron">cron</a></h2>
A plain text file containing two or three numbers per line. 
Example:
<pre>
echo 1d:2h7:0 > cron
</pre>
The service will be started on 02:07:00 UTC every day.
If the third number is nonzero the service will be started
first time immediately (not waiting for cron timestamp).


<p>
Last modified: 17 December 2009

<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

Gratuitious blank lines added so that files.html#link works.

</body>
</html>