zoukankan      html  css  js  c++  java
  • 026_编写 nginx 启动脚本

    #!/bin/bash
    #本脚本编写完成后,放置在/etc/init.d/目录下,就可以被 Linux 系统自动识别到该脚本
    #如果本脚本名为/etc/init.d/nginx,则
    #service nginx start 就可以启动该服务
    #service nginx stop 就可以关闭服务
    #service nginx restart 可以重启服务
    #service nginx status 可以查看服务状态

    program=/usr/local/nginx/sbin/nginx
    pid=/usr/local/nginx/logs/nginx.pid

    start(){
    if [ -f $pid ];then
        echo "nginx 服务已经处于开启状态"
    else
        $program #启动
    fi
    }

    stop(){
    if [ -! -f $pid ];then
            echo "nginx 服务已经关闭"
    else
            $program -s stop #关闭
            echo "关闭服务 ok"
    fi
    }

    status(){
    if [ -f $pid ];then
           echo "服务正在运行..."
    else
           echo "服务已经关闭"
    fi
    }  

    case $1 in
    start)
            start;;
    stop)
            stop;;
    restart)
            stop
            sleep 1
            start;;
    status)
            status;;
    *)
            echo "你输入的语法格式错误"
    esac

  • 相关阅读:
    第四次作业
    第三次
    第十次作业
    第九次作业
    第八次作业
    10.29第七次
    15
    14
    13 this
    12 电视机
  • 原文地址:https://www.cnblogs.com/luwei0915/p/10515175.html
Copyright © 2011-2022 走看看