Nginx的启动脚本
问题:在预编译安装Nginx时候每次启动时都非常不方便,所以想了下写个Nginx脚本在/etc/init.d目录下可实现service的方式启动、停止、重启这样就方便多了!
@H_404_17@ @H_404_17@[root@cml init.d]#vimNginxd#!/bin/bash
#chkconfig: 2345 20 80
prog="Nginxd"
@H_404_17@Nginx_bin="/usr/local/nginx/sbin/Nginx"if [ -x $Nginx_bin ]; then##if语句判断是否存在Nginx路径
echo "$Nginx_bin is installled !"
else
echo -n "$Nginx_bin not installed !"
exit 5
fi
start(){
echo -n "starting $prog:"
@H_404_17@a=$?if [ $a -eq 0 ]; then###if语句判断上一句是否执行成功
touch /tmp/Nginx.pid ##创建一个Nginx.pid文件后启动Nginx
$Nginx_bin
echo "please check your Nginx config"
exit 10
}
stop(){
echo -n $"stopping $prog:"
@H_404_17@$Nginx_bin -s stop ##停止Nginxif [ $a -eq 0 ]; then ##判断执行上一句成功就删除Nginx.pid文件输出信息
rm -rf /tmp/Nginx.pid
echo "success stop Nginx"
echo "check your Nginx command"
exit 11
case $1 in ##
start)
start
;;
stop)
stop
reload|restart)
sleep 2
start
*)
echo "Usage:$0{start|stop|reload/restart}"
;;
esac
@H_404_17@验证: