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
|
rc: install
|
||||||
@echo installing ircbot to /etc/rc.d
|
@echo installing ircbot to /etc/rc.d
|
||||||
@cp -f services/rc/ircbot /etc/rc.d
|
@cp -f services/rc/ircbot /etc/rc.d
|
||||||
|
@chmod 555 /etc/rc.d/ircbot
|
||||||
@echo enabling ircbot
|
@echo enabling ircbot
|
||||||
@rcctl enable ircbot
|
@rcctl enable ircbot
|
||||||
@echo not starting ircbot -- configure it then run `rcctl start ircbot` as root
|
@echo not starting ircbot -- configure it then run `rcctl start ircbot` as root
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
botname=nagiosbot
|
botname=nagiosbot
|
||||||
host=localhost
|
host=localhost
|
||||||
@ -28,7 +28,8 @@ function delay {
|
|||||||
|
|
||||||
SECONDS=0
|
SECONDS=0
|
||||||
echo "NICK $botname
|
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=$?
|
exit=$?
|
||||||
if [ ! "$exit" == 0 ]; then
|
if [ ! "$exit" == 0 ]; then
|
||||||
echo "IRCd CRITICAL: $host: connection failed"
|
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"
|
echo "cannot read configuration file, exiting"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
# shellcheck source=ircbot.conf.default
|
||||||
. $conf
|
. $conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -21,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
|
||||||
@ -46,7 +55,7 @@ loop &
|
|||||||
|
|
||||||
tail -f $inputf | delay | nc $server $port | while read msg
|
tail -f $inputf | delay | nc $server $port | while read msg
|
||||||
do
|
do
|
||||||
echo "$msg" | tee $logf
|
echo "$msg" | tee -a $logf
|
||||||
case "$msg" in
|
case "$msg" in
|
||||||
*'PING'*) echo "$msg" | sed 's/PING/PONG/' >> $inputf
|
*'PING'*) echo "$msg" | sed 's/PING/PONG/' >> $inputf
|
||||||
;;
|
;;
|
||||||
|
@ -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
|
||||||
|
Reference in New Issue
Block a user