执行文件 /path/x.sh
#!/bin/bash
while true:
do
do something
done
配置文件 /lib/systemd/system/x.service
[Unit]
Description=simple bash script
[Service]
Type=simple
WorkingDirectory=/path/
ExecStart=/bin/bash x.sh
[Install]
WantedBy=multi-user.target
链接
ln -s /lib/systemd/system/x.service /etc/systemd/system/x.service
systemctl daemon-reload
systemctl start x.service
systemctl enable x