Apache 的新贵监督 init 脚本?

Ben*_*ams 16 server 10.04 upstart apache2

我想在 Ubuntu 10.04 上运行 apache,并在 upstart 中使用很好的监督工具(我不只是在谈论 apache init 脚本,而是适当的服务监督 a la daemontools - 也就是说,当它死掉时重新启动 apache,事情像那样)。

有没有人有一个正在运行的新贵配置来监督 ubuntu 10.04 上的 apache?

谷歌对我没有帮助,但可能是我的谷歌功能很弱。

Ben*_*ams 10

呜呜!

我已经编写了我自己的版本,它几乎可以正常工作 - 使用一些 conf 文件黑客,并使用-D NO_DETACH.

首先,我必须手动设置User, Groupand PidFilein /etc/apache2/apache2.conf,而不是让它们从/etc/apache2/envvars. 我不能工作了一个办法让那些瓦尔要正确导出(我尝试都envexport每个作为http://manpages.ubuntu.com/manpages/lucid/man5/init.5.html,但没有好)。

root@lucid:/etc/apache2# diff -u apache2.conf.orig apache2.conf
--- apache2.conf.orig   2010-09-20 13:46:33.857868534 +0930
+++ apache2.conf        2010-09-20 13:47:22.377842204 +0930
@@ -63,7 +63,7 @@
 # identification number when it starts.
 # This needs to be set in /etc/apache2/envvars
 #
-PidFile ${APACHE_PID_FILE}
+PidFile /var/run/apache2.pid

 #
 # Timeout: The number of seconds before receives and sends time out.
@@ -142,8 +142,8 @@
 </IfModule>

 # These need to be set in /etc/apache2/envvars
-User ${APACHE_RUN_USER}
-Group ${APACHE_RUN_GROUP}
+User www-data
+Group www-data

 #
 # AccessFileName: The name of the file to look for in each directory
Run Code Online (Sandbox Code Playgroud)

然后,这是我的工作/etc/init/apache2.conf

# apache2 - http server
#
# Apache is a web server that responds to HTTP and HTTPS requests.
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog

description "apache2 http server"

start on runlevel [2345]
stop on runlevel [!2345]

pre-start script
    mkdir -p /var/run/apache2 || true
    install -d -o www-data /var/lock/apache2 || true
    # ssl_scache shouldn't be here if we're just starting up.
    # (this is bad if there are several apache2 instances running)
    rm -f /var/run/apache2/*ssl_scache* || true
end script

# Give up if restart occurs 10 times in 30 seconds.
respawn limit 10 30

exec /usr/sbin/apache2 -D NO_DETACH
respawn
Run Code Online (Sandbox Code Playgroud)

我可以做start|stop|status|reload apache2并获得有意义的结果;如果我kill -9是主 apache 进程,它会立即重新生成,并且按预期启动和停止。所以我认为它运行得相当好。


有些事情我尝试过,但我无法工作。

  • 试图删除-D NO_DETACH,结合:
期待叉子
期待守护进程

那无法启动服务。

  • 尝试使用类似的方法/etc/apache2/envvars来填充${APACHE_*}变量:
导出 APACHE_RUN_USER=www-data
导出 APACHE_RUN_GROUP=www-data
导出 APACHE_PID_FILE=/var/run/apache2.pid

那无法启动,并产生了关于 的错误apache2: bad user name ${APACHE_RUN_USER}

  • 尝试控制台输出和控制台默认选项;在这一点上,我真的只是在试图获得有意义的错误消息。好像没什么区别。

    console output

  • 这对于调试 apache 消息很有用:

    exec /usr/sbin/apache2 -X -e debug -E /var/log/apache2/foo.log

  • 这是另一种不修改/etc/apache2/apache2.conf失败的尝试:

    exec APACHE_RUN_USER=www-data APACHE_RUN_GROUP=www-data APACHE_PID_FILE=/var/run/apache2.pid /usr/sbin/apache2 -D NO_DETACH -e debug -E /var/log/apache2/foo.log


tmu*_*eko 5

好吧,这个脚本对我有用:

# apache2 - http server
#
# Apache is a web server that responds to HTTP and HTTPS requests.
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog

description "apache2 http server"

start on runlevel [2345]
stop on runlevel [!2345]

pre-start script
    mkdir -p /var/run/apache2 || true
    install -d -o www-data /var/lock/apache2 || true
    # ssl_scache shouldn't be here if we're just starting up.
    # (this is bad if there are several apache2 instances running)
    rm -f /var/run/apache2/*ssl_scache* || true
end script

limit cpu 300 300
env APACHE_RUN_USER=www-data
env APACHE_RUN_GROUP=www-data
env APACHE_PID_FILE=/var/run/apache2.pid

# Give up if restart occurs 10 times in 30 seconds.
respawn limit 10 30

exec /usr/sbin/apache2 -D NO_DETACH
respawn
Run Code Online (Sandbox Code Playgroud)