linux系统/etc/init.d目录下的开机自启脚本

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

2.脚本内容如下,加粗内容是模板性注释,不能更改。

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

#!/bin/bash

### BEGIN INIT INFO

# Provides:          test.sh        //test.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-Description: starts the test.sh daemon      //test.sh是自己创建的脚本名称

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

### END INIT INFO

sudo cp /media/share/frp_0.27.0_linux_amd64.tar.gz /opt/        //开机后需要执行的命令

3.赋权限给脚本文件

$sudo chmod 755 /etc/init.d/test.sh

4.加入开机启动

$sudo update-rc.d /etc/init.d/test.sh defaults 90   //在ubuntu环境认可的命令,如果出现update-rc.d: error: unable to read /etc/init.d//etc/init.d/test.sh,请进入到/etc/init.d目录执行update-rc.d的命令。

$sudo chkconfig --add test.sh  && chkconfig test.sh on //在centos环境认可的命令

5.重启验证

结束。

posted @ 2020-06-03 15:20  巴州夜雨  阅读(8331)  评论(0编辑  收藏  举报