一、新建xx-setpower.service文件
sudo gedit /etc/systemd/system/xx-setpower.service
[Unit]
Description=XX SetPower Service
After=network.target
Wants=network.target
[Service]
Type=simple
PIDFile=/run/take_up_boot.pid
ExecStart=/usr/bin/take_up_boot.sh
Restart=on-failure
# Don't restart in the case of configuration error
RestartPreventExitStatus=23
[Install]
WantedBy=multi-user.target
二、新建take_up_boot.sh
sudo gedit /usr/bin/take_up_boot.sh
注意:要有可执行权限
echo "hello" > /home/xxx/myfile.txt
三、 设置服务开机启动
systemctl daemon-reload
systemctl start xx-setpower.service
systemctl enable xx-setpower.service
四、查看启动任务的情况:
sudo systemctl status xx-setpower.service
更改代码的执行权限
sudo chmod a+x /usr/bin/take_up_boot.sh