I want to create a daemon of Telegram-cli (https://github.com/vysheng/tg). I have created the file /etc/systemd/system/telegram.service
with the following contents:
[Service]
Type=simple
KillMode=process
ExecStart=/usr/bin/telegram-daemon
[Install]
WantedBy=default.target
And a file /usr/bin/telegram-daemon
with the following contents:
#!/bin/bash
rm -rf /var/run/telegram.sock
cd /root/tg
bin/telegram-cli -k tg-server.pub -W -s action.lua -S /var/run/telegram.sock > /dev/null 2>&1 &
exit
I can perfectly start this service using systemctl start telegram
, I can enable it using systemctl enable telegram
:
ln -s '/etc/systemd/system/telegram.service' '/etc/systemd/system/default.target.wants/telegram.service'
When I manually start the server and check if telegram is running using ps aux | grep telegram
it is running:
root 2506 0.0 2.2 359208 22632 ? S apr24 1:11 bin/telegram-cli -k tg-server.pub -W -s action.lua -S /var/run/telegram.sock
root 8177 0.0 0.0 112660 964 pts/0 R+ 12:11 0:00 grep --color=auto telegram
However when I reboot, the cli isn't started. The status of the service (systemctl status -l telegram
) is:
telegram.service
Loaded: loaded (/etc/systemd/system/telegram.service; enabled)
Active: inactive (dead) since zo 2015-04-26 12:13:14 UTC; 48s ago
Process: 393 ExecStart=/usr/bin/telegram-daemon (code=exited, status=0/SUCCESS)
Main PID: 393 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/telegram.service
apr 26 12:13:14 vultr.guest systemd[1]: Starting telegram.service...
apr 26 12:13:14 vultr.guest systemd[1]: Started telegram.service.
How can I solve this? Note that I also tried to change the type
to forking
. And I tried to directly run the telegram command from the service. In the latest situatuon systemctl start telegram
keeps running for ever.
Thanks in advance!
P.s. I'm running Centos 7
EDIT: note that starting the service at @reboot via crontab has the same result.