编写一个nginx开机启动脚本
2014-03-12 00:00
519 查看
1.编写脚本
[root@gyf init.d]# vim /etc/init.d/nginx
#!/bin/bash
#chkconfig: 2345 80 90
#description: nginx
alter=$1
nginx=/usr/local/nginx/sbin/nginx
nginx_conf=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
. /etc/rc.d/init.d/functions
function if_info
{
if [ $2 == 0 ];then
echo -n "nginx $1 is ok!" && success && echo
else
echo -n "nginx $1 is error!" && success && echo
fi
}
case $alter in
start)
if [ -f $nginx_pid ];then
echo "nginx is already start!"
else
$nginx -c $nginx_conf
if_info start $?
fi
;;
stop)
if [ ! -f $nginx_pid ];then
echo "nginx is already stop!"
else
kill -TERM `cat $nginx_pid`
if_info stop $?
fi
;;
restart)
if [ ! -f $nginx_pid ];then
echo "nginx is stop,please start nginx!"
else
kill -HUP `cat $nginx_pid`
if_info restart $?
fi
;;
test)
$nginx -t -c $nginx_conf
# $nginx -t
if_info test $?
;;
status)
if [ ! -f $nginx_pid ];then
echo "nginx is stop"
else
echo "nginx is runing"
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart|test}"
;;
esac
#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run
第一行,告诉系统使用的shell,所以的shell脚本都是这样。
第二行,chkconfig后面有三个参数2345,80和90告诉chkconfig程序,需要在rc2.d~rc5.d目录下,创建名字为 S80auto_run的文件连接,连接到/etc/rc.d/init.d目录下的的auto_run脚本。第一个字符是S,系统在启动的时候,运行脚 本auto_run,就会添加一个start参数,告诉脚本,现在是启动模式。同时在rc0.d和rc6.d目录下,创建名字为K90auto_run的 文件连接,第一个字符为K,个系统在关闭系统的时候,会运行auto_run,添加一个stop,告诉脚本,现在是关闭模式
2.将该文件设置为可执行文件
chmod +x /etc/init.d/nginx
3.添加指定的系统服务
chkconfig --add nginx
4.启动
/etc/init.d/nginx start
[root@gyf init.d]# vim /etc/init.d/nginx
#!/bin/bash
#chkconfig: 2345 80 90
#description: nginx
alter=$1
nginx=/usr/local/nginx/sbin/nginx
nginx_conf=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
. /etc/rc.d/init.d/functions
function if_info
{
if [ $2 == 0 ];then
echo -n "nginx $1 is ok!" && success && echo
else
echo -n "nginx $1 is error!" && success && echo
fi
}
case $alter in
start)
if [ -f $nginx_pid ];then
echo "nginx is already start!"
else
$nginx -c $nginx_conf
if_info start $?
fi
;;
stop)
if [ ! -f $nginx_pid ];then
echo "nginx is already stop!"
else
kill -TERM `cat $nginx_pid`
if_info stop $?
fi
;;
restart)
if [ ! -f $nginx_pid ];then
echo "nginx is stop,please start nginx!"
else
kill -HUP `cat $nginx_pid`
if_info restart $?
fi
;;
test)
$nginx -t -c $nginx_conf
# $nginx -t
if_info test $?
;;
status)
if [ ! -f $nginx_pid ];then
echo "nginx is stop"
else
echo "nginx is runing"
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart|test}"
;;
esac
#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run
第一行,告诉系统使用的shell,所以的shell脚本都是这样。
第二行,chkconfig后面有三个参数2345,80和90告诉chkconfig程序,需要在rc2.d~rc5.d目录下,创建名字为 S80auto_run的文件连接,连接到/etc/rc.d/init.d目录下的的auto_run脚本。第一个字符是S,系统在启动的时候,运行脚 本auto_run,就会添加一个start参数,告诉脚本,现在是启动模式。同时在rc0.d和rc6.d目录下,创建名字为K90auto_run的 文件连接,第一个字符为K,个系统在关闭系统的时候,会运行auto_run,添加一个stop,告诉脚本,现在是关闭模式
2.将该文件设置为可执行文件
chmod +x /etc/init.d/nginx
3.添加指定的系统服务
chkconfig --add nginx
4.启动
/etc/init.d/nginx start
相关文章推荐
- nginx开机启动脚本
- RHEL6编译安装nginx、开机启动脚本
- 制作CentOS中Nginx开机启动脚本(转)
- nginx 设置开机自动启动脚本
- nginx启动脚本并且开机自起
- CentOS 6.5 开机启动MySQL Apache Nginx脚本
- Linux服务器Jboss运行环境搭建步骤和开机自动启动脚本编写运行
- Nginx启动脚本的编写
- Linux服务器Jboss运行环境搭建步骤和开机自动启动脚本编写运行
- nginx的编译安装以及启动脚本编写
- Linux 开机启动的 执行rc脚本(shell编写)的顺序
- Nginx开机启动脚本
- nginx 安装、编写启动脚本、配置
- ubuntu编写开机自启动shell脚本
- nginx开机自动启动脚本
- nginx在windows下的安装,以及编写启动关闭nginx等操作的脚本
- 编写nginx的启动脚本和配置文件
- centos LNMP第一部分环境搭建 LAMP LNMP安装先后顺序 php安装 安装nginx 编写nginx启动脚本 懒汉模式 mv /usr/php/{p.conf.default,p.conf} php运行方式SAPI介绍 第二十三节课
- C# 编写Windows服务实现开机启动一个程序
- nginx启动脚本编写