ubuntu18.04 不再使用initd管理系统,改用systemd
- 设置启动参数
vim /lib/systemd/system/rc.local.service1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
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
Alias=rc-local.service - 添加软链接
1
ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/rc.local.service
- 创建服务
1
touch /etc/rc.local
- 赋可执行权限
1
chmod 755 /etc/rc.local
- 编辑自启动服务
vim /etc/rc.local1
2
3
4#开机打印hello
echo "hello" > /etc/test.log
# 开机启动zookeeper
/usr/local/zookeeper/bin start