Table of Contents
DokuBot
Features
- reconnects after Netsplit or kick
- reloads configuration files
- restarts itself on changes for database or irc configuration
- supports MSS (Message Storage System)
- implements test function for proper monitoring
- implements proper logging (inlc. debug mode)
- supports different configuration files (e.g. for testing)
MSS (Message Storage System)
This system is designed by Andrwe.
It stores messages addressed to someone in the channel who isn't online anymore in a database.
After reconnecting of the addressed user the message is send to him as private message including the link to irc log website.
It is activated by starting the message with '@Nickname' e.g. @Andrwe.
Currently the messages are only deleted after there were successfully send to the target.
Usage
This script controls an irc logging bot with command support. Available options: -c - config file to use -h - this help -r - reload configurations and reconnects to irc and database if needed -s - start bot -t - check whether the bot is still running -x - stop bot
On the server of dokuwiki a systemd-file exists:
# start bot systemctl start irclog # stop bot systemctl stop irclog # restart bot systemctl restart irclog # reload bot systemctl reload irclog # checks running bot systemctl status irclog
For testing purpose there is irclog-test init-script. It starts a bot using /var/www/irclog/htdocs/test.conf.php as configuration file.
Configuration
Main
There is an example configuration file in the git.
Move that to irclog.config.php within the directory of the bot-script (irclog.pl) and adapt it.
The parameters you have to change are:
- db_host
- db_user
- db_pass
- db_name
- irc_host
- irc_port
- irc_chan
- irc_nick
- irc_name
- irc_pass
- initscript
The parameters you might want to change:
- *_log
- irc_* for automatic messages
Special commands
The file irclog.special.pl
is loaded by the bot and contains the funciton special()
.
This function implements bot commands by checking for commands within the message.
systemd-file
The following systemd.service file controls irclog.
Copy it to /etc/systemd/system/irclog.service
and activate it with systemctl enable irclog
.
- /etc/systemd/system/irclog.service
[Unit] Description=start dokubot for logging IRC messages After=mysql.service [Service] User=irclog Group=irclog Type=forking Restart=no TimeoutSec=5min RemainAfterExit=yes ExecStart=/var/www/irclog/htdocs/irclog.pl -s ExecStop=/var/www/irclog/htdocs/irclog.pl -x ExecReload=/var/www/irclog/htdocs/irclog.pl -r [Install] WantedBy=multi-user.target
Init-script - deprecated
The following can be used to control the bot on Debian systems. Just copy it to /etc/init.d/irclog
.
- /etc/init.d/irclog
#! /bin/sh ### BEGIN INIT INFO # Provides: irclog # Required-Start: $remote_fs # Required-Stop: $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start dokubot (irclogger) # Description: start dokubot for logging IRC messages ### END INIT INFO # Author: dokuwiki.org (Andrwe) PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="IRC logging service" NAME=irclog.pl DAEMON=/var/www/irclog/htdocs/$NAME PIDFILE=/var/run/$NAME.pid # Exit if the package is not installed [ -x "$DAEMON" ] || exit 1 # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh # Define LSB log_* functions. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions # # Function that starts the daemon/service # do_start() { # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started start-stop-daemon --start --quiet -d /var/www/irclog/htdocs -c irclog -b --exec $DAEMON -- -s \ || return 2 } # # Function that stops the daemon/service # do_stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred start-stop-daemon --stop --quiet --name $NAME -- -x RETVAL="$?" [ "$RETVAL" = 2 ] && return 2 return "$RETVAL" } do_reload() { start-stop-daemon --start --quiet -d /var/www/irclog/htdocs -c irclog --exec $DAEMON -- -r \ || return 1 } do_check() { return start-stop-daemon --start --quiet -d /var/www/irclog/htdocs -c irclog --exec $DAEMON -- -t } case "$1" in start) log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0|1) log_end_msg 0 ;; 2) log_end_msg 1 ;; esac ;; stop) log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) log_end_msg 0 ;; 2) log_end_msg 1 ;; esac ;; reload) log_daemon_msg "Reloading $DESC" "$NAME" do_reload case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; check) log_daemon_msg "Checking $DESC" "$NAME" do_check case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 log_daemon_msg "Couldn't run test." "$NAME" ;; 2) log_end_msg 1 log_daemon_msg "Test failed. To fix it you have to restart the bot." "$NAME" ;; 3) log_end_msg 1 log_daemon_msg "Test failed. To fix it you have to restart the bot." "$NAME" ;; *) log_end_msg 1 ;; esac ;; restart) log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) echo "Usage: $0 {start|stop|restart|reload}" >&2 exit 3 ;; esac
TODO
- check for already running process
- increase error checks
- increase error logging
- write help command
- msgstore cleanup
- zabbix monitoring