ircbot: Restart on failure, do not self-exec if running under systemd

This commit is contained in:
sceox 2023-09-16 14:15:18 -07:00
parent ad4aae50ed
commit d50a1c7c58
2 changed files with 10 additions and 1 deletions

View File

@ -22,7 +22,15 @@ connect() {
echo "PRIVMSG $chan : $joinmsg" >> $inputf echo "PRIVMSG $chan : $joinmsg" >> $inputf
} }
reconnect() { reconnect() {
exec $0 if command -v systemctl >/dev/null; then
# NOTE: systemd is configured to restart the service, so simply dying
# with a non-zero exit code is enough to effectively reconnect.
exit 2
else
# FIXME: We need to make sure we are only running one instance of the
# script at a time. This exec is therefore problematic.
exec $0
fi
} }
delay() { delay() {
while read line while read line

View File

@ -5,6 +5,7 @@ Description=Anarchyplanet IRC Bot
User=nagios User=nagios
Group=nagios Group=nagios
ExecStart=/usr/local/bin/ircbot.sh ExecStart=/usr/local/bin/ircbot.sh
Restart=on-failure
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target