添加nginx到系统服务注意事项
2017-02-04 15:00
645 查看
1、在/etc/init.d/目录下编写脚本,名为nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by ruijie. at 2014.02.26
# if you find any errors on this scripts,please contact ruijie.
# and send mail to ruijie at gmail dot com.
# ruijie.qiao@gmail.com
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ] && netstat -tunpl | grep nginx &> /dev/null;then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog!"
$nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog!"
$nginxd -s stop
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/nginx
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog!"
#kill -HUP `cat ${nginx_pid}`
$nginxd -s reload
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|help}"
exit 1
esac
exit $RETVAL
[root@example
~]# cp nginx /etc/init.d/
[root@example ~]# chmod 755 /etc/init.d/nginx
[root@example ~]# chkconfig --add nginx
3、nginx启动、停止、无间断服务重启
[root@example ~]# service nginx start
[root@example ~]# service nginx stop
[root@example ~]# service nginx reload
添加完以后使用上述命令如果提示No such file or directory 那么可能是因为文件格式不是unix,需要使用命令转化文件格式如下:
两个命令的用法相同,不同的是两个命令使用的环境不一样.
dos2unix在CentOS系列的系统中使用,fromdos则在Ubuntu系列的系统中使用。
用法:dos2unix filename = fromdos filename
意思是:转换文件格式,将windos系统的文件转换成linux系统可以使用的文件格式,否则文件在linux系统中可能会出现错误,如:文件中显示^m 这样的错误字符。
导致这样的错误出现的原因是,windos环境中的换行符是\r\n,而linux系统中的换行符直接\n就行了。
CENTOS下yum install dos2unix -y
UBUNTU下apt-get install tofrodos ?
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by ruijie. at 2014.02.26
# if you find any errors on this scripts,please contact ruijie.
# and send mail to ruijie at gmail dot com.
# ruijie.qiao@gmail.com
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ] && netstat -tunpl | grep nginx &> /dev/null;then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog!"
$nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog!"
$nginxd -s stop
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/nginx
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog!"
#kill -HUP `cat ${nginx_pid}`
$nginxd -s reload
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|help}"
exit 1
esac
exit $RETVAL
[root@example
~]# cp nginx /etc/init.d/
[root@example ~]# chmod 755 /etc/init.d/nginx
[root@example ~]# chkconfig --add nginx
3、nginx启动、停止、无间断服务重启
[root@example ~]# service nginx start
[root@example ~]# service nginx stop
[root@example ~]# service nginx reload
添加完以后使用上述命令如果提示No such file or directory 那么可能是因为文件格式不是unix,需要使用命令转化文件格式如下:
两个命令的用法相同,不同的是两个命令使用的环境不一样.
dos2unix在CentOS系列的系统中使用,fromdos则在Ubuntu系列的系统中使用。
用法:dos2unix filename = fromdos filename
意思是:转换文件格式,将windos系统的文件转换成linux系统可以使用的文件格式,否则文件在linux系统中可能会出现错误,如:文件中显示^m 这样的错误字符。
导致这样的错误出现的原因是,windos环境中的换行符是\r\n,而linux系统中的换行符直接\n就行了。
CENTOS下yum install dos2unix -y
UBUNTU下apt-get install tofrodos ?
相关文章推荐
- Windows下添加MySQL服务到系统服务以及注意事项
- CentOS6.3添加nginx php-fpm系统服务详细说明
- nginx添加系统服务(start|stop|restart|reload)
- 添加nginx为系统服务(service nginx start/stop/restart)
- Linux添加nginx为系统服务(service nginx status/start/stop/restart)
- nginx添加为系统服务
- 添加nginx为系统服务(service nginx start/stop/restart)
- buildroot 文件系统添加telnet, ssh, 以及制作注意事项
- 上层应用调用自定义的系统服务注意事项
- CentOS6.3添加nginx系统服务的实例详解
- 将Nginx添加到系统服务(使其可使用service命令控制)
- CentOS6.3添加nginx系统服务详细说明
- 调用外围系统的webservice服务注意事项
- CentOS6.3添加nginx系统服务详细说明
- magento添加系统sections配置时应注意的事项
- c# 系统服务更改服务名称及部署注意事项
- 添加nginx为系统服务(service nginx start/stop/restart)
- 在windows下将Nginx添加为系统服务
- 添加nginx为系统服务(service nginx start/stop/restart)
- 添加Nginx作为系统服务