From d50a1c7c58c348fe218fc0f2a9da062d9ae65acb Mon Sep 17 00:00:00 2001 From: sceox Date: Sat, 16 Sep 2023 14:15:18 -0700 Subject: [PATCH] ircbot: Restart on failure, do not self-exec if running under systemd --- ircbot.sh | 10 +++++++++- services/systemd/ircbot.service | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ircbot.sh b/ircbot.sh index 8e46847..893cb3f 100755 --- a/ircbot.sh +++ b/ircbot.sh @@ -22,7 +22,15 @@ connect() { echo "PRIVMSG $chan : $joinmsg" >> $inputf } 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() { while read line diff --git a/services/systemd/ircbot.service b/services/systemd/ircbot.service index bb8fa5c..ed67aee 100644 --- a/services/systemd/ircbot.service +++ b/services/systemd/ircbot.service @@ -5,6 +5,7 @@ Description=Anarchyplanet IRC Bot User=nagios Group=nagios ExecStart=/usr/local/bin/ircbot.sh +Restart=on-failure [Install] WantedBy=multi-user.target