shell脚本---nginx自动化脚本

一、该脚本实现nginx的开启,关闭,及重新启动。

#!/bin/bash
. /etc/init.d/functions 

function usage() { 
      echo $"usage:$0 {start|stop|restart}" 
      exit 1 
} 

function start() { 
      /usr/local/nginx/sbin/nginx 
      sleep 1 
      if [ `netstat -antlpe | grep nginx | wc -l` -ge 0 ];then 
      action "nginx is started." /bin/true 
      else 
      action "nginx is started." /bin/false 
      fi 
} 

function stop() { 
      killall nginx &>/dev/null 
      sleep 1 
      if [ `netstat -antlpe | grep nginx | wc -l` -eq 0 ];then 
      action "nginx is stopped." /bin/true 
      else 
      action "nginx is stopped." /bin/false 
      fi 
} 

function main() { 
      if [ $# -ne 1 ];then 
      usage $0 
      fi 
      case $1 in 
      start) 
      start 
      ;; 
      stop) 
      stop 
      ;; 
      restart) 
      stop 
      start 
      ;; 
      *) 
      usage $0 
      ;; 
      esac 
} 

main $* 

测试:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/excellent_L/article/details/86474255