zoukankan      html  css  js  c++  java
  • Ubuntu 16.04开机自启Nginx简单脚本

    本文要记述的是最简单的Ubuntu下开机自启 nginx的脚本

    这里将nginx装在了/usr/local/nginx目录下,nginx本身没有注册成服务,所以直接使用服务开机自启是不行的,除非自己写nginx.service脚本,这不在本文范畴内。

    创建脚本文件

    $ sudo vim /etc/init.d/nginx.sh
    

    脚本内容,注意替换root密码、nginx执行文件目录和配置文件目录

    #!/bin/bash
    #auto run nginx when system startup
    sudo -S /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf << EOF
    root密码
    EOF
    exit 0
    

    指定开机自启,最后可以添加优先级,比如,90

    $ sudo update-rc.d  nginx.sh defaults
    

    此时重启就可以发现nginx已经开机自启了。

    如果你在写完启动脚本的后,手动运行该脚本以确定是否可行的话,你会得到一个错误insserv: warning: script 'nginx.sh' missing LSB tags and overrides ,这种错误不会影响脚本的启动,只是提示脚本写的不规范,没有在脚本中发现以### BEGIN INIT INFO开头,以### END INIT INFO结尾的标签,因为没有影响,这里就没有写,可以参考下边的脚本去去除这个错误:

    #!/bin/sh
    # kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
    if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
        set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
    fi
    ### BEGIN INIT INFO
    # Provides:          skeleton
    # Required-Start:    $remote_fs $syslog
    # Required-Stop:     $remote_fs $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Example initscript
    # Description:       This file should be used to construct scripts to be
    #                    placed in /etc/init.d.  This example start a
    #                    single forking daemon capable of writing a pid
    #                    file.  To get other behavoirs, implemend
    #                    do_start(), do_stop() or other functions to
    #                    override the defaults in /lib/init/init-d-script.
    ### END INIT INFO
    
    # Author: Foo Bar <foobar@baz.org>
    #
    # Please remove the "Author" lines above and replace them
    # with your own name if you copy and modify this script.
    
    DESC="Description of the service"
    DAEMON=/usr/sbin/daemonexecutablename
    

    本文为实操笔记,转载请注明出处 https://www.cnblogs.com/hellxz/p/9441949.html

  • 相关阅读:
    2017年8月27日 星期日 --出埃及记 Exodus 29:6
    2017年8月26日 星期六 --出埃及记 Exodus 29:5
    2017年8月25日 星期五 --出埃及记 Exodus 29:4
    2017年8月24日 星期四 --出埃及记 Exodus 29:3
    2017年8月23日 星期三 --出埃及记 Exodus 29:2
    2017年8月22日 星期二 --出埃及记 Exodus 29:1
    2016年12月总结
    2016年11月总结
    2016年10月总结
    项目风险说明
  • 原文地址:https://www.cnblogs.com/hellxz/p/9441949.html
Copyright © 2011-2022 走看看