Centos7 nginx启动脚本

vi /etc/init.d/nginx

#! /bin/bash
#chkconfig: - 85 15
PATH=/usr/local/nginx
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -e "\033[32m nginx already running \033[0m"
}
do_stop() {
$DAEMON -s stop || echo -e "\033[31m nginx not running \033[0m"
}
do_reload() {
$DAEMON -s reload || echo -e "\033[31m nginx can't reload \033[0m"
}
case "$1" in
start)
echo -e "\033[32m $NAME running \033[0m"
do_start
;;
stop)
echo -e "\033[31m $NAME stoping \033[0m"
do_stop
;;
reload|graceful)
echo -e "\033[32m $NAME configuration...\033[0m"
do_reload
;;
restart)
echo -e "\033[32m Restarting : $NAME \033[0m"
do_stop
do_start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0

注:切记编辑完启动脚本以后一定要给予执行权限,不然启动无效!

转载于:https://blog.51cto.com/13043516/2295965

你可能感兴趣的:(Centos7 nginx启动脚本)