我得到了一个bash脚本,基本上运行了这个脚本:
#!/bin/bash
[...]
while true; do
str="broadcast "`randArrayElement "messages[@]"`
server_send_message $str
sleep $interval
done
现在,我要将其作为systemd服务运行,我的服务脚本如下所示:
[Unit]
Description=Announcer
After=network.target
[Service]
ExecStart=/usr/local/bin/somescript &; disown
ExecStop=/usr/bin/kill -9 `cat /tmp/somescript.pid`
Type=forking
PIDFile=/tmp/somescript.pid
[Install]
WantedBy=default.target
不幸的是,当我通过service somescript start
它运行该服务时,但是由于while true循环,我的终端无法启动脚本:
● somescript.service - somescript service
Loaded: loaded (/etc/systemd/system/somescript.service; disabled; vendor preset: enabled)
Active: activating (start) since Wed 2016-08-17 12:22:34 CEST; 43s ago
Control: 17395 (somescript)
CGroup: /system.slice/somescript.service
├─17395 /bin/bash /usr/local/bin/somescript &; disown
└─17409 sleep 600
如何将这个脚本作为服务运行,而不会陷入“开始” / while true循环中?