run
scripts conventionally use simple tools, that chain load from one tool to the next, to set up a dæmon's process state.
There is quite a large toolset available for this.
These are just some of most widely used chain loading commands.
For exposition, each command here omits the trailing argument vector, which is the rest of the commands to chain to.
That is determined by the script as a whole.
In a script interpreted by nosh
or Laurent Bercot's execlineb
, one could (for readability) place these commands on individual lines.
In a POSIX-conformant shell script, these would have to be all on a single logical line (possibly comprising multiple physical lines joined by backslashed newlines).
setuidgid myservice-d
Drop privileges and operate henceforth under the aegis of user account myservice-d
, the (dedicated) user account for this service.
envuidgid myservice-d
Set up the environment with the ID information of user account myservice-d
, the (dedicated) user account for this service.
setuidgid-fromenv
Drop privileges and operate henceforth under the aegis of the user account whose ID information is given in the environment.
chdir dir
Change process working directory to dir
.
envdir env/
Process the environment directory env/
.
An environment directory with this this name, specifically, is compatible with the get
and set
commands to rcctl
.
softlimit -o 2048
Adjust the soft limit on the number of open file descriptors (in each dæmon process of the service) to 2048.
fdredir -r 0 seed
Redirect standard input to read from an existing file named seed
.
jexec wibble
Switch to running in (BSD) jail wibble
, which (presumably) another service is maintaining with the jail
command.
rtprio 1
Run with (BSD) realtime scheduling policy at priority 1.
chrt --batch 1
Run with (Linux) SCHED_BATCH
scheduling policy at priority 1.
tcp-socket-listen --backlog 2 --combine4and6 "::0" smtp
Listen, with a backlog of two pending connections, to the SMTP Relay port on all IPv6 and (if the system supports it) IPv4 addresses.
The chained-to program receives the listening socket file descriptor at a well-known, fixed, position.
If it needs the systemd convention for this, use the --systemd-compatibility
option.
tcp-socket-accept --connection-limit 16
Accept connections on a pre-supplied listening socket, limiting the number of concurrent active accepted connection service processes to 16.
Multiple chained-to programs are forked, here.
The convention is to use another script, such as ./service
, for the chained-to program.
This permits adjustment of the service command on the fly, without need for stopping and restarting the service itself.
ucspi-socket-rules-check
Apply a UCSPI-TCP/UCSPI-UNIX access control ruleset.
line-banner 'Hello there!'
Print Hello there!
to standard output.
Some server programs, such as Bernstein's publicfile FTP server, expect their initial greetings message to be written out for them.
read-conf --oknofile /etc/defaults/wibble
Read the environment configuration file /etc/defaults/wibble
, without aborting if it does not exist.
Such files are a compatibility measure for setups that used to use such configuration files with System 5 rc
.
They are less preferable to daemontools-like environment directories; and such configuration mechanisms are gradually falling into desuetude anyway.
However, this tool is also useful outwith dæmon run
scripts.