https://blog.csdn.net/qq_19004627/article/details/80661468
A 自带开机脚本
/etc/rc.local脚本是一个ubuntu16.04及其以前的系统中自带的开机脚本,在没有修改之前里面内容如下。
[plain] view plain copy
- #!/bin/sh -e
- #
- # rc.local
- #
- # This script is executed at the end of each multiuser runlevel.
- # Make sure that the script will "exit 0" on success or any other
- # value on error.
- #
- # In order to enable or disable this script just change the execution
- # bits.
- #
- # By default this script does nothing.
- exit 0
可以把开机要执行的命令放到 exit0 前面。
B 添加开机脚本
1,新建个脚本文件new_service.sh
[plain] view plain copy
- #!/bin/bash
- # command content
- exit 0
2,设置权限
[plain] view plain copy
- sudo chmod 755 new_service.sh
3,把脚本放置到启动目录下
[plain] view plain copy
- sudo mv new_service.sh /etc/init.d/
4,将脚本添加到启动脚本
执行如下指令,在这里90表明一个优先级,越高表示执行的越晚
[plain] view plain copy
- cd /etc/init.d/
- sudo update-rc.d new_service.sh defaults 90
移除Ubuntu开机脚本
[plain] view plain copy
- sudo update-rc.d -f new_service.sh remove