Supervisor on linux CentOS 7 only works on startup with root

I try to run the process in the background as a deamon, but it only works when I use root as a user.

This is what I did.

Installed supervisor, as stated on their website

$ yum -y install python-setuptools $ easy_install supervisor 

created configuration folders

 $ mkdir -p /etc/supervisor/conf.d 

filled with default settings

 $ echo_supervisord_conf > /etc/supervisor/supervisord.conf 

add new user

 $ useradd gogopher 

on CentOS 7, to start it automatically, I had to do it

 $ vim /usr/lib/systemd/system/supervisord.service 

added code below

 [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 

Now I can turn it on so that it starts on reboot. it all works great.

 $ systemctl enable supervisord $ systemctl start supervisord $ systemctl status supervisord 

Ok

editing a configuration file to include files from the conf.d folder

 $ vim /etc/supervisor/supervisord.conf 

append to end of file

 [include] files = /etc/supervisor/conf.d/*.conf 

adding a simple program

 $ 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

no error, but the process does not work

If I restart, nothing will happen

 $ systemctl status supervisord 

indicates that the supervisor is running, but not the daemon.

if i run

 $ supervisorctl reload 

I get an error

 error: <class 'socket.error'>, [Errno 111] Connection refused: file: /usr/lib64/python2.7/socket.py line: 571 

if i run

 $ supervisorctl status main 

I get an error

 http://localhost:9001 refused connection 

I have already disabled selinux.

but the strange part is that if I changed both of them to root, it works.

An executable file can be executed by a group of users and others.

Therefore, I have no idea what is happening. I heard that I should not use root as the user who runs the web server for security reasons.

+8
linux
source share
1 answer

For all people having the same problem, this works for me.

 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 

Paste this content into /etc/rc.d/init.d/supervisord (I do not own this script, now I do not remember where I got it from)

 #!/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 

Make the script executable and register it as a service

 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 
+5
source share

All Articles