用shell写ngin启动脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用shell写ngin启动脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash

[ -f /etc/init.d/functions ] && . /etc/init.d/functions 

pid=/application/nginx/logs/nginx.pid

nginx=/application/nginx/sbin/nginx

RED_COLOR=‘\E[1;31m‘

GREEN_COLOR=‘\E[1;32m‘

YELLOW_COLOR=‘\E[1;33m‘

BLUE_COLOR=‘\E[1;34m‘

PINK=‘\E[1;35m‘

SHAN=‘\E[31;5m‘

RES=‘\E[0m‘

 

start(){

   if [ -f $pid ]; then

  action "nginx 正在运行的" /bin/false

   else

  $nginx

  action "nginx 启动" /bin/true

               

fi

}

stop(){

if [ ! -f $pid ]; then

  action "nginx 已经停止了" /bin/false

   else           

  $nginx -s stop

  action  "nginx 停止" /bin/true

fi

}

reload(){

if [ ! -f $pid ]; then

  action "nginx 已经停止了" /bin/false

   else

  $nginx -s reload

  action "nginx 已重启" /bin/true

fi

}

case "$1" in

      start)

        start

      ;;

      stop)

        stop

      ;;

      reload)

        reload

      ;;

      restart)

        stop

        sleep 2

        start

      ;;

      *)

      echo -e "${SHAN}脑残这是例子 :$0 (stop|start|reload|restart)$RES"

esac


本文出自 “12216796” 博客,请务必保留此出处http://12226796.blog.51cto.com/12216796/1912241

以上是关于用shell写ngin启动脚本的主要内容,如果未能解决你的问题,请参考以下文章

用shell写一个服务启动脚本,速度get!

如何用shell脚本定时启动Tomcat服务

python定时器用法 + 获取脚本所在绝对路径 + 定义日志格式 + shell将脚本直接启动到后

Shell脚本 | 性能测试之启动流量

Linux的shell脚本文件中怎么写多个自动启动的系统服务

Shell脚本 | 性能测试之启动流量