linux nginx启动脚本

作者: jaclon 分类: Linux, PHP 发布时间: 2012-09-19 17:24 ė 6没有评论

内容来自网络,方便以后使用。

# vi /etc/init.d/nginx

输入以下脚本内容:

#!/bin/sh 
# 
# Startup script for the Nginx 
# chkconfig: - 88 63 
# description: Nginx is a free,open-source,high-performance HTTP Server and reverse proxy. 
# program:/usr/local/nginx/sbin/nginx 
# config:/usr/local/nginx/conf/nginx.conf 
# pidfile:/usr/local/nginx/logs/nginx.pid 
 
# Synopsis: 
#        nginx [--help] [--version] {start|stop|restart|reload|status|update} 
 
 
# Define variable 
nginx=/usr/local/nginx/sbin/nginx 
pidfile=/usr/local/nginx/logs/nginx.pid 
PROGRAM=`basename $0` 
VERSION=1.0 
# Functions 
usage(){ 
    echo "Usage: $PROGRAM [--help] [--version] {start|stop|restart|reload|status|update}" 
} 
 
version(){ 
    echo "Version:$VERSION" 
} 
 
start(){ 
if [ -e $pidfile ] 
   then 
    echo "Nginx already running..." 
   else 
    echo -e "Starting Nginx:\t\t\t\t\t\t\t\c" 
    /usr/local/nginx/sbin/nginx 
    echo -e "[ \c" 
    echo -e "\033[0;32mOK\033[0m\c" 
    echo -e " ]\c" 
    echo -e "\r" 
fi 
} 
 
stop(){ 
if [ -e $pidfile ] 
   then 
    echo -e "Stopping Nginx:\t\t\t\t\t\t\t\c" 
    kill -TERM `cat ${pidfile}` 
    echo -e "[ \c" 
    echo -e "\033[0;32mOK\033[0m\c" 
    echo -e " ]\c" 
    echo -e "\r" 
   else 
    echo "Nginx already stopped..." 
fi 
} 
 
reload(){ 
if [ -e $pidfile ] 
   then 
    echo -e "Reloading Nginx:\t\t\t\t\t\t\c" 
    kill -HUP `cat ${pidfile}` 
    echo -e "[ \c" 
    echo -e "\033[0;32mOK\033[0m\c" 
    echo -e " ]\c" 
    echo -e "\r" 
   else 
    echo "Nginx is not running..." 
fi 
} 
 
status(){ 
    if [ -e $pidfile ] 
       then 
        PID=`cat $pidfile` 
        echo  "Nginx (pid $PID) is running..." 
       else 
        echo  "Nginx is stopped" 
    fi 
} 
 
update(){ 
if [ -e $pidfile ] 
   then 
    echo -e "Updateing Nginx:\t\t\t\t\t\t\c" 
    kill -USR2 `cat ${pidfile}` 
    echo -e "[ \c" 
    echo -e "\033[0;32mOK\033[0m\c" 
    echo -e " ]\c" 
    echo -e "\r" 
   else 
    echo "Nginx is not running..." 
fi 
} 
if [ $# -gt 0 ] 
   then 
    case $1 in 
        start) 
            start 
            ;; 
        stop) 
            stop 
            ;; 
        restart) 
            stop 
            start 
            ;; 
        reload) 
            reload 
            ;; 
        status) 
            status 
            ;; 
        update) 
            update 
            ;; 
        --help) 
            usage 
            ;; 
        --version) 
            version 
            ;; 
        *) 
            usage 
    esac 
   else 
    usage 
fi 

其中
# Define variable
nginx=/usr/local/nginx/sbin/nginx
pidfile=/usr/local/nginx/logs/nginx.pid
以及start(){…}中的/usr/local/nginx/sbin/nginx 根据实际情况修改

加为系统服务

chmod +x /etc/init.d/nginx
chkconfig --add nginx

之后便可使用,service nginx start/stop/restart/..

本文出自 肥蕉博客@IT技术,热门话题,生活随笔,美图欣赏,转载时请注明出处及相应链接。

本文永久链接: http://www.bananawolf.com/html/2012/09/842.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*

Ɣ回顶部