These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX02/Simple Task Management

Classnotes | UNIX02 | RecentChanges | Preferences

We have already seen process management in UNIX01 (for review, take a look at UNIX01/Introduction To Processes, UNIX01/Viewing Running Processes, and UNIX01/The Kill Command), so we've been introduced to what we need for managing servers and daemons. However, let's return to it briefly by way of a review and to see how these items apply to task management.

Sending Signals to Daemons

Recall that you can use the kill and killall commands to send signals to a running process. As daemons are just processes, this is the way we send them signals as well.

The most common signal you will be sending to a running server daemon is SIGHUP (or "Hang-up Signal"). SIGHUP tells most servers to reload their configuration files. When you have modified a particular server's configuration (whether one file or many), sending that server's daemon SIGHUP will cause it to reread its files.

For example, if I was running SAMBA, which has a daemon of "smbd", I could send it a SIGHUP using

 # killall -SIGHUP smbd

Another common signal will be the SIGTERM one, which will tell a daemon to terminate and exit. The daemon should close all connections, and shut down. For example, if I wanted to stop the SAMBA daemon, I could issue:

 # killall -SIGTERM smbd

Finally, we can't forget SIGKILL, which will terminate the process with extreme prejudice. This should only be used in cases of emergency (where a process may have been remotely compromized, is "running away" and consuming resources, etc.)

 # killall -SIGKILL smbd

Controlling daemons using init scripts

Sometimes you may not know for certain what sending a particular signal to a daemon will do. Just because most daemons reload their configuration files when sent a SIGHUP doesn't mean that all daemons will behave the same. For this reason, it is useful to have access to the init scripts which control these daemons.

The init scripts are generally placed in /etc/init.d. Take a look at the scripts in this directory now.

These scripts know how to control a particular daemon. There is typically a special script just for each daemon. These scripts typically accept the following options:

start
We've seen this before. This starts the daemon, and is how init brings the system up.
stop
We've also seen this before. This stops the daemon, and is how init brings the system down.
restart
This will restart the daemon. Usually, all configuration files are reread, all connections are re-established, and all processes are restarted. While this will often give you the results you want when you want a configuration file reread, it may be a bit drastic as it will stop the daemon before bringing it back up. So, if you have a print server, a restart will probably lose all queued jobs.
reload
This will cause the daemon to reload configuration files. For daemons which accept SIGHUP to do this, often the reload option will be equivalent to sending a SIGHUP.
status
This will cause the daemon to print to STDOUT status information about itself.

Unless you explicitly know how to control a particular server daemon, a prefered way to interface with it is typically through these files. Often, calling a particular script with no options will give you it's usage. For example, Postfix (a mail server) gives me this output:

 root@rygel:/etc/init.d# ./postfix
 Usage: /etc/init.d/postfix
     {start|stop|restart|reload|flush|check|force-reload}

Now we are ready to handle basic network servers and technologies! (Next unit)



Classnotes | UNIX02 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited August 23, 2003 1:46 am (diff)
Search:
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.