【发布时间】:2015-07-01 09:46:36
【问题描述】:
我试图在后台运行一个进程作为守护进程,但它仅在我使用 root 作为用户时才有效。
这就是我所做的。
按照他们网站上的说明安装了主管
$ yum -y install python-setuptools
$ easy_install supervisor
创建配置文件夹
$ mkdir -p /etc/supervisor/conf.d
使用默认设置填充
$ echo_supervisord_conf > /etc/supervisor/supervisord.conf
添加新用户
$ useradd gogopher
在 CentOS 7 上让它自动启动我必须这样做
$ vim /usr/lib/systemd/system/supervisord.service
添加以下代码
[Unit]
Description=supervisord - Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecReload=/usr/bin/supervisorctl reload
ExecStop=/usr/bin/supervisorctl shutdown
User=gogopher
[Install]
WantedBy=multi-user.target
现在我可以启用它,以便它在重新启动时启动。这一切都很好。
$ systemctl enable supervisord
$ systemctl start supervisord
$ systemctl status supervisord
好的
编辑配置文件以包含来自 conf.d 文件夹的文件
$ vim /etc/supervisor/supervisord.conf
在文件末尾添加
[include]
files = /etc/supervisor/conf.d/*.conf
添加一个简单的程序
$ vim /etc/supervisor/conf.d/goapp.conf
[program:main]
command=/srv/www/websiteurl.com/bin/main
autostart=true
autorestart=true
startretries=10
user=gogopher
$ systemctl restart supervisord
没有错误,但进程不工作
如果我重新启动没有任何反应
$ systemctl status supervisord
显示它的 supervisord 正在运行,但不是守护程序。
如果我跑
$ supervisorctl reload
我得到了错误
error: <class 'socket.error'>, [Errno 111] Connection refused: file: /usr/lib64/python2.7/socket.py line: 571
如果我跑
$ supervisorctl status main
我得到了错误
http://localhost:9001 refused connection
我已经禁用了 selinux。
但奇怪的是,如果我将它们都更改为 root,它可以工作。
可执行文件可以被用户组和其他人执行。
所以我不知道发生了什么。我听说我不应该使用 出于安全原因,以 root 身份运行网络服务器的用户。
【问题讨论】:
-
你解决了吗?如果是,怎么做?
标签: linux