安装
yum install supervisor -y
用户配置文件
cd /etc/supervisor/conf.d/
cat testsssping.ini
[program:testsssping]
#command=sh /data/test.sh
stderr_logfile=/tmp/supervisor.err.log
stdout_logfile=/tmp/supervisor.out.log
command=ping www.baidu.com
autostart=true
autorestart=true
user=otoyix
startsecs=5
启动
systemctl start supervisord.service
supervisorctl restart/stop/restart/start testsssping
testsssping: stopped
testsssping: started
[root@VM-16-15-centos supervisord.d]# supervisorctl status
testsssping RUNNING pid 27746, uptime 0:00:32
[root@VM-16-15-centos supervisord.d]# ps -ef|grep ping
otoyix 27746 27745 0 11:54 ? 00:00:00 ping www.baidu.com
普通用户使用 supervisorctl
正常情况下普通用户没有权限使用supervisorctl,会报以下错误
[root@VM-16-15-centos supervisord.d]# su otoyix
[otoyix@VM-16-15-centos supervisord.d]$ supervisorctl status
error: <class 'socket.error'>, [Errno 13] Permission denied: file: /usr/lib64/python2.7/socket.py line: 224
解决方法
chown -R otoyix:otoyix /var/log/supervisor/
chmod -R 777 /var/run/supervisor
vim /etc/supervisord.conf
user=otoyix ; (default is current user, required if root)
有权限了
[otoyix@VM-16-15-centos supervisord.d]$ supervisorctl status
testsssping RUNNING pid 28334, uptime 0:07:21
普通用户使用systemctl
正常情况下普通用户使用systemctl时会提示root密码
[otoyix@VM-16-15-centos supervisord.d]$ systemctl restart supervisord.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password: Failed to restart supervisord.service: Connection timed out
See system logs and 'systemctl status supervisord.service' for details.
[otoyix@VM-16-15-centos supervisord.d]$ polkit-agent-helper-1: pam_authenticate failed: Authentication failure
解决方法
cp -r /usr/share/polkit-1/actions/org.freedesktop.systemd1.policy{,.bak}
cat /usr/share/polkit-1/actions/org.freedesktop.systemd1.policy|grep -Ei 'defaults|allow'
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
<defaults>
<allow_any>yes</allow_any>
<allow_inactive>yes</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<defaults>
<allow_any>yes</allow_any>
<allow_inactive>yes</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<defaults>
<allow_any>yes</allow_any>
<allow_inactive>yes</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
systemctl restart supervisord.service
-------------------end