Home » Uncategorized » supervisor开机自动启动脚本+redis+MySQL+tomcat+nginx进程自动重启配置

supervisor开机自动启动脚本+redis+MySQL+tomcat+nginx进程自动重启配置

supervisor开机自动启动脚本+redis+MySQL+tomcat+nginx进程自动重启配置

supervisor开机自动重启脚本

#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
PROGNAME=supervisord
DAEMON=/usr/bin/$PROGNAME
CONFIG=/etc/$PROGNAME.conf
PIDFILE=/tmp/$PROGNAME.pid
DESC=”supervisord daemon”
SCRIPTNAME=/etc/init.d/$PROGNAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
start()
{
echo -n “Starting $DESC: $PROGNAME”
$DAEMON -c $CONFIG
}
stop()
{
echo -n “Stopping $DESC: $PROGNAME”
supervisor_pid=$(cat $PIDFILE)
kill -15 $supervisor_pid
echo “…”
}
status()
{
ps -ef|grep supervisord
}
case “$1” in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
*)
echo “Usage: $SCRIPTNAME {start|stop|restart|status}” >&2
exit 1
;;
esac
exit 0

之后需要在开机系统文件里面配置开启启动命令(下面的命令就是往里面写内容,或者你可以自己去去手动添加)


[root@JD ~] # echo "/etc/inin.d/supervisord start" > /etc/rc.d/rc.sysinit

supervisor项目管理进程的配置文件(都是一些基础的配置,都是可以管理进程的,要想配置好一点的可以去上网找,写进文件里就行了)

需要注意的地方====》所有要管理的进程都不能开启后台模式,只能使用前台模式进行配置;使用后台模式会出现一直重新开启新进程。

mysql配置文件(要注意command,这里就是要执行这个命令来开启的进程,自己可以找找自己的进程启动的命令)

[program:mysql]
command=/usr/local/tools/mysql/bin/mysqld –basedir=/usr/local/tools/mysql –datadir=/usr/local/tools/data/mysql –plugin-dir=/usr/local/tools/mysql/lib/plugin –user=mysql –log-error=/var/log/mysqld.log –pid-file=/usr/local/tools/data/mysql/JD.jcloud.local.pid –socket=/usr/local/tools/data/mysql/mysql.sock
process_name=%(program_name)s
priority=1001
autostart=true
startretries=3
autorestart=true
user=root

redis配置文件(关闭redis的后台模式,也就是修改redis.conf中的daemon为no)

[program:redisd]
command=/usr/local/redis/bin/redis-server
process_name=%(program_name)s
priority=1001
autostart=true
startretries=3
autorestart=true
user=root

nginx配置文件(也是要关闭后台模式,在执行的命令后面添加-g “daemon off;”)

[program:nginx]
command=/usr/local/tools/nginx/sbin/nginx -g ‘daemon off;’
process_name=%(program_name)s
priority=1000
autostart=true
startretries=3
autorestart=true
user=root

tomcat配置文件(一样关闭后台模式,使用 catalina.sh run)

[program:tomcat1]
command=/usr/local/tools/tomcat1/bin/catalina.sh run
process_name=%(program_name)s
environment=JAVA_HOME=”/usr/local/tools/jdk1.7.0_71/”,JAVA_BIN=”/usr/local/tools/jdk1.7.0_71/bin”
priority=1000
autostart=true
startretries=3
autorestart=true
user=root
~