创建一个服务
/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
初始化脚本内容
/home/qiantao/startup.sh
#!/bin/sh
rm -rf /home/qiantao/.config/bcompare/registry.dat
服务启动/停止:systemctl start my-service / systemctl stop my-service
.
需要开机启动: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.