Starting, Stopping, and Restarting Daemons


As root, you can do anything on the system, but you shouldn't have much to do at all. Generally, Unix (or Linux) systems are configured so that the programs that should be running all the time (like the Web server software, mail server software, or similar programs) are automatically started in the background when the system is booted. Then you, as root, need only handle crises and problems. (Ha! Easier said than done.)

That said, sometimes you'll need to start or stop these daemons (programs running in the backgroundsee Chapter 9 for details). Say, for example, that you get an email from one of the system users complaining that the Web server (or, technically, the httpd daemon) isn't running. As the system administrator, you'll have to start it.

To Start a Daemon:

1.

ps -ef | grep httpd

Verify that the Web server really isn't running. Sometimes users are wrong. If you see lines that list httpd (other than the one that reports the command you're running), httpd is active and doesn't need to be started. The problem may lie elsewhere.

2.

cd /etc/init.d

Change to the directory containing the generic init (for initialization) scripts. This directory is likely /etc/init.d or /etc/rc.d/init.d/, as Code Listing 16.4 shows.

3.

sudo ./httpd start

Use sudo ./httpd (to be absolutely sure that you're running httpd from the current directory and not a program of the same name from elsewhere on the system) and start. The httpd in the /etc/init.d directory is a script to start the daemon with the appropriate options.

4.

ps -ef | grep httpd

Verify that the Web server now is running.

Tips

  • To stop a daemon, use the same process, but use stop (as in, sudo ./httpd stop) to stop a daemon cleanly.

  • Sometimes you might need to restart a daemon. You could stop it, and then start it, but in many cases you could also use restart or reload (as in, sudo ./httpd restart).

  • Be careful about stopping or restarting daemons with which you are not familiar. Unix has a lot of interdependencies that are often not clear, and stopping something you think you don't need might have unexpected consequences.


Code Listing 16.4. Sometimes you have to manually start system daemons.

[jdoe@frazz jdoe]$ ps -ef | grep httpd jdoe   656 21562 0 04:51 pts/5  00:00:00 grep httpd [jdoe@frazz jdoe]$ cd /etc/init.d [jdoe@frazz init.d]$ sudo ./httpd start Password: Starting httpd-perl:[ OK ] Starting httpd:  [ OK ] [jdoe@frazz init.d]$ ps -ef | grep httpd root        793  1 0 04:52 ?          00:00:00 httpd-perl -f /etc/httpd/conf/ht apache      794  793 0 04:52 ?        00:00:00 httpd-perl -f /etc/httpd/conf/ht apache      795  793 0 04:52 ?        00:00:00 httpd-perl -f /etc/httpd/conf/ht apache      796  793 0 04:52 ?        00:00:00 httpd-perl -f /etc/httpd/conf/ht apache      800  793 0 04:52 ?        00:00:00 httpd-perl -f /etc/httpd/conf/ht root        808  1 0 04:52 ?          00:00:00 httpd -DPERLPROXIED -DHAVE_PHP4 apache      816  808 0 04:52 ?        00:00:00 httpd -DPERLPROXIED -DHAVE_PHP4 apache      817  808 0 04:52 ?        00:00:00 httpd -DPERLPROXIED -DHAVE_PHP4 apache      818  808 0 04:52 ?        00:00:00 httpd -DPERLPROXIED -DHAVE_PHP4 apache      819  808 0 04:52 ?        00:00:00 httpd -DPERLPROXIED -DHAVE_PHP4 jdoe        822  21562 0 04:52 pts/5  00:00:00 grep httpd [jdoe@frazz init.d]$ 




Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net