Shell脚本 - nginx启动脚本
OS:CentOS/Redhat 系列
并在 Centos 6.7 和 Centos 7.2 上测试正常
#!/bin/bash
#
# auth: daxin
# time: 2018/07/10
#
# nginx start nginx web server
#
# chkconfig: - 10 90
# description: Start, stops and reload nginx web server
#
# config: /usr/local/nginx/conf/nginx.conf
# config: /usr/local/nginx/conf/vhosts
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start:
# Required-Stop:
# Default-Start: 3
# Default-Stop:
# Short-Description: start and stop nginx web server
# Description: Start, stop and reload nginx web server
### END INIT INFO # Source function library
. /etc/init.d/functions NGINX_DIR="/usr/local/nginx"
NGINX="${NGINX_DIR}/sbin/nginx"
NGINX_CONF="${NGINX_DIR}/conf/nginx.conf"
PROG=$(basename $NGINX)
LOCK_FILE="${NGINX_DIR}/${PROG}.lock" # check Command exists
if [ ! -x ${NGINX} ]; then
echo -n $"${NGINX} does not exists."; warning; echo
exit 5
fi function start() {
[ -f $NGINX_CONF ] || exit 6
$NGINX -c $NGINX_CONF
retval=$?
if [ $retval -eq 0 ]; then
touch $LOCK_FILE
action "Starting $PROG" /bin/true
else
action "Starting $PROG" /bin/false
fi
return $retval
} function stop() {
pkill $PROG
retval=$?
if [ $retval -eq 0 ]; then
rm -f $LOCK_FILE
action "Stop $PROG" /bin/true
else
action "Stop $PROG" /bin/false
fi
return $retval
} function restart() {
configtest_q || return 6
stop
start
} function reload() {
configtest_q || return 6
nginx_main_process=$(ps aux | grep $NGINX | grep -v grep | awk '{print $2}')
kill -HUP $nginx_main_process
retval=$?
if [ $retval -eq 0 ]; then
action "Reload $PROG" /bin/true
else
action "Reload $PROG" /bin/false
fi
return $retval
} function configtest_q() {
$NGINX -t -c $NGINX_CONF
} function status() {
nginx_main_process=$(ps aux | grep $NGINX | grep -v grep | awk '{print $2}')
if [ -z $nginx_main_process ]; then
action "$PROG is not running" /bin/false
else
action "$PROG is runing" /bin/true
fi
} case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest_q
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|reload|configtest|status|restart}"
exit 2
esac
Shell脚本 - nginx启动脚本的更多相关文章
- shell脚本之nginx启动脚本、统计日志字段、for循环实战、跳板机
1.NGINX启动脚本 #!/bin/bash # chkconfig: 235 32 62 # description: nginx [ -f /etc/init.d/functions ] &am ...
- linux nginx 启动脚本
linux nginx 启动脚本 [root@webtest76 ~]# vi /etc/init.d/nginx #!/bin/bash # nginx Startup script for the ...
- Nginx 启动脚本/重启脚本
第一步先运行命令关闭nginx sudo kill `cat /usr/local/nginx/logs/nginx.pid` 第二步 vi /etc/init.d/nginx 输入以下内容 #!/b ...
- nginx启动脚本,手动编辑
nginx启动脚本,手动编辑 #! /bin/bash # chkconfig: - # description: nginx service XDIR=/www/server/nginx DESC= ...
- centos LNMP第一部分环境搭建 LAMP LNMP安装先后顺序 php安装 安装nginx 编写nginx启动脚本 懒汉模式 mv /usr/php/{p.conf.default,p.conf} php运行方式SAPI介绍 第二十三节课
centos LNMP第一部分环境搭建 LAMP安装先后顺序 LNMP安装先后顺序 php安装 安装nginx 编写nginx启动脚本 懒汉模式 mv /usr/local/php/{ ...
- Nginx 启动脚本
Nginx 启动脚本 1.vim /etc/init.d/nginx #!/bin/bash # chkconfig: - 30 21 # description: http service. # S ...
- LNMP 1.4 nginx启动脚本和配置文件
编写Nginx启动脚本,写入下面这段,授权755 vim /etc/init.d/nginx #!/bin/bash # chkconfig: - # description: http servic ...
- nginx启动脚本和配置文件
1.编写Nginx启动脚本,并加入系统服务 vim /etc/init.d/nginx并在其中写入如下内容:#!/bin/bash# chkconfig: - 30 21# description: ...
- nginx启动脚本(class练习)
说明:使用类的方式编写程序启动脚本(练习) 1 #!/usr/bin/env python import sys import os from subprocess import Popen,PIPE ...
随机推荐
- dpr dproj 扩展名区别,dprdproj
这段时间用xe6,看了下目录下生成的一些文件,因为隐藏了扩展名,看到两个名字一样的文件,右键属性看了下,同名但扩展名不同,百度了下区别,没有找到答案,问群里的朋友才知道区别,特此记录下来: dpr:D ...
- 学习 SQL 语句 - Select(9): 其他
//只要前五条记录 procedure TForm1.Button1Click(Sender: TObject); begin with ADODataSet1 do begin Clos ...
- 【bzoj1076】[SCOI2008]奖励关 期望dp+状态压缩dp
题目描述 你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物,每次你都可以选择吃或者不吃(必须在抛出下一个宝物之前做出选择,且现在决定不吃的宝物以后也不能再 ...
- Codeforces Round #524 Div. 2 翻车记
A:签到.room里有一个用for写的,hack了一发1e8 1,结果用了大概600+ms跑过去了.惨绝人寰. #include<iostream> #include<cstdio& ...
- hdu 1142 A Walk Through the Forest (最短路径)
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- NetScaler Best Practice With VMAC In A High Availability Configuration
NetScaler Best Practice With VMAC In A High Availability Configuration https://www.citrix.com/blogs/ ...
- [LOJ #2473] [九省联考2018] 秘密袭击coat
题目链接 洛谷. LOJ,LOJ机子是真的快 Solution 我直接上暴力了...\(O(n^2k)\)洛谷要\(O2\)才能过...loj平均单点一秒... 直接枚举每个点为第\(k\)大的点,然 ...
- Android Intent Action 一览表
String ADD_SHORTCUT_ACTION 动作:在系统中添加一个快捷方式.. "android.intent.action.ADD_SHORTCUT" String A ...
- CORS解决跨域访问问题
简言之,CORS就是为了让AJAX可以实现可控的跨域访问而生的. Tomcat下的配置 下载cors-filter-1.7.jar,java-property-utils-1.9.jar [下载 ...
- opencv学习--透视变化
透视变换和仿射变换具有很大的相同特性,前面提到了放射变化,这里再次把它拿出和透视变换进行比较 #include"cv.h" #include"highgui.h" ...