在Supervisor的监督下启动服务的想法是能够在单个守护程序下运行多个服务。根据Supervisor的配置,它将能够作为子进程启动,停止或重新启动任何给定的服务。在此配置中,我们展示了如何运行
apache2
在Ubuntu /Debian Linux上作为监督服务(对docker映像等有用)。首先,安装主管:
# apt-get install supervisor
包括apache2
的主管配置成/etc/supervisor/conf.d/
。主管将从该目录中选择唯一需要的所有配置文件*.conf
文件扩展名。例如,将以下行插入到新文件中/etc/supervisor/conf.d/apache2.conf
:
[program:apache2]
command=/usr/sbin/apache2ctl -DFOREGROUND
包含上述配置文件后,请停止apache2 webserver(如果当前正在运行):
# /etc/init.d/apache2 stop
[ ok ] Stopping web server: apache2.
root@4e004b451a98:/# /etc/init.d/apache2 status
[FAIL] apache2 is not running ... failed!
并重新启动主管:
# /etc/init.d/supervisor restart
Restarting supervisor: supervisord.
重新启动超级用户后,apache2 Web服务器也应启动。确认apache2网络服务器正在运行:
# /etc/init.d/apache2 status
[ ok ] apache2 is running.
故障排除
如果由于某种原因您无法让您的Apache在主管下运行,nodaemon
模式:
# /etc/init.d/supervisor stop
Stopping supervisor: supervisord.
# supervisord -n
错误信息:
/usr/lib/python2.7/dist-packages/supervisor/options.py:296: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
'Supervisord is running as root and it is searching '
2015-05-07 01:21:00,849 CRIT Supervisor running as root (no user in config file)
2015-05-07 01:21:00,849 WARN Included extra file "/etc/supervisor/conf.d/apache2.conf" during parsing
2015-05-07 01:21:00,858 INFO RPC interface 'supervisor' initialized
2015-05-07 01:21:00,858 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2015-05-07 01:21:00,858 INFO supervisord started with pid 542
2015-05-07 01:21:01,862 INFO spawned: 'apache2' with pid 545
2015-05-07 01:21:01,914 INFO exited: apache2 (exit status 0; not expected)
2015-05-07 01:21:02,918 INFO spawned: 'apache2' with pid 548
2015-05-07 01:21:02,970 INFO exited: apache2 (exit status 0; not expected)
2015-05-07 01:21:04,975 INFO spawned: 'apache2' with pid 551
2015-05-07 01:21:05,025 INFO exited: apache2 (exit status 0; not expected)
2015-05-07 01:21:08,031 INFO spawned: 'apache2' with pid 554
2015-05-07 01:21:08,078 INFO exited: apache2 (exit status 0; not expected)
2015-05-07 01:21:09,079 INFO gave up: apache2 entered FATAL state, too many start retries too quickly
如果看到以上错误消息,请确保您的Apache Web服务器尚未运行。
您可能会看到的另一条错误消息是:
AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf:
Invalid Mutex directory in argument file:${APACHE_LOCK_DIR}
这是因为您正在尝试运行apache2
直接命令。您可以尝试运行apache2ctl
代替。