-
Notifications
You must be signed in to change notification settings - Fork 0
/
koha-status
executable file
·108 lines (93 loc) · 3.03 KB
/
koha-status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# ------------------------------------------------------------------
# Author: Lennon Mazonde
# GitHub: @grandmaestr
# Title: koha-status
# Description:
# This script checks instance health, returning a 200 OK if the OPAC and Staff URL configured in the Apache configs are alive.
# You can copy and paste this script onto your server and make it executable by running "chmod a+x /path/to/file_name"
# To run the script, simply go to "/path/to/file_name" or if it's in your home directory, run "file_name" in the CLI.
# This script is interactive, so you'll be prompted for input at various stages.
# You can modify or use this script however you like but I'd really appreciate it if you give me a shout out or attribution if you post it elsewhere :)
# ------------------------------------------------------------------
set -e
# set -x
# Script version
VERSION=0.1.0
# Set the name of the script to variable
SCRIPT_NAME="$(basename ${0})"
# ------Help--------------------------------------------------------
Help(){
# Display Help
cat <<EOF
Usage: $SCRIPT_NAME -ihv args
Options:
i - instanceid. The name of the koha instance. One instance id per option.
h - help. Print this help.
v - version. Print the script version.
Example:
To define a new staff or OPAC url for a single instance called "library", run:
$SCRIPT_NAME -i library
For multiple instances, run
$SCRIPT_NAME -i library1 -i library2 ...
EOF
}
# --- Options processing -------------------------------------------
if [ $# == 0 ] ; then
Help
exit 1;
fi
while getopts ":i:vh" optname; do
case "$optname" in
v)
echo "Version $VERSION"
exit 0;
;;
i)
instanceid+=("$OPTARG")
;;
h)
Help
exit 0;
;;
\?)
echo "Unknown option $OPTARG"
Help
exit 0;
;;
:)
echo "Error: you must provide at least one instance name for option -$OPTARG"
exit 0;
;;
*)
echo "Unknown error while processing options"
Help
exit 0;
;;
esac
done
shift $(($OPTIND - 1))
param1=$1
param2=$2
# --- Locks -------------------------------------------------------
LOCK_FILE=/tmp/$SUBJECT.lock
if [ -f "$LOCK_FILE" ]; then
echo "Script is already running"
exit
fi
trap "rm -f $LOCK_FILE" EXIT
touch $LOCK_FILE
# --- Body --------------------------------------------------------
# This script checks if the OPAC and Staff page URLs from your Apache config files are reachable
filename=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 5)
for val in "${instanceid[@]}"; do
sudo sed -n /ServerName/p /etc/apache2/sites-enabled/$val.conf | sed 's/ServerName//g' | sed 's/#//g' | awk '{$1=$1};1' >> /tmp/$filename.txt
done;
echo "Checking the status of Koha instance $val"
while read url
do
curl -LIs https://$url | head -n 1
echo " "
done < <(tr ' ' '\n' < /tmp/$filename.txt)
# Delete temp file
rm /tmp/$filename.txt