/etc/ninit/ global special files
Special files in a service directory
in and out
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.
~$ 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|
This is the default home for ninit helpers.
~$ 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*
The most important program here is run. It start a service
checking different files in the service subdirectory.
Never start these files!
Please,
don't remove/rename/replace
the files here, unless you know what are you doing!
They are helpers for
ninit
and
nsvc.
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
remove it!
One good idea
is to make a symbolic link:
ln -s /bin/dash /etc/ninit/bin/sh
Then in all shell scripts in /etc/ninit/ three use on the first
line
#!/etc/ninit/bin/sh
...
You can replace also dash with bash or sh
above.
Since your scripts in /etc/ninit/ are simple (I suppose),
any fast, small, non-interactive shell is welcome.
One such candidate is the original Steve Bourne
sh from 1978.
A new port is available
here.
Install it under the name bsh in /bin/.
I recommend to build it using
dietlibc.
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.
Below all files {in|out}
are differnt from /etc/ninit/{in|out}
repectively.
A plain text file containing a service name per line.
Example: /etc/ninit/dnscache/depends
could contain tinydns.
Each of these services will be started before this service is
started. If you need to wait for static initializations to
complete, use the
sync flag.
See also the
wait
flag.
A symbolic link to the program name. No hard link, because
argv[0]
for the programs is created by extracting the part after the last
slash in the contents of the symbolic link.
Example: /usr/bin/sshd
would be run with argv[0]=sshd.
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.
Similar to depends. The helper
/etc/ninit/run adds
the contents of this file
to the system's environ. Example:
TERM=linux
PATH=/bin:/usr/bin:/usr/local/bin
UID=321
GID=432
BOOT_IMAGE
Since BOOT_IMAGE does not have "=" this variable is removed.
If the first line is empty then the system's environ is deleted first.
Similar to depends.
The helper /etc/inint/run
waits for services included in
this file to finish and after that start a current service.
Include wait services also in depends.
This is different from
sync 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.
It's possible to set wait parameters
(see maxwait) at the end of
each entry. Example:
some_service:180:3
other_service:300:5
A plain text file containing the values n1[:n2]. Wait no more
than n1 sec the services to finish. See also
wait. Default is 600 sec. The value n1=0
means - wait until the service finish.
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.
Similar to depends.
See Daniel Bernstein
softlimit
program.
Lines with the same options as
softlimit
(skip leading '-').
Example:
echo m3000000 > softlimit
echo o30 >> softlimit
echo f200000 >> softlimit
The helper
/etc/ninit/run execs the service with this restrictions.
Touch this file to make ninit respawn the process when it dies.
This should be touched for getty and network servers.
Touch this file to make ninit wait until the service ends. sync is
mutually exclusive with
respawn. This is meant for static
initializations like ifconfig. See also
wait.
If this directory exists, it is taken as service and ninit creates
a FIFO log/in and soft link of
log/in to out. It's equivalent to:
test -d log && mkfifo -m 600 log/in && ln -s log/in out
If the log
service can not be started, the service will block if it writes
to stdout. See also
log.
A plain text file containing the value to add to the nice level
via the nice system call.
A plain text file containing the value n. Sleep n secs after fork
before running child. Useful if respawning is very fast.
in (service's input)
This file (named pipe) is used for stdin.
out (service's output)
This file (named pipe) is used for stdout and stderr.
e.g. a symlink to /dev/null
It's possible to send the output of many services to one logger.
Let for example create one service with:
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, ...
Then in other service dir we can do:
echo logger >> depends
cd /path/to/sevirce-dir
ln -s ../logger/in out
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:
echo 23:99:240:320:100 > uid
start the service with:
UID=23, GID=99, GROUPS=99,240,320,100.
Similar to run.
After the service finish "end" will be executed.
The helper does not set environ, softlimit, uid restrictions.
You can put there for example:
#!/bin/sh
exec /bin/nsvc -C+3 service_name
Use this option instead of
sync or
wait mode. Let for example
services B,C,D must be started after A finish. There are two
possible solutions:
Bad: start A in sync mode
Good: start A i normal mode and put in "end"
#!/bin/sh
exec /bin/nsvc -o B C D
end is started with arguments:
$1=service_name $2=ninit_home $3=ninit_sysdir
Example:
#!/bin/sh
x=`echo $1 | tr '/' ':'`
rm -f /var/run/ninit-$x.pid
If this file exist it is started just before
/etc/ninit/service/run in
sync mode.
If
uid
or
softlimit exist they are applied first and
after that setup is executed. Example:
#!/bin/sh
PATH=/bin:/usr/bin
id; env
setup is started with arguments:
$1=service_name $2=ninit_home $3=ninit_sysdir $4=service_pid
Similar to
setup. It is executed before setup as root and
not softlimit, uid, in/out restrictions.
If you want
to modify some special files see the flag
sys-rsetup. Next create pidfile
before the service start. Remove the pidfile with
end after it finish.
#!/bin/sh
x=`echo $1 | tr '/' ':'`
echo $4 > /var/run/ninit-$x.pid
I really don't know why we need such
nonsense in /var/run/.
In my opinion pids in /var/run/ are outdated and
unreliable thinks!
Similar to
setup.
It is executed first (before rsetup and setup) as root.
It can even modify special files like
params, depends, wait, uid...
Example:
#!/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
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:
cd /etc/ninit/gpm
echo -n /var/run/gpm.pid > pidfile
See also the helper
ninit-pidfile.
If this file exist then /etc/ninit/sys/run
wait for SIGCONT before starting the service's run.
If this file exist then /etc/ninit/sys/run-wait
helper wait for SIGCONT before starting the service's run.
Example:
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
A plain text file containing two or three numbers per line.
Example:
echo 1d:2h7:0 > cron
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).
Last modified: 17 December 2009
Gratuitious blank lines added so that files.html#link works.