ubuntu 开机自动运行 /etc/init.d 目录下的脚本

2023-01-10 20:05:11  浏览:303  作者:yyy

如何在 ubuntu/etc/init.d目录下设置开机自动执行sh文件,方法如下:


  • >>>复制或软连接脚本到/etc/init.d/目录下

  • >>>脚本内容如下,### 开头和结束部分是模板性注释,不能更改,必须存在。

    $cat /etc/init.d/run_php73.sh


    #!/bin/bash


    ### BEGIN INIT INFO

    # Provides:          run_php73.sh        //run_php73.sh是自己创建的脚本名称

    # Required-Start:    $local_fs $network $remote_fs $syslog

    # Required-Stop:     $local_fs $network $remote_fs $syslog

    # Default-Start:     2 3 4 5

    # Default-Stop:      0 1 6

    # Short-De ion: starts the run_php73.sh daemon      //run_php73.sh是自己创建的脚本名称

    # De ion:       starts run_php73.sh using start-stop-daemon     //test.sh是自己创建的脚本名称

    ### END INIT INFO


    #创建PHP-fpm配置文件设定的 php 日志存储目录

    php_run_dir_today="/tmp/log"


    /bin/mkdir -p $php_run_dir_today > /dev/null 2>&1

    #每次服务器开机(测试环境开机 自动启动php73版本)

    /usr/local/php73/sbin/php-fpm



  • >>>赋权限给脚本文件

    chmod 755 /etc/init.d/run_php73.sh


  • >>>加入开机启动

    cd /etc/init.d/    //不切换目录 容易报错:update-rc.d: error: unable to read /etc/init.d//etc/init.d/run_php73.sh                

    update-rc.d run_php73.sh defaults 90    //在ubuntu环境认可的命令


  • >>>重启验证


评论区

共 0 条评论
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~

【随机新闻】

返回顶部