z/OS UNIX System Services Planning
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Starting daemons

z/OS UNIX System Services Planning
GA32-0884-00

Daemons can be started by JCL and also by the shell. Some daemons such as inetd can also be started by the shell. Interactive login shells, shell scripts run as background jobs from a login shell, and batch jobs using BPXBATCH to run the shell all can start daemons.

BPXBATSL is provided as an alias for BPXBATCH. BPXBATSL performs a local spawn but does not require the resetting of environment variables. BPXBATSL behaves exactly like BPXBATCH, and allows local spawning whether the current environment is set up or not.

Many daemons can be started from the shell, both interactively and from shell scripts. In general, processes started from the shell complete (either successfully or with some error) before the parent shell itself exits. Any processes still running receive a SIGHUP signal when the parent shell exits. The default action for SIGHUP is to terminate the process. That is, when the shell exits, the system terminates all running processes started by the shell.

Daemon processes are long-running and generally must continue to run even after the invoking shell terminates. Those daemons started using the shell are therefore written to ignore SIGHUP signals. They are also typically written to return control to the shell immediately. If they did not return, the shell script would wait forever for the daemon to exit.

Rules:
  • When started from the shell, most daemons should not be placed in the background environment. That is, an ampersand should not appear on the shell command line that starts a daemon. Doing so exposes the background job containing the daemon to SIGHUP and causes the daemon to terminate unexpectedly when the shell script exits.
  • Some daemons either do not protect themselves from the SIGHUP signal or do not return to the shell immediately. You have to have those daemons start in the background environment. To do this, add an ampersand character at the end of the command line that starts the daemon.
  • When starting daemons in the background environment, it is very important to include a sleep command at the end of the script. This command gives the background processes time to get started and set up to ignore SIGHUP so that when the shell exits, the daemons keep running when the shell script completes. The amount of time required can be determined empirically. A value of 5 seconds is suggested for a start.
A shell script that starts a more simple daemon called slowpoke that does not return control immediately to the shell would look like this:
slowpoke &
sleep 5
exit
In summary, a shell script that starts the syslogd and cron daemons would look like the following:
_BPX_JOBNAME='SYSLOGD' /usr/sbin/syslogd -f /etc/syslog.conf &
_BPX_JOBNAME='CROND' /usr/sbin/cron &
sleep 5
exit
Although cron and syslogd return immediately and protect themselves from SIGHUP, the & is included with syslogd because this is the only method of getting _BPX_JOBNAME to take effect.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014