【问题标题】:Supervisord on linux CentOS 7 only works when run with rootlinux CentOS 7 上的 Supervisord 仅在以 root 运行时有效
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

  • /etc/rc.d/init.d 不再存在。您需要在 /etc/init.d 中创建脚本,因此请注意路径。
猜你喜欢
  • 2017-12-26
  • 1970-01-01
  • 2015-06-29
  • 2021-07-15
  • 1970-01-01
  • 2011-07-15
  • 2011-06-05
  • 2018-07-18
  • 1970-01-01
相关资源
最近更新 更多