Compare commits
5 Commits
5f96921697
...
d50a1c7c58
Author | SHA1 | Date | |
---|---|---|---|
|
d50a1c7c58 | ||
|
ad4aae50ed | ||
|
163808bf97 | ||
|
03c1923e7e | ||
|
a2dbf25076 |
1
Makefile
1
Makefile
@ -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
|
||||
|
@ -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"
|
||||
|
13
ircbot.sh
13
ircbot.sh
@ -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
|
||||
;;
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user