关闭Aphache和重启Apache
2011-08-07 13:59
190 查看
This document covers stopping and restarting Apache on Unix-like systems. Windows NT, 2000 and XP users should see Running
Apache as a Service and Windows 9x and ME users should see Running Apache as a Console Application for information on how
to control Apache on those platforms.
In order to stop or restart Apache, you must send a signal to the running
There are two ways to send the signals. First, you can use the unix
running on your system, but you should not send signals to any of them except the parent, whose pid is in the
That is to say you shouldn't ever need to send signals to any process except the parent. There are four signals that you can send the parent:
and
To send a signal to the parent you should issue a command such as:
The second method of signaling the
is to use the
as described below. These are arguments to the
but we recommend that you send them using the
script, which will pass them through to
After you have signaled
read about its progress by issuing:
Modify those examples to match your
Signal: TERM
Sending the
its children. It may take it several seconds to complete killing off its children. Then the parent itself exits. Any requests in progress are terminated, and no further requests are served.
Signal: USR1
The
their current request (or to exit immediately if they're not serving anything). The parent re-reads its configuration files and re-opens its log files. As each child dies off the parent replaces it with a child from the new generation of the configuration,
which begins serving new requests immediately.
This code is designed to always respect the process control directive of the MPMs, so the number of processes and threads available to serve clients will be maintained at the appropriate values throughout the restart process. Furthermore, it respects
the following manner: if after one second at least
children have not been created, then create enough to pick up the slack. Hence the code tries to maintain both the number of children appropriate for the current load on the server, and respect your wishes with the
Users of
notice that the server statistics are not set to zero when a
new requests (they will be queued up by the operating system, so they're not lost in any event) and to respect your tuning parameters. In order to do this it has to keep the scoreboard used to keep track of all children across generations.
The status module will also use a
At present there is no way for a log rotation script using
delay after sending the
then you could wait 15 minutes before doing anything with the old log.
If your configuration file has errors in it when you issue a restart then your parent will not restart, it will exit with an error. In the case of graceful restarts it will also leave children running when it exits. (These are the children which are "gracefully
exiting" by handling their last request.) This will cause problems if you attempt to restart the server -- it will not be able to bind to its listening ports. Before doing a restart, you can check the syntax of the configuration files with the
line argument (see
will not guarantee that the server will restart correctly. To check the semantics of the configuration files as well as the syntax, you can try starting
a non-root user. If there are no errors it will attempt to open its sockets and logs and fail because it's not root (or because the currently running
has those ports bound). If it fails for any other reason then it's probably a config file error and the error should be fixed before issuing the graceful restart.
Signal: HUP
Sending the
but the parent doesn't exit. It re-reads its configuration files, and re-opens any log files. Then it spawns a new set of children and continues serving hits.
Users of
notice that the server statistics are set to zero when a
If your configuration file has errors in it when you issue a restart then your parent will not restart, it will exit with an error. See above for a method of avoiding this.
Signal: WINCH
The
after their current request (or to exit immediately if they're not serving anything). The parent will then remove its
cease listening on all ports. The parent will continue to run, and monitor children which are handling requests. Once all children have finalised and exited or the timeout specified by the
been reached, the parent will also exit. If the timeout is reached, any remaining children will be sent the
A
have been removed, you will not be able to use
The
the same time. This is a powerful feature when performing graceful upgrades of Apache, however it can also cause deadlocks and race conditions with some configurations.
Care has been taken to ensure that on-disk files such as the
contain the server PID, and should coexist without problem. However, if a configuration directive, third-party module or persistent CGI utilises any other on-disk lock or state files, care should be taken to ensure that multiple running instances of
not clobber each others files.
You should also be wary of other potential race conditions, such as using
piped logging. Multiple running instances of
to rotate the same logfiles at the same time may destroy each other's logfiles.
Apache as a Service and Windows 9x and ME users should see Running Apache as a Console Application for information on how
to control Apache on those platforms.
Introduction
In order to stop or restart Apache, you must send a signal to the running httpdprocesses.
There are two ways to send the signals. First, you can use the unix
killcommand to directly send signals to the processes. You will notice many
httpdexecutables
running on your system, but you should not send signals to any of them except the parent, whose pid is in the
PidFile.
That is to say you shouldn't ever need to send signals to any process except the parent. There are four signals that you can send the parent:
TERM,
USR1,
HUP,
and
WINCH, which will be described in a moment.
To send a signal to the parent you should issue a command such as:
kill -TERM `cat /usr/local/apache2/logs/httpd.pid`
The second method of signaling the
httpdprocesses
is to use the
-kcommand line options:
stop,
restart,
gracefuland
graceful-stop,
as described below. These are arguments to the
httpdbinary,
but we recommend that you send them using the
apachectlcontrol
script, which will pass them through to
httpd.
After you have signaled
httpd, you can
read about its progress by issuing:
tail -f /usr/local/apache2/logs/error_log
Modify those examples to match your
ServerRootand
PidFilesettings.
Stop Now
Signal: TERMapachectl -k stop
Sending the
TERMor
stopsignal to the parent causes it to immediately attempt to kill off all of
its children. It may take it several seconds to complete killing off its children. Then the parent itself exits. Any requests in progress are terminated, and no further requests are served.
Graceful Restart
Signal: USR1apachectl -k graceful
The
USR1or
gracefulsignal causes the parent process to advise the children to exit after
their current request (or to exit immediately if they're not serving anything). The parent re-reads its configuration files and re-opens its log files. As each child dies off the parent replaces it with a child from the new generation of the configuration,
which begins serving new requests immediately.
This code is designed to always respect the process control directive of the MPMs, so the number of processes and threads available to serve clients will be maintained at the appropriate values throughout the restart process. Furthermore, it respects
StartServersin
the following manner: if after one second at least
StartServersnew
children have not been created, then create enough to pick up the slack. Hence the code tries to maintain both the number of children appropriate for the current load on the server, and respect your wishes with the
StartServersparameter.
Users of
mod_statuswill
notice that the server statistics are not set to zero when a
USR1is sent. The code was written to both minimize the time in which the server is unable to serve
new requests (they will be queued up by the operating system, so they're not lost in any event) and to respect your tuning parameters. In order to do this it has to keep the scoreboard used to keep track of all children across generations.
The status module will also use a
Gto indicate those children which are still serving requests started before the graceful restart was given.
At present there is no way for a log rotation script using
USR1to know for certain that all children writing the pre-restart log have finished. We suggest that you use a suitable
delay after sending the
USR1signal before you do anything with the old log. For example if most of your hits take less than 10 minutes to complete for users on low bandwidth links
then you could wait 15 minutes before doing anything with the old log.
If your configuration file has errors in it when you issue a restart then your parent will not restart, it will exit with an error. In the case of graceful restarts it will also leave children running when it exits. (These are the children which are "gracefully
exiting" by handling their last request.) This will cause problems if you attempt to restart the server -- it will not be able to bind to its listening ports. Before doing a restart, you can check the syntax of the configuration files with the
-tcommand
line argument (see
httpd). This still
will not guarantee that the server will restart correctly. To check the semantics of the configuration files as well as the syntax, you can try starting
httpdas
a non-root user. If there are no errors it will attempt to open its sockets and logs and fail because it's not root (or because the currently running
httpdalready
has those ports bound). If it fails for any other reason then it's probably a config file error and the error should be fixed before issuing the graceful restart.
Restart Now
Signal: HUPapachectl -k restart
Sending the
HUPor
restartsignal to the parent causes it to kill off its children like in
TERM,
but the parent doesn't exit. It re-reads its configuration files, and re-opens any log files. Then it spawns a new set of children and continues serving hits.
Users of
mod_statuswill
notice that the server statistics are set to zero when a
HUPis sent.
If your configuration file has errors in it when you issue a restart then your parent will not restart, it will exit with an error. See above for a method of avoiding this.
Graceful Stop
Signal: WINCHapachectl -k graceful-stop
The
WINCHor
graceful-stopsignal causes the parent process to advise the children to exit
after their current request (or to exit immediately if they're not serving anything). The parent will then remove its
PidFileand
cease listening on all ports. The parent will continue to run, and monitor children which are handling requests. Once all children have finalised and exited or the timeout specified by the
GracefulShutdownTimeouthas
been reached, the parent will also exit. If the timeout is reached, any remaining children will be sent the
TERMsignal to force them to exit.
A
TERMsignal will immediately terminate the parent process and all children when in the "graceful" state. However as the
PidFilewill
have been removed, you will not be able to use
apachectlor
httpdto send this signal.
The
graceful-stopsignal allows you to run multiple identically configured instances of
httpdat
the same time. This is a powerful feature when performing graceful upgrades of Apache, however it can also cause deadlocks and race conditions with some configurations.
Care has been taken to ensure that on-disk files such as the
Lockfileand
ScriptSockfiles
contain the server PID, and should coexist without problem. However, if a configuration directive, third-party module or persistent CGI utilises any other on-disk lock or state files, care should be taken to ensure that multiple running instances of
httpddo
not clobber each others files.
You should also be wary of other potential race conditions, such as using
rotatelogsstyle
piped logging. Multiple running instances of
rotatelogsattempting
to rotate the same logfiles at the same time may destroy each other's logfiles.
相关文章推荐
- Mac OS 终端起动、关闭、重启apache的方法
- mac下重启、打开、关闭Apache
- ubuntu下打开,关闭,重启apache的方法
- Mac OS 终端起动、关闭、重启apache的方法
- Mac 终端启动,关闭,重启Apache
- linux 下启动关闭以及重启 apache
- Mac OS 终端起动、关闭、重启apache的方法
- ubuntu启动、重启、关闭apache服务
- linux平台apache启动、关闭、重启的几种方式
- LAMP系列之Apache优雅重启、优雅关闭
- Linux下启动、关闭及重启apache命令
- Mac OS 终端起动、关闭、重启apache的方法
- Linux下apache服务器安装,sqlite安装,apache启动,关闭,重启,编写cig程序进行测试,浏览器访问cig程序
- apache禁止列目录:apache如何打开或者关闭列目录功能
- 开启和关闭 apache 指令
- nginx 服务器重启命令,关闭
- Apache 配置关闭文件目录浏览
- mongodb异常关闭后重启
- WORD2007在关闭时报错"恢复我的工作并重启microsoft office word"_解决方法
- nginx(二)----ubuntu14.04下启动或重启和关闭nginx