zoukankan      html  css  js  c++  java
  • Linux shell 函数应用示例02

    nginx服务控制脚本:

    安装ngix

    [root@wei function]# yum install gcc pcre-devel openssl-devel
    
    [root@wei function]# tar xf nginx-1.14.2.tar.gz 
    [root@wei function]# cd nginx-1.14.2
    [root@wei nginx-1.14.2]# ./configure --prefix=/usr/local/nginx
    [root@wei nginx-1.14.2]# make && make instal
    
    


    编写控制nginx的脚本

    #!/bin/bash
    #
    
    nginx_cmd=/usr/local/nginx/sbin/nginx
    nginx_conf=/usr/local/nginx/conf/nginx.conf
    nginx_pid_file=/usr/local/nginx/logs/nginx.pid
    start(){
        $nginx_cmd
        if [ $? -eq 0 ];then
            echo "服务nginx启动.....[ok]"
        fi
    }
    
    stop(){
        $nginx_cmd -s stop
        
    
    }
    
    reload(){
        if $nginx_cmd -t &> /dev/null;then
            $nginx_cmd -s reload
        else
            $nginx_cmd -t
        fi
    
    }
    
    status(){
        if [ -e $nginx_pid_file  ];then
            echo "服务nginx(`cat $nginx_pid_file`) is running"
        else
            echo "服务nginx is stopped"
        fi
    }
    
    
    if [ -z $1 ];then
        echo "使用:$0{start|stop|restart|reload|status}"
        exit 9
    fi
    
    case $1 in
        start)
            start
            ;;
        stop)
            stop
            ;;
        restart)
            stop
            sleep 2
            start
            ;;
        reload)
            reload
            ;;
        *)
            echo "使用:$0{start|stop|restart|reload|status}"
            exit 9
            ;;
    esac

    演示:

    [root@wei init.d]# /etc/init.d/nginx status
    服务nginx(4974) is running
    [root@wei init.d]# /etc/init.d/nginx statscdsdc
    使用:/etc/init.d/nginx{start|stop|restart|reload|status}
    [root@wei init.d]# /etc/init.d/nginx stop
    [root@wei init.d]# /etc/init.d/nginx status
    服务nginx is stopped
    [root@wei init.d]# /etc/init.d/nginx start
    服务nginx启动.....[ok]
    
    人生得意须尽欢,莫使金樽空对月。 天生我材必有用,千金散尽还复来。
  • 相关阅读:
    UVaLive 3695 Distant Galaxy (扫描线)
    UVaLive 3695 City Game (扫描线)
    CodeForces 349B Color the Fence (DP)
    UVaLive 3905 Meteor (扫描线)
    UVaLive 3902 Network (无根树转有根树,贪心)
    NodeJS学习笔记 (16)子进程-child_process(ok)
    字符编码笔记:ASCII,Unicode 和 UTF-8
    NodeJS学习笔记 (15)二进制数据-buffer(ok)
    NodeJS学习笔记 (14)URL查询字符串-querystring(ok)
    NodeJS学习笔记 (13)数据加密-crypto(OK)
  • 原文地址:https://www.cnblogs.com/heian99/p/11972302.html
Copyright © 2011-2022 走看看