centos6 nginx开机启动脚本练习

452次阅读
没有评论

共计 1359 个字符,预计需要花费 4 分钟才能阅读完成。

#!/bin/bash
# chkconfig: 2345 32 62 
# description: nginx is a http server[-f /etc/init.d/functions] && . /etc/init.d/functions
pidfile=/usr/local/nginx/logs/nginx.pid
nginx=/usr/local/nginx/sbin/nginxusage(){ 
 RETVAL=$?
 if [$RETVAL -eq 0];then
 action "nginx is $1" /bin/true
 else
 action "nginx is $1" /bin/false
 fi
}
Start_nginx(){if [ -f $pidfile]; then
 echo "nginx is runing"
 else
 $nginx start
 RETVAL=$?
 usage STARTED
 fi
 return $RETVAL
}Stop_nginx(){if [ -f $pidfile]; then
 $nginx -s stop
 usage STOPED
 else
 ection "nginx is spoped" /bin/false
 fi
 return $RETVAL
}
Reload_nginx(){if [ -f $pidfile]; then
 $nginx -s reload
 usage RELOAD
 else
 action "nginx is stop, please start nginx!" /bin/false
 fi
 return $RETVAL
}case "$1" in
 start)
 Start_nginx
 RETVAL=$?
 ;;
 stop)
 Stop_nginx
 RETVAL=$?
 ;;
 restart)
 Stop_nginx
 sleep 2
 Start_nginx
 RETVAL=$?
 ;;
 reload)
 Reload_nginx
 RETVAL=$?
 ;;
 *)
 echo "usage:$0 {start|stop|reload|restart}"
 exit 1
esacexit $RETVAL

思路 centos6 开机作为启动项时默认会传值 start|stop|restart| 值 需要注意 nginx.pid 的文件, 随着启动进程号的出现而出现 首先把写好的脚本 cp nginx.sh /etc/init.d/nginxchmod +x /etc/init.d/nginx脚本开始加上启动顺序具体还要了解下基础# chkconfig: 2345 10 90
# description: nginx is a http server需要了解基础 contos 系统启动 nit.d ll /etc/rc.d/rc3.d |grep 31init.d ll /etc/rc.d/rc3.d |grep 32➜  init.d ll /etc/rc.d/rc3.d |grep 61➜  init.d ll /etc/rc.d/rc3.d |grep 62 然后把脚本启动修改为# chkconfig: 2345 31 62
# description: nginx is a http server注意这是 centos6 的使用方法和 7 有不同之处➜ init.d chkconfig --add nginx
➜ init.d chkconfig --list nginxchkconfig nginx on/off自启动的机制就是 server 服务 start所以加入自启动后系统会自动给脚本传 start 参数

微信扫描下方的二维码阅读本文

正文完
 0
yx
版权声明:本站原创文章,由 yx 于2018-05-04发表,共计1359字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码

bttech

文章搜索
一言一句话
-「
随机文章
ubuntu20 TeslaT4 安装stable diffusion-webui

ubuntu20 TeslaT4 安装stable diffusion-webui

升级系统 执行 nvidia-smi 查看是否安装了相关驱动 如果执行 nvidia-smi 没有相关命令就需...
MacBook Pro M4 关闭swap

MacBook Pro M4 关闭swap

Swap 是将磁盘虚拟为内存来用的,所以速度肯定比不上扎扎实实的内存的。我是 16G 内存,对于我平时使用完全...
elasticsearch7.8.0索引备份到阿里云oss以及恢复

elasticsearch7.8.0索引备份到阿里云oss以及恢复

背景需求,阿里云新建了一套 elk 但是数据需要进行迁移备份, 解决方案使用 logstash 迁移很慢,10...
ubuntu20安装部署comfyui脚本

ubuntu20安装部署comfyui脚本

基础环境参考上一篇文章安装基本的驱动 这个使用的曲线较高,有一定的学习成本。脚本如下直接使用即可! 微信扫描下...
k8s安装chatwoot后配置邮件报超时问题

k8s安装chatwoot后配置邮件报超时问题

k8s 安装好 chathoot 后配置好了邮件的相关变量 官方配置示例 SMTP_ADDRESS: ""SM...