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 background—see 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.
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. | |
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.
[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]$ |