1 准备文件
1.1myservice-local.service (自启服务的配置)
[Unit]
Description=/etc/myservice.local Compatibility
ConditionFileIsExecutable=/etc/myservice.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/myservice.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no [Install]
WantedBy=multi-user.target
Alias=/etc/myservice.local
[Install]
WantedBy=multi-user.target
Alias=myservice.local
放在 /etc/systemd/system/myservice-local.service
1.2myservice.local (你要执行的脚本)
#!/bin/bash
echo "test" >> /var/myservice.log
exit 0
放在 /etc/myservice.local
2 使能
sudo systemctl enable myservice-local.service