linux

Page 229

82935c10.qxd:Toolbox

10/29/07

1:16 PM

Page 204

Chapter 10: Managing the System To manage services, you can use the chkconfig and service commands. For example, to start the NTP service immediately, you could type this: $ sudo /etc/init.d/ntp start Starting NTP server ntpd

Start Samba service immediately [ OK ]

Each service comes with a shell script in the /etc/init.d directory. You can pass start or stop options to each service. The format is: sudo /etc/init.d/service_to_control start sudo /etc/init.d/service_to_control stop

Most of the scripts in the /etc/init.d directory support start and stop options, while some support other features as well. Here’s how to use service to start and stop services: $ /etc/init.d/ntp Show usage statement (with no options) Usage: /etc/init.d/ntp {start|stop|restart|try-restart|force-reload|status} $ sudo /etc/init.d/ntp restart * Stopping NTP server ntpd * Starting NTP server ntpd $ sudo /etc/init.d/ntp try-restart * Stopping NTP server ntpd * Starting NTP server ntpd $ sudo /etc/init.d/ntp force-reload * Stopping NTP server ntpd * Starting NTP server ntpd $ sudo /etc/init.d/ntp status * NTP server is running. $ sudo /etc/init.d/ntp stop * Stopping NTP server ntpd

Restart NTP service (first off, then on) [ OK ] [ OK ] Restart NTP service (if already running) [ OK ] [ OK ] Reload settings in config file [ OK ] [ OK ] Check if the NTP service is running (smbd) Stop NTP service [ OK ]

Any of the init scripts contained in /etc/init.d can be started in this way, but not all scripts support all the features just shown. Most init scripts, however, will show their usage statement with no option (as shown in the first example above). Although the previous commands start the run level script service immediately, to have a service start automatically at boot time or during a run level change, you can use the update-rc.d command. In addition, most installation scripts for services will automatically turn a service on for the next time you boot. With update-rc.d, you can turn services on, or turn them off on a per–run level basis. Here are examples: $ sudo update-rc.d ntp defaults

Turn on the NTP service

NOTE The documentation for the update-rc.d command recommends you not use this command to manage the run levels of your system. See the online man page for the update-rc.d command for details. Although you can use the init command to change to any run level, including init 0 (shut down) and init 6 (reboot), there are also specific commands for stopping Linux.

204


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.