創(chuàng)建一個(gè)服務(wù)
/etc/systemd/system/my-service.service
[Unit]
Description=My custom startup script
# After=network.target
# After=systemd-user-sessions.service
# After=network-online.target
[Service]
# User=spark
# Type=simple
# PIDFile=/run/my-service.pid
ExecStart=/home/qiantao/startup.sh start
# ExecReload=/home/qiantao/startup.sh reload
# ExecStop=/home/qiantao/startup.sh stop
# TimeoutSec=30
# Restart=on-failure
# RestartSec=30
# StartLimitInterval=350
# StartLimitBurst=10
[Install]
WantedBy=multi-user.target
初始化腳本內(nèi)容
/home/qiantao/startup.sh
#!/bin/sh
rm -rf /home/qiantao/.config/bcompare/registry.dat
服務(wù)啟動(dòng)/停止:systemctl start my-service / systemctl stop my-service
.
需要開機(jī)啟動(dòng):systemctl enable my-service
.
$ systemctl enable my-service
Created symlink /etc/systemd/system/multi-user.target.wants/my-service.service → /etc/systemd/system/my-service.service.