![为 Supervisord 编写自定义初始化脚本](https://linux22.com/image/678957/%E4%B8%BA%20Supervisord%20%E7%BC%96%E5%86%99%E8%87%AA%E5%AE%9A%E4%B9%89%E5%88%9D%E5%A7%8B%E5%8C%96%E8%84%9A%E6%9C%AC.png)
我在用主管控制我在 Amazon Linux 上的进程。我想在我的 init 脚本中使用它supervisorctl
。到目前为止,我有以下内容。
#!/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/init.d/functions
USER=mv2
RETVAL=0
prog="supervisord"
pidfile=/usr/local/supervisor/logs/supervisord.pid
lockfile="/var/lock/subsys/supervisord"
config=/usr/local/supervisor/conf/supervisord_conf.ini
SUPERVISORCTL=/usr/local/bin/supervisorctl
hard_start()
{
echo -n $"Starting $prog: "
daemon --user $USER --pidfile $pidfile /usr/local/bin/supervisord -c $config
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${lockfile}
}
hard_stop()
{
echo -n $"Shutting down $prog: "
killproc -p ${pidfile} /usr/local/bin/supervisord
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f ${lockfile} ${pidfile}
fi
}
soft_stop(){
$SUPERVISORCTL signal SIGTERM all
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
echo "do something"
fi
}
soft_start(){
$SUPERVISORCTL start all
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
echo "do something"
fi
}
reload(){
echo -ne $"Reloading config file: "\\r
$($SUPERVISORCTL update) &> /dev/null &
RETVAL=$?
echo
success
}
case "$1" in
hard-start)
hard_start
;;
hard-stop)
hard_stop
;;
status)
status $prog
;;
restart)
hard_stop
hard_start
;;
soft-stop)
soft_stop
;;
soft-start)
soft_start
;;
reload)
reload
;;
*)
echo "Usage: $0 {hard-start|hard-stop|restart|status|soft-stop|soft-start|soft-restart|reload}"
;;
esac
和hard-stop
选项hard-start
运行良好。但是,我不确定如何显示和选项的常用success
和failed
消息。soft-stop
soft-start
reload