linux - Linux CentOS 7 上的 Supervisord 仅在使用 root 运行时有效

标签 linux

我试图在后台运行一个进程作为守护进程,但只有当我使用 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 重新启动 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 身份运行网络服务器。

最佳答案

对于所有遇到同样问题的人,这对我有用。

cd 
echo_supervisord_conf > /etc/supervisord.conf
# content of /etc/supervisord.conf ...

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[inet_http_server] ; inet (TCP) server disabled by default
port=*:9001        ; (ip_address:port specifier, *:port for all iface) - I had all this wrong from my original config.
username=user
password=passwd

将此内容粘贴到/etc/rc.d/init.d/supervisord(我不是这个脚本的所有者,现在我不记得我从哪里得到的)

#!/bin/sh
#
# /etc/rc.d/init.d/supervisord
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord

# Source init functions
. /etc/rc.d/init.d/functions

prog="supervisord"

prefix="/usr/local/"
exec_prefix="${prefix}"
prog_bin="${exec_prefix}/bin/supervisord -c /etc/supervisord.conf"
PIDFILE="/var/run/$prog.pid"

start()
{
       echo -n $"Starting $prog: "
       daemon $prog_bin --pidfile $PIDFILE
       sleep 1
       [ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog startup"
       echo
}

stop()
{
       echo -n $"Shutting down $prog: "
       [ -f $PIDFILE ] && sleep 1 && killproc $prog || success $"$prog shutdown"
       echo
}

case "$1" in

 start)
   start
 ;;

 stop)
   stop
 ;;

 status)
       status $prog
 ;;

 restart)
   stop
   start
 ;;

 *)
   echo "Usage: $0 {start|stop|restart|status}"
 ;;

esac

使脚本可执行并将其注册为服务

sudo chmod +x /etc/rc.d/init.d/supervisord
sudo chkconfig --add supervisord
sudo chkconfig supervisord on

# Start the service
sudo service supervisord start

# Stop the service
sudo service supervisord stop

# Restart the service
sudo service supervisord restart

关于linux - Linux CentOS 7 上的 Supervisord 仅在使用 root 运行时有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31157928/

相关文章:

linux - 目录被检测为 perl 中的文件

linux - xterm 退出后在终端中保留页面

linux - block 大小的大小限制

c - 来自一个进程的多个客户端连接

linux - 快速密码套件

linux - 为什么HTOP在正常运行时间旁边显示感叹号

linux - 在 linux 中等待条件变量时,当 condition_timed_wiat 时间过去时会发生什么

java - 如何防止用户关闭我的应用程序? (Linux 触摸屏应用程序)

linux - 在 Linux 上安装 Anaconda3-4.3.1 - Spyder 无法启动 (PyQt5.QtWebEngineWidgets)

linux - Shell 脚本不从 cron 作业执行