首页 > 系统相关 >nginx启停shell脚本

nginx启停shell脚本

时间:2022-10-10 15:45:31浏览次数:64  
标签:shell 服务 start pid stop echo nginx 启停

#!/bin/bash

# 编写 nginx 启动脚本 
# 本脚本编写完成后,放置在/etc/init.d/目录下,就可以被 Linux 系统自动识别到该脚本
# 如果本脚本名为/etc/init.d/nginx,则 service nginx start 就可以启动该服务
# service nginx stop 就可以关闭服务
# service nginx restart 可以重启服务
# service nginx status 可以查看服务状态
 
program=/usr/local/nginx/sbin/nginx
pid=/usr/local/nginx/logs/nginx.pid
start(){
if [ -f $pid ];then
  echo  "nginx 服务已经处于开启状态"
else
  $program
fi
stop(){
if [ -! -f $pid ];then
  echo "nginx 服务已经关闭"
else
  $program -s stop
  echo "关闭服务 ok"
fi
}
status(){
if [ -f $pid ];then
  echo "服务正在运行..."
else
  echo "服务已经关闭"
fi
}
 
case $1 in
start)
  start;;
stop)
  stop;;
restart)
  stop
  sleep 1
  start;;
status)
  status;;
*)
  echo  "你输入的语法格式错误"
esac

标签:shell,服务,start,pid,stop,echo,nginx,启停
From: https://www.cnblogs.com/tang-learning/p/16775949.html

相关文章

  • FinalShell - SSH工具
    官网:http://www.hostbuf.com/ Windows版下载地址:http://www.hostbuf.com/downloads/finalshell_install.exe  ......
  • 使用shell脚本上传文件至阿里云OSS(无需装任何sdk)
      #!/bin/bashhost="oss-cn-hangzhou.aliyuncs.com"bucket="bucket"#BucketNameid="id"#AccessKeyIdkey="key"#AccessKeySecretosshost=$bucket.$host......
  • 41、shell编程基础
    bash的变量默认都是全局变量,脚本内都可以调用,无论在什么位置(函数体中也一样),即函数体外可以调用函数体内的变量;local一般用于局部变量声明,多在函数体内使用;如果......
  • nginx 图片压缩
    说明本文使用的nginx是用编译后安装的方式本文添加模块是在编译前,进行配置需要ngx_http_image_filter_module模块步骤安装nginx运行命令下载文件包wgethttp://ng......
  • 给NGINX添加几个常用的安全选项
    add_headerX-XSS-Protection1;add_headerX-Frame-OptionsSAMEORIGINalways;add_headerX-Content-Type-Options'nosniff';add_headerReferrer-Policy "no-referre......
  • 修改Nginx配置返回指定content-type的方法详解
    nginx作为一个http服务器,在功能实现方面和性能方面都表现的非常优越,下面这篇文章主要给大家介绍了关于修改Nginx配置返回指定content-type的相关资料,需要的朋友可以参考......
  • Nginx面试题
    1、请解释一下什么是Nginx?Nginx是一个web服务器和反向代理服务器,用于HTTP、HTTPS、SMTP、POP3和IMAP协议。2、请列举Nginx的一些特性。Nginx服务器的特性包括:反......
  • nginx+uwsgi 部署 django项目
    一、nginx:1.目录结构、常用命令和查杀进程:/usr/sbin/nginx:主程序/etc/nginx:存放配置文件/usr/share/nginx:存放静态文件/var/log/nginx:存放日志2.命令:servicenginxsta......
  • Jmeter——BeanShell 内置变量vars、props、prev的使用
    在使用Jmeter过程中,或多或少都会接触些BeanShell,它会使工具的使用,变得更灵活。Jmeter中关于BeanShell的有:1.BeanShellSampler取样器:完成Beanshell请求组件中定......
  • Nginx 反向代理教程
       官网地址:https://nginx.org/en/download.html  1.修改Nginx监听端口号8089server{listen8089;server_namelocalhost;......