模拟Nginx服务启动关闭

已知Nginx管理命令为:

启动:/application/nginx/sbin/nginx

停止:/application/nginx/sbin/nginx
-s stop

重新加载:/application/nginx/sbin/nginx
-s reload

请用case脚本模拟Nginx服务启动关闭:

/etc/init.d/nginx {start|stop|reload|restart},并可通过chkconfig管理。

[[email protected] ~]# cat /etc/init.d/nginx
#/bin/sh
# chkconfig: 2345 15 62  #设定运行级别以及启动和停止Nginx服务顺序
# description: Nginx Server  #脚本说明

[ -f /etc/init.d/functions]&&. /etc/init.d/functions||exit 1

#Define Arivables
Path=/application/nginx/sbin/nginx
RETVAL=0
 
#Define Start Function
start() {
  if [ `ss -lntup|grep nginx|wc -l` -gt 0];then
    echo "Nginx is Running..."
    else
      $Path
      RETVAL=$?
      if [ $RETVAL -eq 0 ];then
        action "Starting Nginx..."/bin/true
        else
        action "Starting Nginx..."/bin/false
      fi
  fi
  return $RETVAL
}
#Define Stop Function
stop() {
  if [ `ss -lntup|grep nginx|wc -l` -gt 0];then
      $Path -s stop
      RETVAL=$?
      if [ $RETVAL -eq 0 ];then
        action "Stopping Nginx..."/bin/true
        else
        action "Stopping Nginx..."/bin/false
      fi
    else
    echo "Nginx is Stopped"
  fi
  return $RETVAL
}
#Define Restart Function
reload() {
  if [ `ss -lntup|grep nginx|wc -l` -gt 0];then
      $Path -s reload
      RETVAL=$?
      if [ $RETVAL -eq 0 ];then
        action "Reloading Nginx..."/bin/true
        else
        action "Reloading Nginx..."/bin/false
      fi
    else
    echo "Nginx is Stopped"
  fi
  return $RETVAL
}
#Define Restart Function
restart() {
  stop
  sleep 1
  start
  return $RETVAL
}
case "$1" in
  start)
        start
        RETVAL=$?
        ;;
  stop)
        stop
        RETVAL=$?
        ;;
  reload)
        reload
        RETVAL=$?
        ;;
  restart)
        restart
        RETVAL=$?
        ;;
  *)
        echo "USAGE:$0 {start|stop|reload|restart}"
        RETVAL=2
        ;;
esac
exit $RETVAL

[[email protected] ~]# ls -l /etc/init.d/nginx
-rwxr-xr-x. 1 root root 1680 Jun  9 12:13 /etc/init.d/nginx
[[email protected] ~]# chkconfig --list|grep nginx
nginx           0:off 1:off 2:on 3:on 4:on 5:on 6:off
时间: 2024-12-09 18:44:30

模拟Nginx服务启动关闭的相关文章

Nginx系列~Nginx服务启动不了

1.错误:No mapping for the Unicode character exists in the target multi-byte code page) 解决方法:安装路径具有中文字符   2.错误:An attempt was made to access a socket in a way forbidden by its access permissions) 应为nginx默认使用的端口80端口,停止80端口   无法终止pid为4的system占用80端口进程 解决方法

NGINX快速启动关闭脚本

@echo off c: cd C:\nginx-1.8.0 :menu echo -------Nginx启动助手--------- echo 1.重启服务器 echo 2.启动服务器 echo 3.关闭服务器 @echo off set /p choose="请选择:" if %choose%==1 (goto rs) if %choose%==2 (goto start) if %choose%==3 (goto stop) :: 不合法输入符号 if %choose%!=1 |

windows下nginx的启动关闭

Windows下Nginx的启动.停止等命令 在Windows下使用Nginx,我们需要掌握一些基本的操作命令,比如:启动.停止Nginx服务,重新载入Nginx等,下面我就进行一些简单的介绍. 1.启动: C:\server\nginx-1.0.2>start nginx 或 C:\server\nginx-1.0.2>nginx.exe 注:建议使用第一种,第二种会使你的cmd窗口一直处于执行中,不能进行其他命令操作. 2.停止: C:\server\nginx-1.0.2>ngin

97: Address family not supported by protocol,nginx服务启动失败

1.启动nginx服务报错 环境:centos 6.9,yum安装的nginx,启动报错 [[email protected] ~]# nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)nginx: configuration file

linux 服务 启动 关闭 列表

##查看服务在每个级别的运行状态 chkconfig --list httpd           0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:启用  6:关闭 bluetooth       0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关闭  6:关闭 #停止 HTTPD服务  www.2cto.com [root@zhangxx etc]# service httpd stop 停止 httpd:[  确定  ] #启动httpd服务 [root@zh

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

tengine是淘宝对于nginx1.6.2的一个二次开发,性能比原生态nginx更好,这几天在做测试,想应用到现有的架构里.源码包安装后就牵涉到一个添加到系统服务方便管理问题,到网上搜nginx启动脚本一大堆,但不是自己写的总归不放心,再者好多用的是系统的/etc/rc.d/init.d/funtions函数来实现的,虽然看着很健壮,但想到出了问题后又得研究怎么排查,一不做二不休干脆写一个,把脚本和添加到系统服务的过程分享一下. 功能主要有:service tengine start serv

Svn服务启动关闭脚本

Svn启动服务脚本 因每次都需要手动开启关闭svn服务,颇为麻烦,直接使用数字键1-N来配置 使用平台: rhel centos6 7 使用: 直接复制脚本,然后chmod +x xx.sh 就能使用了 #!/bin/bash # # __auther__: xiong # __ time __: 2018年02月26日 09:28:09 # __ 作用 __: 用于启动svn服务的集中脚本文件 # __需学习__: shell数组,case # __ 使用 __: 脚本名称需要执行权限 直接使

LNMP环境搭建之Nginx服务启动失败

错误提示: Starting nginx:nginx:[emerg]bind()to 0.0.0.0:80 failed(98:Address alreadr in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)nginx: [emerg] bind(

Nginx服务启动脚本

#!/bin/sh#filename:rsync_start.sh#date:2015-12-23#作者:linuxzkq#Email:[email protected]#version:v1.0 .  /etc/init.d/functionspath=/application/nginx/sbin/nginxpid=/application/nginx/logs/nginx.pidprocess=`ps -ef|grep nginx|grep -v grep|wc -l` #USAGEfun