shell语句编写nginx的启动脚本
2017-09-04 23:22
363 查看
nginx的启动脚本
问题:在预编译安装nginx时候每次启动时都非常不方便,所以想了下写个nginx脚本在/etc/init.d目录下可实现service的方式启动、停止、重启这样就方便多了! [root@cml init.d]# vim nginxd#!/bin/bash#chkconfig: 2345 20 80
prog="nginxd"nginx_bin="/usr/local/nginx/sbin/nginx" if [ -x $nginx_bin ]; then ##if语句判断是否存在nginx路径 echo "$nginx_bin is installled !" else echo -n "$nginx_bin not installed !" exit 5fi start(){ echo -n "starting $prog:" $nginx_bin -t ##测试nginx配置文件 a=$? if [ $a -eq 0 ]; then ###if语句判断上一句是否执行成功 touch /tmp/nginx.pid ##创建一个nginx.pid文件后启动nginx $nginx_bin else echo "please check your nginx config" exit 10 fi} stop(){ echo -n $"stopping $prog:" $nginx_bin -s stop ##停止nginx a=$? if [ $a -eq 0 ]; then ##判断执行上一句成功就删除nginx.pid文件输出信息 rm -rf /tmp/nginx.pid echo "success stop nginx" else echo "check your nginx command" exit 11 fi} case $1 in ## start) start;; stop) stop;; reload|restart) stopsleep 2start;; *) echo "Usage:$0{start|stop|reload/restart}" ;;esac 验证:
[root@cml init.d]# service nginxd start/usr/local/nginx/sbin/nginx is installled !starting nginxd:nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successfulnginx: [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() 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() to 0.0.0.0:80 failed (98: Address already in use)nginx: [emerg] still could not bind() [root@cml init.d]# service nginxd stop/usr/local/nginx/sbin/nginx is installled !stopping nginxd:success stop nginx[root@cml init.d]# service nginxd start/usr/local/nginx/sbin/nginx is installled !starting nginxd:nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@cml init.d]# service nginxd restart/usr/local/nginx/sbin/nginx is installled !stopping nginxd:success stop nginxstarting nginxd:nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
问题:在预编译安装nginx时候每次启动时都非常不方便,所以想了下写个nginx脚本在/etc/init.d目录下可实现service的方式启动、停止、重启这样就方便多了! [root@cml init.d]# vim nginxd#!/bin/bash#chkconfig: 2345 20 80
prog="nginxd"nginx_bin="/usr/local/nginx/sbin/nginx" if [ -x $nginx_bin ]; then ##if语句判断是否存在nginx路径 echo "$nginx_bin is installled !" else echo -n "$nginx_bin not installed !" exit 5fi start(){ echo -n "starting $prog:" $nginx_bin -t ##测试nginx配置文件 a=$? if [ $a -eq 0 ]; then ###if语句判断上一句是否执行成功 touch /tmp/nginx.pid ##创建一个nginx.pid文件后启动nginx $nginx_bin else echo "please check your nginx config" exit 10 fi} stop(){ echo -n $"stopping $prog:" $nginx_bin -s stop ##停止nginx a=$? if [ $a -eq 0 ]; then ##判断执行上一句成功就删除nginx.pid文件输出信息 rm -rf /tmp/nginx.pid echo "success stop nginx" else echo "check your nginx command" exit 11 fi} case $1 in ## start) start;; stop) stop;; reload|restart) stopsleep 2start;; *) echo "Usage:$0{start|stop|reload/restart}" ;;esac 验证:
[root@cml init.d]# service nginxd start/usr/local/nginx/sbin/nginx is installled !starting nginxd:nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successfulnginx: [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() 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() to 0.0.0.0:80 failed (98: Address already in use)nginx: [emerg] still could not bind() [root@cml init.d]# service nginxd stop/usr/local/nginx/sbin/nginx is installled !stopping nginxd:success stop nginx[root@cml init.d]# service nginxd start/usr/local/nginx/sbin/nginx is installled !starting nginxd:nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@cml init.d]# service nginxd restart/usr/local/nginx/sbin/nginx is installled !stopping nginxd:success stop nginxstarting nginxd:nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
相关文章推荐
- shell学习二十三--case语句编写mysql启动脚本
- 用shell编写nginx脚本的启动,关闭,重加载
- 编写启动程序和停止程序的shell脚本
- 自己写了个nginx启动脚本,shell
- centos LNMP第一部分环境搭建 LAMP LNMP安装先后顺序 php安装 安装nginx 编写nginx启动脚本 懒汉模式 mv /usr/php/{p.conf.default,p.conf} php运行方式SAPI介绍 第二十三节课
- shell脚本条件语句编写
- SHELL编写redis启动脚本
- shell脚本编写 之 条件选择,条件判断,循环语句
- nginx 安装、编写启动脚本、配置
- 编写nginx的启动脚本和配置文件
- CentOS6.8 x86_64bit shell脚本实现模拟nginx服务启动与关闭
- shell 为jar文件,编写可执行启动脚本
- 编写可以监控oracle监听器是否启动的shell脚本
- 安装apached源码包以及编写shell脚本使其启动更加方便,并且和启动系统服务相同
- rails+unicorn+nginx配置、shell启动脚本
- mysql5.6.7多实例安装、配置的详细讲解分析及shell启动脚本的编写
- nginx的编译安装以及启动脚本编写
- nginx启动脚本编写
- linux环境下编写shell脚本实现启动停止tomcat服务的方法
- nginx在windows下的安装,以及编写启动关闭nginx等操作的脚本