From 9ed3fee3b7e6d20a1ef29681eeeff8702603b555 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Thu, 28 Dec 2023 23:28:47 +0000 Subject: [PATCH] Check/restart SIP2 with monit --- installmonit.sh | 2 ++ koha-sip/README | 24 +++++++++++++++++++ koha-sip/checksip.sh | 47 ++++++++++++++++++++++++++++++++++++ koha-sip/restartsip.sh | 54 ++++++++++++++++++++++++++++++++++++++++++ koha-sip/sip.conf | 6 +++++ 5 files changed, 133 insertions(+) create mode 100644 koha-sip/README create mode 100644 koha-sip/checksip.sh create mode 100644 koha-sip/restartsip.sh create mode 100644 koha-sip/sip.conf diff --git a/installmonit.sh b/installmonit.sh index ef031e3..9e21cfa 100755 --- a/installmonit.sh +++ b/installmonit.sh @@ -8,9 +8,11 @@ bashpath=/usr/sbin/ cp ./koha-plack/plack.conf $monitpath/conf.d/plack.conf cp ./koha-zebra/zebra.conf $monitpath/conf.d/zebra.conf cp ./koha-coce/coce.conf $monitpath/conf.d/coce.conf +cp ./koha-sip/sip.conf $monitpath/conf.d/sip.conf cp ./koha-zebra/*.sh $bashpath/ cp ./koha-plack/*.sh $bashpath/ cp ./koha-coce/*.sh $bashpath/ +cp ./koha-sip/*.sh $bashpath/ echo "What mailserver should we send through?" read mailserver diff --git a/koha-sip/README b/koha-sip/README new file mode 100644 index 0000000..21e084e --- /dev/null +++ b/koha-sip/README @@ -0,0 +1,24 @@ +NAME + Koha::Contrib::koha-sip - Monit conf file and bash scripts to monitor and automatically restart failed SIP instances + +VERSION + version 1 + +DESCRIPTION + MONITORING SIP + koha-sip directory contains a Monit .conf file (sip.conf) and two bash scripts (checksip.sh and restartsip.sh). Move the sip.conf into the /etc/monit/conf.d directory and run monit using the following commands: + + sudo su + sudo service monit start + monit start all + + sip.conf will monitor your sip instances using the checksip.sh script. If that script returns a 1 then the restartsip.sh script is run and that starts the appropriate SIP instance + + All output of the monitoring is logged in the /var/log/monit.log + +AUTHOR + Catalyst IT 2023 + + This is free software, licensed under: + the GNU GPL version 3 or later. + diff --git a/koha-sip/checksip.sh b/koha-sip/checksip.sh new file mode 100644 index 0000000..6520956 --- /dev/null +++ b/koha-sip/checksip.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# This file is part of Koha. +# +# Copyright (C) 2023 Catalyst IT +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +set -e + +# include helper functions +if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then + . "/usr/share/koha/bin/koha-functions.sh" +else + echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2 + exit 1; +fi + +declare -a instancearray +for singleinstancename in $(koha-list --sip --enabled) +do + if ! is_sip_running $singleinstancename; then + instancearray+=("false") + else + instancearray+=("true") + fi +done + +sipstatus=0 +for value in "${instancearray[@]}" +do + if [ "$value" == "false" ] ; then + sipstatus=1 + fi +done +echo $sipstatus +exit $sipstatus diff --git a/koha-sip/restartsip.sh b/koha-sip/restartsip.sh new file mode 100644 index 0000000..d9d3ce0 --- /dev/null +++ b/koha-sip/restartsip.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# This file is part of Koha. +# +# Copyright (C) 2023 Catalyst IT +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +set -e + +. /lib/lsb/init-functions + +# Read configuration variable file if it is present +[ -r /etc/default/koha-common ] && . /etc/default/koha-common + +# include helper functions +if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then + . "/usr/share/koha/bin/koha-functions.sh" +else + echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2 + exit 1 +fi + +declare -a sipinstances +for singleinstancename in $(koha-list --sip --enabled) +do + if ! is_sip_running $singleinstancename; then + sipinstances+=" $singleinstancename" + warn "The SIP service for instance $singleinstancename is not running." + else + warn "SIP service is running for this instance $singleinstancename." + fi +done + +if [ ! -z "$sipinstances" ]; +then + for sipinstance in $sipinstances + do + instancename=$sipinstance + run=$(koha-sip --start $instancename) + warn "Starting SIP service for $instancename" + done +fi +exit 0; diff --git a/koha-sip/sip.conf b/koha-sip/sip.conf new file mode 100644 index 0000000..288401b --- /dev/null +++ b/koha-sip/sip.conf @@ -0,0 +1,6 @@ +set logfile /var/log/monit.log +set idfile /var/lib/monit/id +set statefile /var/lib/monit/state + +check program checksip with path /usr/sbin/checksip.sh + if status = 1 then exec "/usr/sbin/restartsip.sh"