ubuntu16.04默认没有rc.local,
就算加上去也不能开机执行,所以我写了一个rc-local.service的服务,让它开机执行rc.local里面的内容。
系统环境 16.04,17.04
###添加rc-local服务
1
|
sudo vim /lib/systemd/system/rc-local.service
|
在里面填写
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
[Install]
WantedBy=multi-user.target
|
然后让它开机启动
1
|
sudo systemctl enable rc-local.service
|
###添加rc.local文件
此时/etc/rc.local里面的代码就可以执行了
例如添加ss开机启动
1
2
3
|
#!/bin/bash
/usr/bin/sslocal -c /etc/ss/config.json -d start
exit 0
|
当然不要忘记给让rc.local设置权限
1
|
sudo chmod +x /etc/rc.local
|