Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Linux+ Certification Bible.pdf
Скачиваний:
46
Добавлен:
15.03.2015
Размер:
3.78 Mб
Скачать

362 Part IV Administration

You should always warn your users before shutting down a system. It gives them a chance to close any open files and log out of the system. Shutdowns without warning can often damage files that are still open.

Managing Linux Services

4.14 Stop, start, and restart services (daemons) as needed (e.g., init files)

Managing Linux services is a job function that most Linux administrators will encounter on a daily basis. Most of the services that administrators must manage are applications, such as a Web or FTP servers. However, these services can also include system processes, such as DNS, DHCP, and other important services and daemons.

Most application and service scripts are located in /etc/rc.d/init.d, or /etc/init.d. For example, the following is the startup script for the Apache Web server httpd daemon:

#!/bin/sh

#

#Startup script for the Apache Web Server

#chkconfig: 345 85 15

#description: Apache is a World Wide Web server. It is used to serve \

#HTML files and CGI.

#processname: httpd

#pidfile: /var/run/httpd.pid

#config: /etc/httpd/conf/httpd.conf

#Source function library.

. /etc/rc.d/init.d/functions

# See how we were called. case “$1” in

start)

echo -n “Starting httpd: “ daemon httpd

echo

touch /var/lock/subsys/httpd

;;

stop)

echo -n “Shutting down http: “ killproc httpd

echo

rm -f /var/lock/subsys/httpd rm -f /var/run/httpd.pid

;;

status)

Chapter 11 Linux System Commands 363

status httpd

;;

restart) $0 stop $0 start

;;

reload)

echo -n “Reloading httpd: “ killproc httpd -HUP

echo

;;

*)

echo “Usage: $0{start|stop|restart|reload|status}” exit 1

eesac exit 0

Most scripts utilize the arguments start, stop, restart, reload, and status.

start: if it is not currently running, starts the process.

stop: if it is currently running, stops the process.

restart: stops, and then restarts the process.

reload: restarts the process, reloading any configuration files.

status: gives the current status of the process.

You don’t have to memorize these startup scripts, but know where they are located and how to change the status of process.

As you can see from the example httpd daemon script above, each argument will run the corresponding part of the script that will change the status of the process as directed. You must be the root user to run these scripts.

For example, if you want to restart the httpd service, use the following command:

/etc/rc.d/init.d/httpd restart

You will have to restart a process or daemon after you have changed its configuration file. The process daemon won’t reload any changes until you have stopped and started the service, or performed a reload or restart. Most configuration files are located in the /etc directory. For example, the configuration file for the httpd service is /etc/httpd/conf/httpd.conf.

You may also find that you may need to occasionally restart certain services if they become locked up. For example, you may find that your DHCP service is not providing IP addresses to clients, but if you restart the service, it will start operating normally.

Соседние файлы в предмете Операционные системы