小助手科技_小程序定制开发图片

小助手科技_小程序定制开发图片

小助手科技_小程序定制开发图片

小助手科技_小程序定制开发图片

小助手科技_小程序定制开发图片

开机自启动nginx

作者: 梧桐下细语
来源: http://www.l-helper.com
时间: Aug 19, 2020
当前位置:  小助手科技 > 资讯 > 开机自启动nginx

编写shell脚本的方式来处理

vi /etc/init.d/nginx  (输入下面的代码)


#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL


:wq  保存并退出

设置文件的访问权限

chmod a+x /etc/init.d/nginx   (a+x ==> all user can execute  所有用户可执行)


#nginx reload


执行提示 /bin/bash^M: bad interpreter: No such file or directory
脚本是在windows下编辑上传的,出现上面错误的原因之一是脚本文件是DOS格式的,即每一行的行尾以\r\n来标识, 使用vim编辑器打开脚本, 运行:
:set ff?
可以看到set ff=dos的字样. 使用:set ff=unix把它强制为unix格式的, 然后wq存盘退出, 即可.


参考:

http://www.cnblogs.com/meteoric_cry/archive/2011/01/27/1945882.html


上一篇: 关于myql函数不能执行的问题

想了解更多?现在就开始免费体验

请您留言
深圳市小助手科技有限公司
0755-82494862
小助手科技_姓名图片
小助手科技_电话图片
小助手科技_邮箱图片
类型咨询类型
小助手科技_类型图片
180 0250 1799(微信同号)
0755-8249 4862
QQ交谈 QQ交谈
友情链接:
网站地图
Copyright 2014-2020 深圳市小助手科技有限公司-版权所有
ICP备案号:粤ICP备15072167号-1