#!/bin/bash
# Startup script. for the nginx Web Server
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
# HTML files and CGI.
# processname: nginx
# pidfile: /opt/nginx/logs/nginx.pid
# config: /opt/nginx/conf/nginx.conf
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
NGINX_HOME=/opt/nginx/sbin
NGINX_CONF=/opt/nginx/conf
NGINX_LOG=/opt/nginx/logs
NGINX_PID=${NGINX_LOG}/nginx.pid
if [ ! -f "$NGINX_HOME/nginx" ]
then
echo "nginxserver startup: cannot start"
exit
fi
check_conf() {
echo -n "Validation Configurations..."
${NGINX_HOME}/nginx -t 1>/dev/null 2>&1
if [ $? == 0 ]; then
echo "Success"
else
echo "Fail"
echo "Please run $NGINX_HOME/nginx -t for details"
exit 2
fi
}
start_nginx() {
check_conf
echo -n "Start nginx..."
$NGINX_HOME/nginx
if [ $? == 0 ]; then
echo "Success"
else
echo "Fail"
exit 2
fi
}
stop_nginx() {
echo -n "Stop nginx..."
kill `cat $NGINX_PID`
if [ $? == 0 ]; then
echo "Success"
else
echo "Fail"
exit 2
fi
}
reload_nginx() {
check_conf
echo -n "Reload nginx..."
kill -HUP `cat $NGINX_PID`
if [ $? == 0 ]; then
echo "Success"
else
echo "Fail"
exit 2
fi
}
case "$1" in
'start')
start_nginx
;;
'stop')
stop_nginx
;;
'restart')
stop_nginx
sleep 2
start_nginx
;;
'reload')
reload_nginx
;;
'chkconfig')
check_conf
;;
*)
echo "Usage: nginx {start|stop|restart|reload|chkconfig}"
exit 1
;;
esac
保存到/etc/init.d/nginx
chkconfig --add nginx
阅读(954) | 评论(0) | 转发(0) |