1.将supervisor配置成服务&&开机自启
配置supervisor为服务:
0.将supervisord文件移动到/etc/init.d/目录下
cp supervisord /etc/init.d/
配置开机启动:
1.使用chkconfig管理supervisor服务:
chkconfig --add supervisord
2.设置开机运行supervisor服务
chkconfig supervisord on
3.注意,配置服务脚本可执行权限
chmod 755 /etc/init.d/supervisord
服务命令:service supervisord start/stop/restart/status
其他:
centos7上,由于python3安装位置不同,故需要更改supervisord文件中的PREFIX变量(即python3位置)
如果flask以debug运行,则supervisor下flask会有两个进程,debug关闭后是正常的一个
#!/bin/bash
#
# supervisord This scripts turns supervisord on
#
# Author: Mike McGrath (based off yumupdatesd)
# Jason Koppe adjusted to read sysconfig,
# use supervisord tools to start/stop, conditionally wait
# for child processes to shutdown, and startup later
# Mikhail Mingalev Merged
# redhat-init-jkoppe and redhat-sysconfig-jkoppe, and
# made the script "simple customizable".
# Brendan Maguire Added OPTIONS to
# SUPERVISORCTL status call
#
# chkconfig: 345 83 04
#
# description: supervisor is a process control utility. It has a web based
# xmlrpc interface as well as a few other nifty features.
# Script was originally written by Jason Koppe .
#
# source function library
. /etc/rc.d/init.d/functions
set -a
PREFIX=/usr/local/python3
SUPERVISORD=$PREFIX/bin/supervisord
SUPERVISORCTL=$PREFIX/bin/supervisorctl
PIDFILE=/var/run/supervisord.pid
LOCKFILE=/var/lock/subsys/supervisord
OPTIONS="-c /home/python/estateQuery/estate_query_nolog/supervisor/supervisord.conf"
# unset this variable if you don't care to wait for child processes to shutdown before removing the $LOCKFILE-lock
WAIT_FOR_SUBPROCESSES=yes
# remove this if you manage number of open files in some other fashion
ulimit -n 96000
RETVAL=0
running_pid()
{
# Check if a given process pid's cmdline matches a given name
pid=$1
name=$2
[ -z "$pid" ] && return 1
[ ! -d /proc/$pid ] && return 1
(cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1
return 0
}
running()
{
# Check if the process is running looking at /proc
# (works for all users)
# No pidfile, probably no daemon present
[ ! -f "$PIDFILE" ] && return 1
# Obtain the pid and check it against the binary name
pid=`cat $PIDFILE`
running_pid $pid $SUPERVISORD || return 1
return 0
}
start() {
echo "Starting supervisord: "
if [ -e $PIDFILE ]; then
echo "ALREADY STARTED"
return 1
fi
# start supervisord with options from sysconfig (stuff like -c)
$SUPERVISORD $OPTIONS
# show initial startup status
$SUPERVISORCTL $OPTIONS status
# only create the subsyslock if we created the PIDFILE
[ -e $PIDFILE ] && touch $LOCKFILE
}
stop() {
echo -n "Stopping supervisord: "
$SUPERVISORCTL $OPTIONS shutdown
if [ -n "$WAIT_FOR_SUBPROCESSES" ]; then
echo "Waiting roughly 60 seconds for $PIDFILE to be removed after child processes exit"
for sleep in 2 2 2 2 4 4 4 4 8 8 8 8 last; do
if [ ! -e $PIDFILE ] ; then
echo "Supervisord exited as expected in under $total_sleep seconds"
break
else
if [[ $sleep -eq "last" ]] ; then
ech