Compare commits

...

5 Commits

4 changed files with 16 additions and 4 deletions

View File

@ -10,6 +10,7 @@ SYSTEMD_UNIT_DIR = /lib/systemd/system
rc: install
@echo installing ircbot to /etc/rc.d
@cp -f services/rc/ircbot /etc/rc.d
@chmod 555 /etc/rc.d/ircbot
@echo enabling ircbot
@rcctl enable ircbot
@echo not starting ircbot -- configure it then run `rcctl start ircbot` as root

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
botname=nagiosbot
host=localhost
@ -28,7 +28,8 @@ function delay {
SECONDS=0
echo "NICK $botname
USER $botname 8 * : $botname" | nc -i 1 -q $crit -w $crit $host $port 2>&1 > /dev/null
USER $botname 8 * : $botname
QUIT" | nc -i 1 -w $crit $host $port 2>&1 > /dev/null
exit=$?
if [ ! "$exit" == 0 ]; then
echo "IRCd CRITICAL: $host: connection failed"

View File

@ -8,6 +8,7 @@ if ! test -r $conf; then
echo "cannot read configuration file, exiting"
exit 1
else
# shellcheck source=ircbot.conf.default
. $conf
fi
@ -21,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
@ -46,7 +55,7 @@ loop &
tail -f $inputf | delay | nc $server $port | while read msg
do
echo "$msg" | tee $logf
echo "$msg" | tee -a $logf
case "$msg" in
*'PING'*) echo "$msg" | sed 's/PING/PONG/' >> $inputf
;;

View File

@ -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