完善lnmp中的nginx的服务脚本
快速重启NGINX的脚本
把以下代码存为reboot.sh,具体的nginx的路径根据你自己的情况改.
/usr/local/nginx/sbin/nginx -t;
stat=`echo $?`; #echo $? 上一个命令是否成功
if [ "$stat" = "0" ]; then
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`;
/usr/local/php/sbin/php-fpm restart;
echo "reload nginx OK";
else
echo "reload nginx fail";
fi
我的启动(初始化)脚本
#! /bin/sh
### BEGIN INIT INFO
# Provides: Nginx-php-fpm(php-fpm)
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 3 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop nginx php-fpm
# Description: Start and stop nginx php-fpm
# http://a18zhizao.com a18ccms@gmail.com
### END INIT INFO
ulimit -SHn 51200
set -e
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() {
/usr/local/php/sbin/php-fpm start > /dev/null 2>&1
$DAEMON -c $CONFIGFILE || echo -n " already running"
}
d_stop() {
/usr/local/php/sbin/php-fpm stop > /dev/null 2>&1
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
d_reload() {
/usr/local/php/sbin/php-fpm reload > /dev/null 2>&1
kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration ..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
网络上的优秀脚本:
http://67054.blog.51cto.com/57054/128245
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-De.ion: starts the nginx web server
# De.ion: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/nginx.pid \
--exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/nginx.pid \
--exec $DAEMON
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/usr/local/nginx/logs/nginx.pid --exec $DAEMON
sleep 1
start-stop-daemon --start --quiet --pidfile \
/usr/local/nginx/logs/nginx.pid --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/nginx.pid \
--exec $DAEMON
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
继续
添加脚本到系统默认运行级别
/usr/sbin/update-rc.d -f nginx defaults
最新评论