Nginx管理脚本

Posted 青山应回首

tags:

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

 1 #!/bin/bash
 2 # chkconfig: 2345 40 98
 3 # description: Start/Stop nginx server
 4 
 5 path=/application/nginx/sbin
 6 pid=/application/nginx/logs/nginx.pid
 7 RETVAL=0
 8 
 9 . /etc/init.d/functions
10 
11 start(){
12     if [ ! -f $pid ];then
13         $path/nginx
14         RETVAL=$?
15         if [ $RETVAL -eq 0 ];then
16             action "nginx is started" /bin/true
17             return $RETVAL
18         else
19             action "nginx is started" /bin/false
20             return $RETVAL
21         fi
22     else
23         echo "nginx is running"
24         return 0
25     fi
26 }
27 stop(){
28     if [ -f $pid ];then
29         $path/nginx -s stop
30          RETVAL=$?
31         if [ $RETVAL -eq 0 ];then
32             action "nginx is stopped" /bin/true
33             return $RETVAL
34         else
35             action "nginx is stopped" /bin/false
36             return $RETVAL
37         fi
38     else
39         echo "nginx is no running"
40         return $RETVAL
41     fi
42 }
43  
44 case "$1" in
45     start)
46         start
47         RETVAL=$?
48         ;;
49     stop)
50         stop
51         RETVAL=$?
52         ;;
53     restart)
54          stop
55              sleep 1
56          start
57          RETVAL=$?
58          ;;
59     *)
60          echo $"Usage: $0 {start|stop|restart|reload}"
61          exit 1
62 esac
63 exit $RETVAL

 

以上是关于Nginx管理脚本的主要内容,如果未能解决你的问题,请参考以下文章

Nginx和Tomcat的管理脚本

片段中未调用 onSaveInstanceState

Nginx管理脚本

常用python日期日志获取内容循环的代码片段

tengine/nginx服务启动管理脚本(未使用系统funtions函数)

使用本脚本可以自动批量完成中间节点环境的部署工作,包括:Nginx编译安装添加程序管理脚本设置开机启动反向代理配置证书分发添加iptables规则等