Chinaunix首页 | 论坛 | 博客
  • 博客访问: 852993
  • 博文数量: 188
  • 博客积分: 4433
  • 博客等级: 上校
  • 技术积分: 1905
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-14 07:14
个人简介

linux

文章分类

全部博文(188)

文章存档

2016年(6)

2015年(22)

2014年(18)

2013年(5)

2012年(125)

2011年(10)

2010年(2)

分类: LINUX

2012-03-08 09:39:04

#!/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) |
给主人留下些什么吧!~~