#!/bin/bash # Description: Anubis weighs the soul of incoming HTTP requests # Written by: Eric Hameleers 2021 # Run multiple instances of Anubis by creating a symlink to this script with # a suffix prepended byan underscore. # Examples: # - symlink /etc/rc.d/rc.anubis_alien will run an instance called 'alien' # - the script itself will run a default instance, aka instance == 'default' instance=$(echo $0 |cut -d_ -f2) [ "$instance" == "$0" ] && instance="default" description="Anubis Web AI Firewall ($instance)" pidfile=${pidfile:-/var/run/anubis/${instance}.pid} config=/etc/anubis/${instance}.env command="/usr/bin/anubis" [ ! -x $command ] && exit 99 [ ! -f $config ] && exit 99 || source $config daemon=/usr/bin/daemon command_args="\ -bind ${BIND:-/run/anubis/${instance}.sock -bind-network unix -socket-mode ${SOCKET_MODE:-0770}} \ -metrics-bind ${METRICS_BIND:-/run/anubis/${instance}_metrics.sock -metrics-bind-network unix -socket-mode ${SOCKET_MODE:-0770}} \ -target ${TARGET:-http://localhost:3923} \ -difficulty ${DIFFICULTY:-4} \ ${ANUBIS_OPTS} \ " command_user=${command_user:-anubis} command_group=${command_group:-anubis} RETVAL=0 start() { if [ -e "$pidfile" ]; then echo "$description already started!" else echo -n "Starting $description: " mkdir -p $(dirname $pidfile) chown $command_user:$command_group $(dirname $pidfile) chmod 0770 $(dirname $pidfile) $daemon -S -u $command_user -F $pidfile -- $command $command_args RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/anubis_${instance} echo "- done." fi } stop(){ echo -n "Stopping $description: " kill -TERM $(cat $pidfile) RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/anubis_${instance} echo "- done." } restart(){ stop sleep 1 start } condrestart(){ [ -e /var/lock/subsys/anubis_${instance} ] && restart } status() { pids=$(cat $pidfile 2>/dev/null) if test "$pids" ; then echo "$description is running." ps up $pids else echo "$description is stopped." fi } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status ;; restart) restart ;; condrestart) condrestart ;; *) echo "Usage: $0 {start|stop|status|restart|condrestart}" RETVAL=1 esac exit $RETVAL