/etc/init.d/nginx
#!/bin/sh
# chkconfig: 2345 90 10
# description: nginx
# Simple nginx init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=80
EXEC=/usr/local/nginx/sbin/nginx
PIDFILE=/var/run/nginx.pid
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting nginx server..."
$EXEC
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$EXEC -s stop
while [ -x /proc/${PID} ]
do
echo "Waiting for nginx to shutdown ..."
sleep 1
done
echo "nginx stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
#修改权限 chmod 755 /etc/init.d/nginx #添加 nginx服务 chkconfig --add nginx #添加开机自动启动服务 chkconfig nginx on #以下就可以允许这些服务 service nginx start service nginx stop service nginx reload



