From ee95ca3899a99b415fdc74df919008f1535085f3 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 24 Apr 2017 02:03:55 +0200 Subject: [PATCH 01/45] Update check_dyndns.sh. --- check_dyndns.sh | 184 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 122 insertions(+), 62 deletions(-) diff --git a/check_dyndns.sh b/check_dyndns.sh index c7fdd4a..e094c16 100755 --- a/check_dyndns.sh +++ b/check_dyndns.sh @@ -1,8 +1,25 @@ #!/usr/bin/env bash -PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -function usage() { +#--------------------------------------- +#----------------------------- +# Predifined Variables +#----------------------------- +#--------------------------------------- + +conf_file="/etc/ddclient.conf" +ddclient_script="/usr/sbin/ddclient" + +_SKIP_IP=false + + +#--------------------------------------- +#----------------------------- +# Functions +#----------------------------- +#--------------------------------------- + +usage() { echo @@ -15,93 +32,136 @@ function usage() { } +fatal(){ + echo "" + echo -e " [ Fatal ] $*" + echo "" + echo -e "\tScript terminated.." + echo "" + exit 1 +} +info (){ + echo "" + echo -e " [ Info ] $*" + echo "" +} + +ok (){ + echo "" + echo -e " [ Ok ] $*" + echo "" +} + + +#--------------------------------------- +#----------------------------- +# Evaluate command line +#----------------------------- +#--------------------------------------- + [ $# -eq "0" -o $# -gt "2" ] && usage "wrong number of arguments" DYNDNS_NAME=$1 -_SKIP_IP=false +#--------------------------------------- +#----------------------------- +# Some checks +#----------------------------- +#--------------------------------------- - - -## - only run ddclient, if it is installed -## - -if [ ! -x "/usr/sbin/ddclient" ]; then - exit 0 +# - Only run ddclient, if it is installed +# - +if [[ ! -x "$ddclient_script" ]]; then + fatal "Script '${ddclient_script}' not found!" fi +# - Configuration present? +# - +if [[ ! -f "$conf_file" ]]; then + fatal "ddclient Configuration '${conf_file}' not found!" +fi -if [ -f "/etc/ddclient.conf" ]; then - - ## - read variable "if" from configurationd file "/etc/ddclient.conf" - ## - - eval `sed -n 's/\(if=[^ ,]*\)/\1/p' /etc/ddclient.conf` - - ## - check if interface used by dyndns is present - ## - if [ -n "$if" ];then - for _IFACE in `ifconfig | grep -e"^ppp" | cut -d" " -f1 `; do - if [ "$_IFACE" = $if ];then - PPP_IFACE=$_IFACE - break - fi - done - - ## - exit if no connection for dydns interface exists - ## - - if [ "X" = "X$PPP_IFACE" ]; then - echo "No interface for dydns exists. exiting now.." - exit 0 - fi - - else - _SKIP_IP=true - fi +# - Running on a terminal? +# - +if [[ -t 1 ]] ; then + LOGGING=true else - ## - No configuration file found, so do not run - ## - - echo "No configuration file \"/etc/ddclient.conf\" found, so do not run" - exit 0 + LOGGING=false fi +# - Check, if ddclient uses a local interface (variable "if") +# - +# - if true, interface name will be stored into variable 'if' +# - +eval `sed -n 's/\(if=[^ ,]*\)/\1/p' /etc/ddclient.conf` + +# - Check if interface used by dyndns is present +# +if [ -n "$if" ];then + for _IFACE in `ifconfig | grep -e"^ppp" | cut -d" " -f1 `; do + if [ "$_IFACE" = $if ];then + PPP_IFACE=$_IFACE + break + fi + done + + ## - exit if no connection for dydns interface exists + ## - + if [ "X" = "X$PPP_IFACE" ]; then + fatal "No interface for dydns exists." + fi + +else + _SKIP_IP=true +fi + + +#--------------------------------------- +#----------------------------- +# Update DynDNS IP-Address if needed +#----------------------------- +#--------------------------------------- if ! $_SKIP_IP ; then + PPP_REMOTE=`ifconfig $PPP_IFACE 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1` PPP_LOCAL=`ifconfig $PPP_IFACE 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f2 | cut -d " " -f1` -fi - -if [ "X$PPP_REMOTE" != "X" -a "X$PPP_LOCAL" != "X" ] ; then - - if $_SKIP_IP ; then - - # Load defaults - if [ -f /etc/default/ddclient ]; then - - source /etc/default/ddclient - if [ "$run_daemon" = "true" ]; then - exit 0 - fi - fi - - /usr/sbin/ddclient - - else + if [ "X$PPP_REMOTE" != "X" -a "X$PPP_LOCAL" != "X" ] ; then DYNDNS_IP=`dig $DYNDNS_NAME +short` - #echo "$DYNDNS_NAME: $DYNDNS_IP - Local (PPP) IP: $PPP_LOCAL" if [ "$DYNDNS_IP" != "$PPP_LOCAL" ] ; then - ## - Run ddclient with the IP address of the ppp device - ## - - echo "try to update ipadress entry at dyndns.org.." - echo + # - Run ddclient with the IP address of the ppp device + # - + info "Try to update ip-adress entry at dyndns.org.." /usr/sbin/ddclient -syslog -ip $PPP_LOCAL + else + if $LOGGING ; then + ok "DynDNS IP is up-to-date" + fi fi fi +else + + # - Load defaults + source /etc/default/ddclient + if [ "$run_daemon" = "true" ]; then + if $LOGGING ; then + info "'ddclient' is configured to run as daemon. So nothing to do here." + fi + else + if $LOGGING ; then + info "Going to run '${ddclient_script}'.." + fi + /usr/sbin/ddclient -file $conf_file + fi + fi + exit 0; From cdaa18f23637d7a2df99458d3bee3c9ac7d60e65 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 1 May 2017 14:26:18 +0200 Subject: [PATCH 02/45] Add check_postfix.sh Fix minor error at check_webservice_load.sh --- check_postfix.sh | 152 +++++++++++++++++++++++++++++++++++++++ check_webservice_load.sh | 2 +- 2 files changed, 153 insertions(+), 1 deletion(-) create mode 100755 check_postfix.sh diff --git a/check_postfix.sh b/check_postfix.sh new file mode 100755 index 0000000..3cd878e --- /dev/null +++ b/check_postfix.sh @@ -0,0 +1,152 @@ +#!/usr/bin/env bash + +check_string_ps="" +if [[ -x "/usr/lib/postfix/master" ]] ; then + check_string_ps="/usr/lib/postfix/master" +elif [[ -x "/usr/libexec/postfix/master" ]] ; then + check_string_ps="/usr/libexec/postfix/master" +fi + +postfix_init_script="" +if [[ -x "/etc/init.d/postfix" ]] ; then + postfix_init_script="/etc/init.d/postfix" +fi + +LOCK_DIR=`mktemp -d` + + +#--------------------------------------- +#----------------------------- +# Base Function(s) +#----------------------------- +#--------------------------------------- + +fatal(){ + echo "" + echo -e " [ Fatal ] $*" + echo "" + echo -e "\tScript terminated.." + echo "" + rm -rf $LOCK_DIR + exit 1 +} + +error (){ + echo "" + echo -e " [ Error ] $*" + echo "" +} + +warn (){ + echo "" + echo -e " [ Warn ] $*" + echo "" +} + +info (){ + echo "" + echo -e " [ Info ] $*" + echo "" +} + +ok (){ + echo "" + echo -e " [ Ok ] $*" + echo "" +} + +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + + +#--------------------------------------- +#----------------------------- +# Check some prerequisites +#----------------------------- +#--------------------------------------- + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true + LOGGING=true +else + terminal=false + LOGGING=false +fi + +if [[ -z $check_string_ps ]]; then + fatal "$(basename $0): Postfix seems NOT to be installed" +fi + +# - Systemd supported ? +# - +systemd=$(which systemd) +systemctl=$(which systemctl) + +systemd_supported=false +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +else + if [[ ! -x $postfix_init_script ]]; then + fatal "$(basename $0): Missing Postfix Init-Script!" + fi +fi + + +#--------------------------------------- +#----------------------------- +# Check if Postfix Mailservice is running +#----------------------------- +#--------------------------------------- + +if $LOGGING ; then + echo -e "\n Check if Postfix Mailservice is running.." + echo -e " =========================================" +fi +if ! ps ax | grep -e "\ ${check_string_ps}" | grep -v grep > /dev/null ; then + error "Postfix Mailservice seems to be down! Trying to restart service now.." + + if $systemd_supported ; then + $systemctl stop postfix > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + sleep 10 + $systemctl start postfix > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + else + $postfix_init_script stop > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Stopping Postfix Mailservice failed!" + fi + sleep 10 + $postfix_init_script start > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Starting Postfix Mailservice failed!" + fi + fi + + + if ! ps ax | grep -e "\ ${check_string_ps}" | grep -v grep > /dev/null ; then + error "Restarting Postfix Mailservice failed!" + else + ok "Postfix Mailservice is up and running." + fi + +else + if $LOGGING ; then + ok "Postfix Mailservice is up and running." + fi +fi + +rm -rf $LOCK_DIR +exit 0 + + diff --git a/check_webservice_load.sh b/check_webservice_load.sh index dfae912..9d46226 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -125,7 +125,7 @@ systemd=$(which systemd) systemctl=$(which systemctl) systemd_supported=false -if [[ -n "$systemd" ]] && [[ -n "$systemd" ]] ; then +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then systemd_supported=true fi From 762e6116d9ebbeccb4bfe46a0c5849127406c558 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 17 May 2017 02:07:59 +0200 Subject: [PATCH 03/45] check_dns.sh: redesign check_vpn.sh: redisign check_postfix.sh: Add support for Debian 9 (stretch). --- check_dns.sh | 181 +++++++++++++++++++++++++++++++++++++++++++++-- check_postfix.sh | 19 ++++- check_vpn.sh | 180 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 362 insertions(+), 18 deletions(-) diff --git a/check_dns.sh b/check_dns.sh index c505b85..7e1d155 100755 --- a/check_dns.sh +++ b/check_dns.sh @@ -1,20 +1,187 @@ #!/usr/bin/env bash -PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +check_string_ps="" +if [[ -f "/usr/sbin/named" ]] ; then + check_string_ps="/usr/sbin/named" +fi alternate_addr="oopen.de google.com heise.de debian.org ubuntu.com" + +# - used, if systemd is NOT supported +bind_init_script="" +if [[ -x "/etc/init.d/bind9" ]] ; then + bind_init_script="/etc/init.d/bind9" +fi + +# - Used if systemd is supported +# - +service_name=bind9 + +LOCK_DIR=`mktemp -d` + + +#--------------------------------------- +#----------------------------- +# Base Function(s) +#----------------------------- +#--------------------------------------- + +fatal(){ + echo "" + echo -e " [ Fatal ] $*" + echo "" + echo -e "\tScript terminated.." + echo "" + rm -rf $LOCK_DIR + exit 1 +} + +error (){ + echo "" + echo -e " [ Error ] $*" + echo "" +} + +warn (){ + echo "" + echo -e " [ Warn ] $*" + echo "" +} + +info (){ + echo "" + echo -e " [ Info ] $*" + echo "" +} + +ok (){ + echo "" + echo -e " [ Ok ] $*" + echo "" +} + +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + + +#--------------------------------------- +#----------------------------- +# Check some prerequisites +#----------------------------- +#--------------------------------------- + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true + LOGGING=true +else + terminal=false + LOGGING=false +fi + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true + LOGGING=true +else + terminal=false + LOGGING=false +fi + +if [[ -z $check_string_ps ]]; then + fatal "$(basename $0): Bind Nameservice seems NOT to be installed" +fi + +# - Systemd supported ? +# - +systemd=$(which systemd) +systemctl=$(which systemctl) + +systemd_supported=false +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +else + if [[ ! -x $bind_init_script ]]; then + fatal "$(basename $0): Missing Bind Init-Script!" + fi +fi + + +#--------------------------------------- +#----------------------------- +# Check if Bind Nameservice is running +#----------------------------- +#--------------------------------------- + +if $LOGGING ; then + echo -e "\n Check if Bind Nameservice is running.." + echo -e " ======================================" +fi + for ip_addr in $alternate_addr ; do - ping -c3 $ip_addr >/dev/null 2> /dev/null + ping -c3 $ip_addr >> /dev/null 2>&1 if [ $? -eq 0 ]; then - exit 0 + + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + if [[ "X${PID}" = "X" ]]; then + break + else + + if $LOGGING ; then + ok "Bind Nameservice is up and running." + fi + exit 0 + fi fi done; -/etc/init.d/bind9 restart +error "Bind Nameservice seems to be down! Trying to restart service now.." -echo "" -echo "[ Info ]: Restartet Nameservice bind on host `hostname --long` at `date +\"%d.%m.%Y %H:%M:%S\"`" -echo "" +if $systemd_supported ; then + $systemctl stop $service_name > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + sleep 10 + $systemctl start $service_name > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi +else + $bind_init_script stop > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Stopping Bind Nameservice failed!" + fi + sleep 10 + $bind_init_script start > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Starting Bind Nameservice failed!" + fi +fi + +declare -i counter=0 +PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') +while [[ "X${PID}" = "X" ]]; do + sleep 1 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + if [[ $counter -gt 10 ]]; then + break + else + ((counter++)) + fi +done + +if [[ "X${PID}" = "X" ]] ; then + error "Restarting Bind Nameservice failed!" +else + ok "Bind Nameservice is up and running." +fi exit 0; diff --git a/check_postfix.sh b/check_postfix.sh index 3cd878e..33472a5 100755 --- a/check_postfix.sh +++ b/check_postfix.sh @@ -1,7 +1,9 @@ #!/usr/bin/env bash check_string_ps="" -if [[ -x "/usr/lib/postfix/master" ]] ; then +if [[ -x /usr/lib/postfix/sbin/master ]]; then + check_string_ps="/usr/lib/postfix/sbin/master" +elif [[ -x "/usr/lib/postfix/master" ]] ; then check_string_ps="/usr/lib/postfix/master" elif [[ -x "/usr/libexec/postfix/master" ]] ; then check_string_ps="/usr/libexec/postfix/master" @@ -108,7 +110,7 @@ if $LOGGING ; then echo -e "\n Check if Postfix Mailservice is running.." echo -e " =========================================" fi -if ! ps ax | grep -e "\ ${check_string_ps}" | grep -v grep > /dev/null ; then +if ! ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}" | grep -v grep > /dev/null ; then error "Postfix Mailservice seems to be down! Trying to restart service now.." if $systemd_supported ; then @@ -133,8 +135,19 @@ if ! ps ax | grep -e "\ ${check_string_ps}" | grep -v grep > /dev/null ; then fi fi + declare -i counter=0 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + while [[ "X${PID}" = "X" ]]; do + sleep 1 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + if [[ $counter -gt 10 ]]; then + break + else + ((counter++)) + fi + done - if ! ps ax | grep -e "\ ${check_string_ps}" | grep -v grep > /dev/null ; then + if [[ "X${PID}" = "X" ]] ; then error "Restarting Postfix Mailservice failed!" else ok "Postfix Mailservice is up and running." diff --git a/check_vpn.sh b/check_vpn.sh index 0467e2f..8720c33 100755 --- a/check_vpn.sh +++ b/check_vpn.sh @@ -1,13 +1,177 @@ #!/usr/bin/env bash -PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - -if ! ps ax | grep openvpn | grep -v grep > /dev/null ; then - echo -e "\n\tOpenVPN is not running. so i'm going to (re)start the vpn service..\n" - /etc/init.d/openvpn stop - kill -9 `cat /var/run/openvpn.server.pid 2>/dev/null` > /dev/null 2>&1 - rm -f /var/run/openvpn.server.pid - /etc/init.d/openvpn start +check_string_ps="" +if [[ -f "/usr/sbin/openvpn" ]] ; then + check_string_ps="/usr/sbin/openvpn --daemon" fi + +# - used, if systemd is NOT supported +init_script="" +if [[ -x "/etc/init.d/openvpn" ]] ; then + init_script="/etc/init.d/openvpn" +fi + +# - Used if systemd is supported +# - +service_name=openvpn + +LOCK_DIR=`mktemp -d` + + +#--------------------------------------- +#----------------------------- +# Base Function(s) +#----------------------------- +#--------------------------------------- + +fatal(){ + echo "" + echo -e " [ Fatal ] $*" + echo "" + echo -e "\tScript terminated.." + echo "" + rm -rf $LOCK_DIR + exit 1 +} + +error (){ + echo "" + echo -e " [ Error ] $*" + echo "" +} + +warn (){ + echo "" + echo -e " [ Warn ] $*" + echo "" +} + +info (){ + echo "" + echo -e " [ Info ] $*" + echo "" +} + +ok (){ + echo "" + echo -e " [ Ok ] $*" + echo "" +} + +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + + +#--------------------------------------- +#----------------------------- +# Check some prerequisites +#----------------------------- +#--------------------------------------- + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true + LOGGING=true +else + terminal=false + LOGGING=false +fi + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true + LOGGING=true +else + terminal=false + LOGGING=false +fi + +if [[ -z $check_string_ps ]]; then + fatal "$(basename $0): OpenVPN Service seems NOT to be installed" +fi + +# - Systemd supported ? +# - +systemd=$(which systemd) +systemctl=$(which systemctl) + +systemd_supported=false +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +else + if [[ ! -x $init_script ]]; then + fatal "$(basename $0): Missing Bind Init-Script!" + fi +fi + + +#--------------------------------------- +#----------------------------- +# Check if OpenVPN Service is running +#----------------------------- +#--------------------------------------- + +if $LOGGING ; then + echo -e "\n Check if OpenVPN Service is running.." + echo -e " =====================================" +fi + +PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') +if [[ "X${PID}" = "X" ]]; then + + error "OpenVPN Service seems to be down! Trying to restart service now.." + + if $systemd_supported ; then + $systemctl stop $service_name > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + sleep 10 + $systemctl start $service_name > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + else + $init_script stop > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Stopping OpenVPN Service failed!" + fi + sleep 10 + $init_script start > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Starting OpenVPN Service failed!" + fi + fi + + declare -i counter=0 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + while [[ "X${PID}" = "X" ]]; do + sleep 1 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + if [[ $counter -gt 10 ]]; then + break + else + ((counter++)) + fi + done + + if [[ "X${PID}" = "X" ]] ; then + error "Restarting OpenVPN Service failed!" + else + ok "OpenVPN Service is up and running." + fi + +else + if $LOGGING ; then + ok "OpenVPN Service is up and running." + fi +fi + exit 0; From 24ba503a6f23cfbef1b9c775fd1e46acb767f490 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 17 May 2017 14:56:00 +0200 Subject: [PATCH 04/45] Change ps check string (add a second one). --- check_vpn.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/check_vpn.sh b/check_vpn.sh index 8720c33..cad2980 100755 --- a/check_vpn.sh +++ b/check_vpn.sh @@ -2,9 +2,11 @@ check_string_ps="" if [[ -f "/usr/sbin/openvpn" ]] ; then - check_string_ps="/usr/sbin/openvpn --daemon" + check_string_ps="/usr/sbin/openvpn" fi +check_string_ps_plus="--daemon" + # - used, if systemd is NOT supported init_script="" @@ -123,7 +125,7 @@ if $LOGGING ; then echo -e " =====================================" fi -PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') +PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}" | grep "\ ${check_string_ps_plus}\ " | grep -v grep | awk '{print$2}') if [[ "X${PID}" = "X" ]]; then error "OpenVPN Service seems to be down! Trying to restart service now.." @@ -151,10 +153,10 @@ if [[ "X${PID}" = "X" ]]; then fi declare -i counter=0 - PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}" | grep "\ ${check_string_ps_plus}\ " | grep -v grep | awk '{print$2}') while [[ "X${PID}" = "X" ]]; do sleep 1 - PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}" | grep "\ ${check_string_ps_plus}\ " | grep -v grep | awk '{print$2}') if [[ $counter -gt 10 ]]; then break else From b3761600fa03d9c23ce5e949b1d4de14634a2dea Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 28 Jun 2017 01:15:07 +0200 Subject: [PATCH 05/45] Add clean_up function. Trap signals SIGHUP SIGINT SIGTERM --- check_vpn.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/check_vpn.sh b/check_vpn.sh index cad2980..c06e203 100755 --- a/check_vpn.sh +++ b/check_vpn.sh @@ -27,14 +27,20 @@ LOCK_DIR=`mktemp -d` #----------------------------- #--------------------------------------- +clean_up() { + + # Perform program exit housekeeping + rm rf $LOCK_DIR + exit $1 +} + fatal(){ echo "" echo -e " [ Fatal ] $*" echo "" echo -e "\tScript terminated.." echo "" - rm -rf $LOCK_DIR - exit 1 + clean_up 1 } error (){ @@ -68,6 +74,10 @@ trim() { echo -n "$var" } +# - The trap command allows you to execute a command when a signal +# - is received by your script. +# - +trap clean_up SIGHUP SIGINT SIGTERM #--------------------------------------- #----------------------------- From 1a39e701ad75c8523ba9331a9fb5afc31be4793a Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 28 Jun 2017 01:19:02 +0200 Subject: [PATCH 06/45] Call clean_up function at normal end of script. --- check_vpn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_vpn.sh b/check_vpn.sh index c06e203..36f5137 100755 --- a/check_vpn.sh +++ b/check_vpn.sh @@ -186,4 +186,4 @@ else fi fi -exit 0; +clean_up From fb75b474baf0662af3c0e2506b21df0c0f323f80 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 28 Jun 2017 02:12:25 +0200 Subject: [PATCH 07/45] Fix error in 'clean_up' function. --- check_vpn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_vpn.sh b/check_vpn.sh index 36f5137..9342e4a 100755 --- a/check_vpn.sh +++ b/check_vpn.sh @@ -30,7 +30,7 @@ LOCK_DIR=`mktemp -d` clean_up() { # Perform program exit housekeeping - rm rf $LOCK_DIR + rm -rf $LOCK_DIR exit $1 } From 1bde6f91bc28243defd749fc5900d3d3d4d261cf Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 27 Sep 2017 03:04:07 +0200 Subject: [PATCH 08/45] Add script 'check_remote_websites.sh'. --- .gitignore | 5 +- check_remote_websites.sh | 247 +++++++++++++++++++++++++ conf/check_remote_websites.conf.sample | 58 ++++++ 3 files changed, 308 insertions(+), 2 deletions(-) create mode 100755 check_remote_websites.sh create mode 100644 conf/check_remote_websites.conf.sample diff --git a/.gitignore b/.gitignore index 7c9b3a5..251f61e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -check_webservice_load.conf -BAK/* +*.swl +/conf/*.conf +/BAK/* diff --git a/check_remote_websites.sh b/check_remote_websites.sh new file mode 100755 index 0000000..b92aae7 --- /dev/null +++ b/check_remote_websites.sh @@ -0,0 +1,247 @@ +#!/usr/bin/env bash + + +working_dir="$(dirname $(realpath $0))" +conf_file="${working_dir}/conf/check_remote_websites.conf" + +LOCK_DIR="/tmp/check_remote_websites.LOCK" + +declare -a alert_email_arr + +# ------------- +# --- Read Configurations from $conf_file +# ------------- + +if [[ ! -f "$conf_file" ]]; then + echo "" + echo -e " [ Fatal ] Configuration file '$(basename ${conf_file})' not found!" + echo "" + echo -e "\tScript terminated.." + echo "" + exit 1 +else + source "$conf_file" +fi + +for _email in $alert_email_addresses ; do + alert_email_arr+=("$_email") +done + +[[ -n "$sender_address" ]] || sender_address="check_websites@$(hostname -f)" +[[ -n "$content_type" ]] || content_type='Content-Type: text/plain;\n charset="utf-8"' + +[[ -n "$TIME_OUT" ]] || TIME_OUT=240 +TIME_OUT_MAX="$(expr ${TIME_OUT} + 5)" + + +# ------------- +# - Job is already running? +# ------------- + +# - If job already runs, stop execution.. +# - +if mkdir "$LOCK_DIR" 2> /dev/null ; then + + ## - Remove lockdir when the script finishes, or when it receives a signal + trap clean_up SIGHUP SIGINT SIGTERM + +else + + datum="$(date +"%d.%m.%Y %H:%M")" + + msg="[ Error ]: A previos instance of \"`basename $0`\" seems already be running.\n\n Exiting now.." + + echo "" + echo "[ Error ]: A previos instance of that script \"`basename $0`\" seems already be running." + echo "" + echo -e " Exiting now.." + echo "" + + for _email in ${alert_email_arr[@]} ; do + echo -e "To:${_email}\n${content_type}\nSubject:Error cronjob `basename $0` -- $datum\n${msg}\n" \ + | sendmail -F "Error `hostname -f`" -f $sender_address $_email + done + + exit 1 + +fi + + +# ------------- +# --- Some functions +# ------------- + +clean_up() { + + # Perform program exit housekeeping + rm -rf "$LOCK_DIR" + exit $1 +} + +echononl(){ + if $terminal && $LOGGING ; then + echo X\\c > /tmp/shprompt$$ + if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then + echo -e -n "$*\\c" 1>&2 + else + echo -e -n "$*" 1>&2 + fi + rm /tmp/shprompt$$ + fi +} + +fatal(){ + echo "" + if $terminal ; then + echo -e "[ \033[31m\033[1mError\033[m ]: $*" + echo "" + echo -e "\t\033[31m\033[1mScript was interupted\033[m!" + else + echo " [ Fatal ]: $*" + echo "" + echo " Script was terminated...." + fi + echo "" + clean_up 1 +} + +error (){ + echo "" + if $terminal ; then + echo -e "\t[ \033[31m\033[1mError\033[m ]: $*" + else + echo "[ Error ]: $*" + fi + echo "" +} + +warn (){ + echo "" + if $terminal ; then + echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" + else + echo "[ Warning ]: $*" + fi + echo "" +} + +echo_done() { + if $terminal && $LOGGING ; then + echo -e "\033[75G[ \033[32mdone\033[m ]" + else + if $LOGGING ; then + echo " [ done ]" + fi + fi +} +echo_ok() { + if $terminal && $LOGGING ; then + echo -e "\033[75G[ \033[32mok\033[m ]" + else + if $LOGGING ; then + echo " [ ok ]" + fi + fi +} +echo_failed(){ + if $terminal && $LOGGING ; then + echo -e "\033[75G[ \033[1;31mfailed\033[m ]" + else + if $LOGGING ; then + echo " [ failed ]" + fi + fi +} +echo_skipped() { + if $terminal && $LOGGING ; then + echo -e "\033[75G[ \033[33m\033[1mskipped\033[m ]" + else + if $LOGGING ; then + echo " [ skipped ]" + fi + fi +} + + + + +# ------------- +# --- Check some prerequisites +# ------------- + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true + LOGGING=true +else + terminal=false + LOGGING=false +fi + + +# - Systemd supported ? +# - +systemd=$(which systemd) +systemctl=$(which systemctl) + +systemd_supported=false +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +fi + + +if $LOGGING ; then + echo "" +fi + +if [[ -n "$WEBSITES_TO_CHECK" ]] ; then + for _site in $WEBSITES_TO_CHECK ; do + echononl " Check site \033[1m$_site\033[m .." + response="$(curl --max-time $TIME_OUT --connect-timeout 30 \ + -I -k -L --write-out %{http_code} --silent --output /dev/null $_site 2> ${LOCK_DIR}/err.msg)" + if [[ "$response" -eq 200 ]]; then + echo_ok + else + echo_failed + if [[ -s "$(cat ${LOCK_DIR}/err.msg)" ]] ; then + error "$(cat ${LOCK_DIR}/err.msg)" + fi + websites_failed_arr+=("$_site") + fi + done +else + warn "No Website to check given (empty var 'WEBSITES_TO_CHECK')" +fi + +if [[ ${#websites_failed_arr[@]} -gt 0 ]] ; then + #if [[ ${#websites_failed_arr[@]} -eq 1 ]] ; then + # err_msg="\n[ Error ]: Website ${websites_failed_arr[0]} does NOT respond as exspected\n" + # error "Website ${websites_failed_arr[0]} does NOT respond as exspected" + #else + error "Some Websites does not respond as expected:" + err_msg="\n[ Error ]: Some Websites does not respond as expected:\n\n" + for _site in ${websites_failed_arr[@]} ; do + err_msg+=" $_site\n" + if $LOGGING ; then + echo -e "\t \033[1m$_site\033[m" + #echo -e "\n\tWebsite \033[1m$_site\033[m does NOT respond as exspected" + else + echo " $_site" + fi + done + #fi + + datum="$(date +"%d.%m.%Y %H:%M")" + for _email in ${alert_email_arr[@]} ; do + echo -e "To:${_email}\n${content_type}\nSubject:Error: Website(s) not reachable - ${datum}\n$err_msg" \ + | /usr/sbin/sendmail -F "$company - Check Websites" -f $sender_address $_email + done +fi + +if $LOGGING ; then + echo "" +fi +clean_up 0 + +#curl --max-time 35 --connect-timeout 30 -L --write-out %{http_code} --silent --output /dev/null https:/ats.warenform.de diff --git a/conf/check_remote_websites.conf.sample b/conf/check_remote_websites.conf.sample new file mode 100644 index 0000000..5e00e25 --- /dev/null +++ b/conf/check_remote_websites.conf.sample @@ -0,0 +1,58 @@ +#--------------------------------------- +#----------------------------- +# Settings for script check_remote_websites.sh +#----------------------------- +#--------------------------------------- + +# - WEBSITES_TO_CHECK +# - +# - Contains a list of websites, whichn will be checked +# - +# - blank seperated list of URLs +# - +# - Example: WEBSITES_TO_CHECK=" +# - https://webmail.oopen.de +# - https://webmail.initiativenserver.de +# - https://webmail.interventionistische-linke.org +# - http://www.oopen.de" +# - +WEBSITES_TO_CHECK="" + +# - TIME_OUT +# - +# - Timeout for curl request of each website +# - +# - Defaults to: TIME_OUT=240 +# - +#TIME_OUT=240 + + +# --- +# - E-Mail settings for sending script messages +# --- + +# - company +# - +# - Example: company="O.OPEN" +# - +company="" + +# - sender_address +# - +# - Defaults to: sender_address="root@$(hostname -f)" +# - +#sender_address="check_websites@$(hostname -f)" + +# - content_type +# - +# - Defaults to: content_type='Content-Type: text/plain;\n charset="utf-8"' +# - +#content_type='Content-Type: text/plain;\n charset="utf-8"' + +# - alert_email_addresses +# - +# - blank separated list of e-mail addresses +# +# - Example: alert_email_addresses="ckubu@oopen.de axel@warenform.net" +# - +alert_email_addresses="" From e1ecfa5fd47fe812b754c9b9e25217f4d06f20b9 Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 24 Oct 2017 15:59:04 +0200 Subject: [PATCH 09/45] check_postfix.sh: add 'systemctl 'daemon reload' befor restarting postfix service. Its a workaround! --- check_postfix.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/check_postfix.sh b/check_postfix.sh index 33472a5..62dd085 100755 --- a/check_postfix.sh +++ b/check_postfix.sh @@ -114,6 +114,11 @@ if ! ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}" | grep -v grep > /dev/n error "Postfix Mailservice seems to be down! Trying to restart service now.." if $systemd_supported ; then + $systemctl daemon-reload > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + sleep 2 $systemctl stop postfix > /dev/null 2> ${LOCK_DIR}/err_msg.log if [[ $? -ne 0 ]]; then error "$(cat ${LOCK_DIR}/err_msg.log)" From 1a2b5dca453bc156f4611dc523a5e542e295c29f Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 30 Nov 2017 17:29:38 +0100 Subject: [PATCH 10/45] check_webservice_load.sh: MySQL: Check not only against Pid of '' (mysqld_safe), also check against Pid of '' (mysqld). --- check_webservice_load.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index 9d46226..4a6717f 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -500,7 +500,7 @@ stop_mysql() { kill -9 $_PID > /dev/null 2>&1 done sleep 2 - PIDS=i$(ps aux | grep "$MYSQLD" | grep -v grep | awk '{print$2}') + PIDS=$(ps aux | grep "$MYSQLD" | grep -v grep | awk '{print$2}') i=i+1 done @@ -643,6 +643,10 @@ start_mysql() { NEWPID=$(ps aux | grep "$MYSQLD_SAFE" | grep -v grep | grep root | awk '{print$2}') + if [[ -z "$NEWPID" ]]; then + NEWPID=$(ps aux | grep "$MYSQLD" | grep -v grep | awk '{print$2}') + fi + if [ "X${NEWPID}X" = "XX" ]; then echo "" >> $LOCK_DIR/extra_msg.txt @@ -1064,6 +1068,10 @@ if $check_mysql ; then PID=`ps aux | grep "$MYSQLD_SAFE" | grep -v grep | awk '{print$2}'` + if [[ -z "$PID" ]] ; then + PID=`ps aux | grep "$MYSQLD" | grep -v grep | awk '{print$2}'` + fi + if [ "X${PID}X" = "XX" ];then echo -e "\nMySQL is not running! - Try to start it.." >> $LOCK_DIR/extra_msg.txt From 5bd4f7fef540d11b8796c14af72899395768a662 Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 15 Dec 2017 12:03:07 +0100 Subject: [PATCH 11/45] check_amavis.pl: some minor changes in script output. --- check_amavis.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check_amavis.pl b/check_amavis.pl index 1797bd9..2aba967 100755 --- a/check_amavis.pl +++ b/check_amavis.pl @@ -93,8 +93,8 @@ if ($result =~/2.7.[01] Ok, discarded/) { exit $STATES{OK}; } else { print "[ Warning ]: Respond of amavisd-new service is not as expected !\n"; - print " amavisd-new returned:\n $result\n"; - print "\n\nRestart Service amavisd-new now.."; + print " amavisd-new returned:\n $result\n\n"; + print "\n\nRestart Service amavisd-new now..\n"; # - Restart Service amavisd-new # - From 50b01f734a6a6ba115a63a0f4800cb4c0b4ab4da Mon Sep 17 00:00:00 2001 From: Christoph Date: Thu, 28 Dec 2017 11:13:56 +0100 Subject: [PATCH 12/45] check_webservice_load.sh: add support for apache2 systemd service. --- check_webservice_load.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index 4a6717f..362cf35 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -184,13 +184,22 @@ if $check_apache ; then fi fi + APACHE_SYSTEMD_SERVICE_EXISTS=false + if $systemd_supported ; then + if $(locate apache2.service > /dev/null 2>&1) ; then + APACHE_SYSTEMD_SERVICE_EXISTS=true + fi + fi + APACHE_INIT_SCRIPT="" if [ -x "/etc/init.d/apache2" ]; then APACHE_INIT_SCRIPT="/etc/init.d/apache2" elif [ -x "/etc/init.d/apachectl" ]; then APACHE_INIT_SCRIPT="/etc/init.d/apachectl" - else - fatal 'Cannot find init-script for Apache web server!' + fi + + if [[ -z "$APACHE_INIT_SCRIPT" ]] && ! $APACHE_SYSTEMD_SERVICE_EXISTS ; then + fatal 'Neither an init-script nor a service file for apache2 found!' fi fi @@ -363,7 +372,11 @@ stop_apache() { ## - Stop Apache Webservice ## - - $APACHE_INIT_SCRIPT stop > /dev/null 2>&1 + if $APACHE_SYSTEMD_SERVICE_EXISTS ; then + systemctl stop apache2 > /dev/null 2>&1 + else + $APACHE_INIT_SCRIPT stop > /dev/null 2>&1 + fi sleep 12 @@ -691,7 +704,14 @@ start_apache() { send_msg=$1 send_msg=${send_msg:=true} - $APACHE_INIT_SCRIPT start > /dev/null 2>&1 + + ## - Start Apache Webservice + ## - + if $APACHE_SYSTEMD_SERVICE_EXISTS ; then + systemctl start apache2 > /dev/null 2>&1 + else + $APACHE_INIT_SCRIPT start > /dev/null 2>&1 + fi sleep 2 NEWPID=$(ps aux | grep "$HTTPD" | grep -v grep | grep root | awk '{print$2}') From ba0d11c728ef813a2ace942d601d2671c5f520cd Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 2 Jan 2018 14:25:20 +0100 Subject: [PATCH 13/45] Redesign scrpt. --- check_samba4_service.sh | 271 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 248 insertions(+), 23 deletions(-) diff --git a/check_samba4_service.sh b/check_samba4_service.sh index 2a57f9f..d2e2542 100755 --- a/check_samba4_service.sh +++ b/check_samba4_service.sh @@ -1,28 +1,253 @@ -#"!/usr/bin/env bash +#!/usr/bin/env bash -PIDS=`ps aux | grep "/usr/local/samba/sbin/samba" | grep -v grep | awk '{print$2}'` +working_dir="$(dirname $(realpath $0))" + + +# ------------- +# - Some Variables +# ------------- + +LOCK_DIR="/tmp/$(basename $0).LOCK" + + +# ------------- +# - Job is already running? +# ------------- + +# - If job already runs, stop execution.. +# - +if mkdir "$LOCK_DIR" 2> /dev/null ; then + + ## - Remove lockdir when the script finishes, or when it receives a signal + trap clean_up SIGHUP SIGINT SIGTERM + +else + + datum="$(date +"%d.%m.%Y %H:%M")" + + msg="[ Error ]: A previos instance of \"`basename $0`\" seems already be running.\n\n Exiting now.." + + echo "" + echo "[ Error ]: A previos instance of that script \"`basename $0`\" seems already be running." + echo "" + echo -e " Exiting now.." + echo "" + + for _email in ${alert_email_arr[@]} ; do + echo -e "To:${_email}\n${content_type}\nSubject:Error cronjob `basename $0` -- $datum\n${msg}\n" \ + | sendmail -F "Error `hostname -f`" -f $sender_address $_email + done + + exit 1 -if [ "X${PIDS}X" = "XX" ];then - echo -e "\n[Error]: Samba Service seems to be down. Try to (re)start .." - /etc/init.d/samba4 stop > /dev/null 2>&1 - /etc/init.d/samba4 start > /dev/null - sleep 2 - NEW_PIDS=`ps aux | grep "/usr/local/samba/sbin/samba" | grep -v grep | awk '{print$2}'` - if [ "X${NEW_PIDS}X" = "XX" ]; then - echo -e "" - echo -e "\t[Error]: Restarting samba services failed !!" - echo -e "\n\t[Error]: Restarting samba services failed !!\n" - echo -e "" - else - PIDS="" - for pid in $NEW_PIDS ; do - PIDS="$PIDS $pid" - done - echo -e - echo -e "\tI have restarted the samba services. The new PIDs are $PIDS" - echo -e - fi fi -exit 0 + +# ------------- +# - Some functions +# ------------- + +clean_up() { + + # Perform program exit housekeeping + rm -rf "$LOCK_DIR" + exit $1 +} + +echononl(){ + if $terminal ; then + echo X\\c > /tmp/shprompt$$ + if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then + echo -e -n "$*\\c" 1>&2 + else + echo -e -n "$*" 1>&2 + fi + rm /tmp/shprompt$$ + fi +} + +fatal(){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ]: $*" + echo "" + echo -e " \033[31m\033[1mScript was interupted\033[m!" + else + echo " [ Fatal ]: $*" + echo "" + echo " Script was terminated...." + fi + echo "" + clean_up 1 +} + +error (){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ]: $*" + else + echo "[ Error ]: $*" + fi + echo "" +} + +warn (){ + echo "" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarning\033[m ]: $*" + else + echo "[ Warning ]: $*" + fi + echo "" +} + +info (){ + if $terminal ; then + echo "" + echo -e " [ \033[32m\033[1mInfo\033[m ]: $*" + echo "" + fi +} + +echo_done() { + if $terminal && $LOGGING ; then + echo -e "\033[75G[ \033[32mdone\033[m ]" + fi +} +echo_failed(){ + if $terminal && $LOGGING ; then + echo -e "\033[75G[ \033[1;31mfailed\033[m ]" + fi +} +echo_skipped() { + if $terminal && $LOGGING ; then + echo -e "\033[75G[ \033[33m\033[1mskipped\033[m ]" + fi +} + + +# ------------- +# - Check some prerequisites +# ------------- + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true +else + terminal=false +fi + +# - Systemd supported ? +# - +systemd=$(which systemd) +systemctl=$(which systemctl) + +systemd_supported=false +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +fi + +check_string_ps="(sbin/smbd | sbin/samba )" + +# - Check How to start/stop service +# - +SYSTEMD_UNIT_FILE="" +SYSY_INIT_SCRIPT="" +if $systemd_supported ; then + SYSTEMD_UNIT_FILE="$(systemctl list-unit-files | grep -E "samba[^@]*\.service" | grep "enabled" | cut -d' ' -f1)" +fi + +if [[ -z "$SYSTEMD_UNIT_FILE" ]]; then + SYSY_INIT_SCRIPT="$(service --status-all | awk '{print$4}' | grep samba | head -1)" +fi + +if [[ -z "$SYSTEMD_UNIT_FILE" ]] && [[ -z "$SYSY_INIT_SCRIPT" ]] ; then + fatal 'Neither an init-script nor a service file for samba service found!' +fi + + +# ------------- +# - Main Part of Script +# ------------- + +if $terminal ; then + echo -e "\n Check if Samba Service is running.." + echo -e " ===================================" +fi + +PIDS="$(ps ax | grep -E "$check_string_ps" | grep -v grep | awk '{print$1}')" + +if [[ -z "$PIDS" ]];then + + error "Samba Service seems to be down. Try to (re)start .." + + echononl "Stop Samba Service first .." + if [[ -n "$SYSTEMD_UNIT_FILE" ]] ; then + systemctl stop $SYSTEMD_UNIT_FILE > /dev/null 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + fi + else + /etc/init.d/$SYSY_INIT_SCRIPT stop > /dev/null 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + fi + fi + + sleep 2 + + echononl "Start Samba Service .." + if [[ -n "$SYSTEMD_UNIT_FILE" ]] ; then + systemctl start $SYSTEMD_UNIT_FILE > /dev/null 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + fi + else + /etc/init.d/$SYSY_INIT_SCRIPT start > /dev/null 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + fi + fi + + + declare -i count=0 + + while [[ $count -lt 10 ]] && [[ -z "${PIDS}" ]]; do + sleep 1 + PIDS="$(ps ax | grep -E "$check_string_ps" | grep -v grep | awk '{print$1}')" + ((count++)) + done + + if [[ -z "${PIDS}" ]] ; then + error "Restarting Samba Service failed" + else + + NEW_PIDS="" + for _pid in $NEW_PIDS ; do + NEW_PIDS="$PIDS $_pid" + done + + info "the new PIDs are $NEW_PIDS" + + echo "" + echo " Samba Service was restarted and is now up and running." + echo " The new PIDs are $NEW_PIDS" + echo "" + + fi + +else + info "Samba Service is up and running." +fi + +clean_up 0 From e9fdd42ce675c9c2cf9c8709d1cf0b28c35d6498 Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 2 Jan 2018 14:49:03 +0100 Subject: [PATCH 14/45] Fix some minor error at script output. --- check_samba4_service.sh | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/check_samba4_service.sh b/check_samba4_service.sh index d2e2542..f91d328 100755 --- a/check_samba4_service.sh +++ b/check_samba4_service.sh @@ -110,7 +110,7 @@ info (){ } echo_done() { - if $terminal && $LOGGING ; then + if $terminal ; then echo -e "\033[75G[ \033[32mdone\033[m ]" fi } @@ -182,18 +182,18 @@ if [[ -z "$PIDS" ]];then error "Samba Service seems to be down. Try to (re)start .." - echononl "Stop Samba Service first .." + echononl " Stop Samba Service first .." if [[ -n "$SYSTEMD_UNIT_FILE" ]] ; then systemctl stop $SYSTEMD_UNIT_FILE > /dev/null 2>&1 if [[ $? -eq 0 ]] ; then - echo_ok + echo_done else echo_failed fi else /etc/init.d/$SYSY_INIT_SCRIPT stop > /dev/null 2>&1 if [[ $? -eq 0 ]] ; then - echo_ok + echo_done else echo_failed fi @@ -201,18 +201,18 @@ if [[ -z "$PIDS" ]];then sleep 2 - echononl "Start Samba Service .." + echononl " Start Samba Service .." if [[ -n "$SYSTEMD_UNIT_FILE" ]] ; then systemctl start $SYSTEMD_UNIT_FILE > /dev/null 2>&1 if [[ $? -eq 0 ]] ; then - echo_ok + echo_done else echo_failed fi else /etc/init.d/$SYSY_INIT_SCRIPT start > /dev/null 2>&1 if [[ $? -eq 0 ]] ; then - echo_ok + echo_done else echo_failed fi @@ -232,15 +232,21 @@ if [[ -z "$PIDS" ]];then else NEW_PIDS="" - for _pid in $NEW_PIDS ; do - NEW_PIDS="$PIDS $_pid" + count=0 + for _pid in $PIDS ; do + if [[ $count -eq 1 ]] ; then + NEW_PIDS="$_pid" + else + NEW_PIDS="$NEW_PIDS $_pid" + fi + ((count++)) done info "the new PIDs are $NEW_PIDS" echo "" - echo " Samba Service was restarted and is now up and running." - echo " The new PIDs are $NEW_PIDS" + echo "[ Success ]: Samba Service was restarted and is now up and running." + echo " The new PIDs are $NEW_PIDS" echo "" fi From 569cde854e0d5e35160e4f148b45b6e565efab55 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 8 Jan 2018 21:20:06 +0100 Subject: [PATCH 15/45] check_webservice_load.sh: added support for mysql systemd service file. --- check_webservice_load.sh | 140 +++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 73 deletions(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index 362cf35..abd3bcf 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -141,12 +141,51 @@ if $check_mysql ; then fi fi - MYSQLD_SAFE=`realpath $(which mysqld_safe) 2>/dev/null` - if [ -z "$MYSQLD_SAFE" ]; then - if [ -x "/usr/local/mysql/bin/mysqld_safe" ]; then - MYSQLD_SAFE=`realpath "/usr/local/mysql/bin/mysqld_safe"` - else - fatal 'Command \"mysqld_safe\" not found!' + MYSQL_INIT_SCRIPT="" + MYSQLD_SERVICE_FILE="" + if $systemd_supported ; then + # - Is Service exclusive controlled by systemd + # - + if systemctl -t service list-unit-files \ + | grep -e "^mysql" \ + | grep -q enabled 2> /devnull ; then + + MYSQLD_SERVICE_FILE=$(systemctl -t service list-unit-files \ + | grep -e "^mysql" \ + | awk '{print$1}') + fi + + fi + + if [[ -z "$MYSQLD_SERVICE_FILE" ]] ; then + if [ -x "$(realpath /etc/init.d/mysql.server)" ]; then + MYSQL_INIT_SCRIPT="/etc/init.d/mysql.server" + elif [ -x "$(realpath /etc/init.d/mysql)" ]; then + MYSQL_INIT_SCRIPT="/etc/init.d/mysql" + fi + fi + + if [[ -z "$MYSQL_INIT_SCRIPT" ]] && [[ -z "$MYSQLD_SERVICE_FILE" ]]; then + fatal 'Neither an init-script nor a service file for MySQL found!' + elif [[ -n "$MYSQL_INIT_SCRIPT" ]] ; then + MYSQL_PS_CHECK_STRING="$(dirname "$MYSQLD")/(mysqld_safe |$(basename "$MYSQLD") )" + #MYSQL_PS_CHECK_STRING="(bin/mysqld_safe |bin/mysqld )" + else + MYSQL_PS_CHECK_STRING="$MYSQLD" + fi + + if [[ -z "$MYSQL_PS_CHECK_STRING" ]]; then + fatal "Cannot determin a check string for output of command 'ps ax'" + fi + + if [[ -n "$MYSQL_INIT_SCRIPT" ]] ; then + MYSQLD_SAFE=`realpath $(which mysqld_safe) 2>/dev/null` + if [ -z "$MYSQLD_SAFE" ]; then + if [ -x "/usr/local/mysql/bin/mysqld_safe" ]; then + MYSQLD_SAFE=`realpath "/usr/local/mysql/bin/mysqld_safe"` + else + fatal 'Command \"mysqld_safe\" not found!' + fi fi fi @@ -159,15 +198,6 @@ if $check_mysql ; then fi fi - MYSQL_INIT_SCRIPT="" - if [ -x "/etc/init.d/mysql.server" ]; then - MYSQL_INIT_SCRIPT="/etc/init.d/mysql.server" - elif [ -x "/etc/init.d/mysql" ]; then - MYSQL_INIT_SCRIPT="/etc/init.d/mysql" - else - fatal 'Cannot find init-script for MySQL server!' - fi - fi if $check_apache ; then @@ -437,14 +467,18 @@ stop_mysql() { ## - Stop MySQL Service ## - - $MYSQL_INIT_SCRIPT stop > /dev/null 2>&1 + if [[ -n "$MYSQL_INIT_SCRIPT" ]]; then + $MYSQL_INIT_SCRIPT stop > /dev/null 2>&1 + else + systemctl stop "$MYSQLD_SERVICE_FILE" > /dev/null 2>&1 + fi _msg=false - sleep 2 + sleep 5 declare -i i=0 - PIDS=$(ps aux | grep "$MYSQLD_SAFE" | grep -v grep | awk '{print$2}') + PIDS="$(ps aux | grep -E "${MYSQL_PS_CHECK_STRING}" | grep -v grep | awk '{print$2}')" while [ "X$PIDS" != "X" ]; do if [ $i -eq 0 ]; then @@ -458,13 +492,13 @@ stop_mysql() { info "Going to kill MySQL Processes (mysqld_safe).." fi - if [ $i -gt 20 ]; then + if [ $i -gt 10 ]; then echo "" >> $LOCK_DIR/extra_msg.txt - echo -e "\t[ Error ]: Killing MySQL Processes (mysqld_safe) failed !!!" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Error ]: Killing MySQL Processes failed !!!" >> $LOCK_DIR/extra_msg.txt echo "" >> $LOCK_DIR/extra_msg.txt - error "Killing MySQL Processes (mysqld_safe) failed !!!" + error "Killing MySQL Processes failed !!!" _msg=true @@ -472,52 +506,15 @@ stop_mysql() { fi for _PID in $PIDS ; do - kill -9 $_PID > /dev/null 2>&1 + kill -15 $_PID > /dev/null 2>&1 done - sleep 2 + sleep 5 - PIDS=$(ps aux | grep "$MYSQLD_SAFE" | grep -v grep | awk '{print$2}') + PIDS="$(ps aux | grep -E "${MYSQL_PS_CHECK_STRING}" | grep -v grep | awk '{print$2}')" i=i+1 done - PIDS=$(ps aux | grep "$MYSQLD" | grep -v grep | awk '{print$2}') - declare -i i=0 - while [ "X$PIDS" != "X" ]; do - - if [ $i -eq 0 ]; then - echo "" >> $LOCK_DIR/extra_msg.txt - echo -e "\t[ Error ]: MySQL Processes (mysqld) still exists !!!" >> $LOCK_DIR/extra_msg.txt - echo "" >> $LOCK_DIR/extra_msg.txt - echo -e "\t[ Info ]; Going to kill remaining MySQL Processes (mysqld).." >> $LOCK_DIR/extra_msg.txt - echo "" >> $LOCK_DIR/extra_msg.txt - - error "MySQL Processes (mysqld) still exists !!!" - info "Going to kill remaining MySQL Processes (mysqld).." - fi - - if [ $i -gt 20 ]; then - - echo "" >> $LOCK_DIR/extra_msg.txt - echo -e "\t[ Error ]: Killing remaining MySQL Processes (mysqld) failed !!!" >> $LOCK_DIR/extra_msg.txt - echo "" >> $LOCK_DIR/extra_msg.txt - - error "Killing remaining MySQL Processes (mysqld) failed !!!" - - _msg=true - - break - fi - - for _PID in $PIDS ; do - kill -9 $_PID > /dev/null 2>&1 - done - sleep 2 - PIDS=$(ps aux | grep "$MYSQLD" | grep -v grep | awk '{print$2}') - i=i+1 - - done - if $send_msg && $_msg ; then subject="[ Error ]: Stopping MySQL Engine on `hostname -f` failed -- $datum" msg="\n\n`cat $LOCK_DIR/extra_msg.txt`\n" @@ -651,15 +648,16 @@ start_mysql() { send_msg=$1 send_msg=${send_msg:=true} - $MYSQL_INIT_SCRIPT start > /dev/null 2>&1 - sleep 2 - - NEWPID=$(ps aux | grep "$MYSQLD_SAFE" | grep -v grep | grep root | awk '{print$2}') - - if [[ -z "$NEWPID" ]]; then - NEWPID=$(ps aux | grep "$MYSQLD" | grep -v grep | awk '{print$2}') + if [[ -n "$MYSQL_INIT_SCRIPT" ]]; then + $MYSQL_INIT_SCRIPT start > /dev/null 2>&1 + else + systemctl start "$MYSQLD_SERVICE_FILE" > /dev/null 2>&1 fi + sleep 5 + + NEWPID="$(ps aux | grep -E "${MYSQL_PS_CHECK_STRING}" | grep -v grep | awk '{print$2}' | head -1) " + if [ "X${NEWPID}X" = "XX" ]; then echo "" >> $LOCK_DIR/extra_msg.txt @@ -1086,11 +1084,7 @@ if $check_mysql ; then echo -e "\nChecking Mysql databse service on \"`hostname -f`\".." fi - PID=`ps aux | grep "$MYSQLD_SAFE" | grep -v grep | awk '{print$2}'` - - if [[ -z "$PID" ]] ; then - PID=`ps aux | grep "$MYSQLD" | grep -v grep | awk '{print$2}'` - fi + PID="$(ps aux | grep -E "${MYSQL_PS_CHECK_STRING}" | grep -v grep | awk '{print$2}')" if [ "X${PID}X" = "XX" ];then From 0d81eb18c8bc032c60e372228393e77f2cc572ff Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 10 Jan 2018 04:27:15 +0100 Subject: [PATCH 16/45] Replace script 'check_zombies_php-cgi.sh' by 'clean_up_from_zombies.sh'. --- .../check_zombies_php-cgi.sh | 0 clean_up_from_zombies.sh | 240 ++++++++++++++++++ 2 files changed, 240 insertions(+) rename check_zombies_php-cgi.sh => OLD/check_zombies_php-cgi.sh (100%) create mode 100755 clean_up_from_zombies.sh diff --git a/check_zombies_php-cgi.sh b/OLD/check_zombies_php-cgi.sh similarity index 100% rename from check_zombies_php-cgi.sh rename to OLD/check_zombies_php-cgi.sh diff --git a/clean_up_from_zombies.sh b/clean_up_from_zombies.sh new file mode 100755 index 0000000..fc16341 --- /dev/null +++ b/clean_up_from_zombies.sh @@ -0,0 +1,240 @@ +#!/usr/bin/env bash + +working_dir="$(dirname $(realpath $0))" + +# ------------- +# - Some Variables +# ------------- + +LOCK_DIR="/tmp/$(basename $0).LOCK" + +KILL_SIGNAL=HUP + +CHECK_COMMANDS="$*" + + +# ------------- +# - Some functions +# ------------- + +usage() { + + + [[ -n "$1" ]] && error "$1" + + + [[ $terminal ]] && echo -e " +\033[1mUsage:\033[m + + $(basename $0) COMMAND [COMMAND] .. + +\033[1mDescription\033[m + + Searches for zombie (defunct) child prozesses from given command(s). If such + processes exists, the script tries to kill them by sending a HUP signal to + the parent process. + + At least one command as a cammand line option must be gicen. + +\033[1mExample:\033[m + + Search for (and delete) defunct child prozesses of parent '/usr/local/php/bin/php-cgi' + + $(basename $0) /usr/local/php/bin/php-cgi + + Search for (and delete) defunct child prozesses of parent processes + '/usr/local/sympa/bin/sympa_msg.pl' and '/usr/local/sympa/bin/bulk.pl' + + $(basename $0) /usr/local/sympa/bin/sympa_msg.pl /usr/local/sympa/bin/bulk.pl + +" + + clean_up 1 + +} + +clean_up() { + + # Perform program exit housekeeping + rm -rf "$LOCK_DIR" + exit $1 +} + +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + +fatal(){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ]: $*" + echo "" + echo -e " \033[31m\033[1mScript was interupted\033[m!" + else + echo "[ Fatal ]: $*" + echo "" + echo " Script was terminated...." + fi + echo "" + clean_up 1 +} + +error (){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ]: $*" + else + echo "[ Error ]: $*" + fi + echo "" +} + +warn (){ + echo "" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarning\033[m ]: $*" + else + echo "[ Warning ]: $*" + fi + echo "" +} + +info (){ + echo "" + if $terminal ; then + echo -e " [ \033[32m\033[1mInfo\033[m ]: $*" + else + echo "[ Info ]: $*" + fi + echo "" +} +info_terminal (){ + if $terminal ; then + echo "" + echo -e " [ \033[32m\033[1mInfo\033[m ]: $*" + echo "" + fi +} + +ok (){ + echo "" + if $terminal ; then + echo -e " [ \033[32m\033[1mOk\033[m ]: $*" + else + echo "[ Ok ]: $*" + fi + echo "" +} + + +# ------------- +# - Check some prerequisites +# ------------- + +# - Is this script running on terminal ? +# - +if [[ -t 1 ]] ; then + terminal=true +else + terminal=false +fi + + +# - Print help? +# - +if [[ "$(trim $*)" = "-h" ]] || [[ "$(trim $*)" = "--help" ]] ; then + usage +fi + +if [[ -z "$(which basename)" ]]; then + fatal 'It seems "basename" is not installed, but needed!' +fi + +if [[ -z "$(which realpath)" ]]; then + fatal 'It seems "realpath" is not installed, but needed!' +fi + + +if [[ -z "$CHECK_COMMANDS" ]]; then + usage "At least one command must be given." +else + for _COMMAND in ${CHECK_COMMANDS[@]} ; do + if [[ ! -x "$_COMMAND" ]]; then + fatal "no binary/script '$_COMMAND' found on the server" + fi + done +fi + + +# ------------- +# - Jobhandling +# ------------- + +# - If job already runs, stop execution.. +# - +if mkdir "$LOCK_DIR" 2> /dev/null ; then + + ## - Remove lockdir when the script finishes, or when it receives a signal + trap clean_up SIGHUP SIGINT SIGTERM + +else + + datum="$(date +"%d.%m.%Y %H:%M")" + + fatal "A previos instance of that script \"$(basename $0)\" seems already be running." + + exit 1 + +fi + + +# ------------- +# Checking .. +# ------------- + +if $terminal ; then + echo "" + echo -e " \033[1mCheck for zombie (defunct) child prozesses\033[m" + echo " ==========================================" +fi + +for _COMMAND in ${CHECK_COMMANDS[@]} ; do + +if $(ps -Ao"stat,command" | grep "$(basename ${_COMMAND})" | grep -v grep | grep -e '^[zZ]' > /dev/null 2>&1) +then + + warn "Found Zombie Processes '${_COMMAND}' on '$(hostname -f)':" + + ps -Ao"stat,user,pid,ppid,command" | grep "$(basename ${_COMMAND})" | grep -v grep | grep -e '^[zZ]' + + membefore=$(cat /proc/meminfo | grep Committed_AS | awk '{print $2}') + + info "Trying a graceful kill to the concerning parents with signal '$KILL_SIGNAL' .." + + # - Sending the kill signal + # - + ps -Ao"stat,pid,ppid,command" | grep "$(basename ${_COMMAND})" | grep -v grep | grep -e '^[zZ]' \ + | awk '{ print $3 }' | sort -u | xargs --no-run-if-empty kill -$KILL_SIGNAL + + if [[ "$?" -eq 0 ]];then + sleep 10 + ok "Cleaning up zombie processes '${_COMMAND}' seems succsessfully finisched" + + memafter=`cat /proc/meminfo | grep Committed_AS | awk '{print $2}'` + + info "`expr $membefore - $memafter` KB RAM has been freed" + else + error "Cleaning up zombie processes '${_COMMAND}' failed!" + fi +else + info_terminal "No zombie prossses '${_COMMAND}' found." +fi +done + +if $terminal ; then + echo "" +fi +clean_up 0 From 00fcb8de66db0d6632781beb38e8fdcef4e46252 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 10 Jan 2018 04:40:39 +0100 Subject: [PATCH 17/45] Improve detection of apache systemd service file if exists. --- check_webservice_load.sh | 50 +++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index abd3bcf..d67c81e 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -214,21 +214,45 @@ if $check_apache ; then fi fi - APACHE_SYSTEMD_SERVICE_EXISTS=false if $systemd_supported ; then - if $(locate apache2.service > /dev/null 2>&1) ; then - APACHE_SYSTEMD_SERVICE_EXISTS=true + # - Is Service exclusive controlled by systemd + # - + if systemctl -t service list-unit-files \ + | grep -e "^mysql" \ + | grep -q enabled 2> /devnull ; then + + MYSQLD_SERVICE_FILE=$(systemctl -t service list-unit-files \ + | grep -e "^mysql" \ + | awk '{print$1}') + fi + + fi + + APACHE_SERVICE_FILE="" + APACHE_INIT_SCRIPT="" + if $systemd_supported ; then + # - Is Service exclusive controlled by systemd + # - + if systemctl -t service list-unit-files \ + | grep -e "^apache" \ + | grep -q enabled 2> /devnull ; then + + APACHE_SERVICE_FILE=$(systemctl -t service list-unit-files \ + | grep -e "^apache" \ + | awk '{print$1}') + fi fi - APACHE_INIT_SCRIPT="" - if [ -x "/etc/init.d/apache2" ]; then - APACHE_INIT_SCRIPT="/etc/init.d/apache2" - elif [ -x "/etc/init.d/apachectl" ]; then - APACHE_INIT_SCRIPT="/etc/init.d/apachectl" + if [[ -z "$APACHE_SERVICE_FILE" ]] ; then + if [ -x "/etc/init.d/apache2" ]; then + APACHE_INIT_SCRIPT="/etc/init.d/apache2" + elif [ -x "/etc/init.d/apachectl" ]; then + APACHE_INIT_SCRIPT="/etc/init.d/apachectl" + fi fi - if [[ -z "$APACHE_INIT_SCRIPT" ]] && ! $APACHE_SYSTEMD_SERVICE_EXISTS ; then + if [[ -z "$APACHE_INIT_SCRIPT" ]] && [[ -z "$APACHE_SERVICE_FILE" ; then fatal 'Neither an init-script nor a service file for apache2 found!' fi fi @@ -402,8 +426,8 @@ stop_apache() { ## - Stop Apache Webservice ## - - if $APACHE_SYSTEMD_SERVICE_EXISTS ; then - systemctl stop apache2 > /dev/null 2>&1 + if [[ -n "$APACHE_SERVICE_FILE" ]] ; then + systemctl stop "$APACHE_SERVICE_FILE" > /dev/null 2>&1 else $APACHE_INIT_SCRIPT stop > /dev/null 2>&1 fi @@ -705,8 +729,8 @@ start_apache() { ## - Start Apache Webservice ## - - if $APACHE_SYSTEMD_SERVICE_EXISTS ; then - systemctl start apache2 > /dev/null 2>&1 + if [[ -n "$APACHE_SERVICE_FILE" ]] ; then + systemctl start "$APACHE_SERVICE_FILE" > /dev/null 2>&1 else $APACHE_INIT_SCRIPT start > /dev/null 2>&1 fi From 89502d3ad190aaaab4c09d2218ae65fb8ebfd5f0 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 10 Jan 2018 15:49:19 +0100 Subject: [PATCH 18/45] Now two scripts handels the cleaning up from zombie (defunct) processes, one by giving command another new one by giving process owner. --- .gitignore | 2 +- ...om_zombies.sh => remove_zombies_command.sh | 0 remove_zombies_user.sh | 265 ++++++++++++++++++ 3 files changed, 266 insertions(+), 1 deletion(-) rename clean_up_from_zombies.sh => remove_zombies_command.sh (100%) create mode 100755 remove_zombies_user.sh diff --git a/.gitignore b/.gitignore index 251f61e..a3b58e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -*.swl +*.swp /conf/*.conf /BAK/* diff --git a/clean_up_from_zombies.sh b/remove_zombies_command.sh similarity index 100% rename from clean_up_from_zombies.sh rename to remove_zombies_command.sh diff --git a/remove_zombies_user.sh b/remove_zombies_user.sh new file mode 100755 index 0000000..37ab892 --- /dev/null +++ b/remove_zombies_user.sh @@ -0,0 +1,265 @@ +#!/usr/bin/env bash + +working_dir="$(dirname $(realpath $0))" + +# ------------- +# - Some Variables +# ------------- + +LOCK_DIR="/tmp/$(basename $0).LOCK" + +KILL_SIGNAL=HUP + +#CHECK_USER="$*" + + +# ------------- +# - Some functions +# ------------- + +usage() { + + + [[ -n "$1" ]] && error "$1" + + + [[ $terminal ]] && echo -e " +\033[1mUsage:\033[m + + $(basename $0) -u + +\033[1mDescription\033[m + + Searches for zombie (defunct) child prozesses owned by a given user. If such + processes exists, the script tries to kill them by sending a HUP signal to + the parent process. + + A user must be given using option '-u'. + +\033[1mOptions\033[m + + -h + Prints this help. + + -u + Searches for zombie (defunct) prozesses owned by this user. + +\033[1mExample:\033[m + + Search for (and delete) defunct child prozesses owned by user 'sympa'' + + $(basename $0) -u sympa + +" + + clean_up 1 + +} + +clean_up() { + + # Perform program exit housekeeping + rm -rf "$LOCK_DIR" + exit $1 +} + +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + +fatal(){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ]: $*" + echo "" + echo -e " \033[31m\033[1mScript was interupted\033[m!" + else + echo "[ Fatal ]: $*" + echo "" + echo " Script was terminated...." + fi + echo "" + clean_up 1 +} + +error (){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ]: $*" + else + echo "[ Error ]: $*" + fi + echo "" +} + +warn (){ + echo "" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarning\033[m ]: $*" + else + echo "[ Warning ]: $*" + fi + echo "" +} + +info (){ + echo "" + if $terminal ; then + echo -e " [ \033[32m\033[1mInfo\033[m ]: $*" + else + echo "[ Info ]: $*" + fi + echo "" +} +info_terminal (){ + if $terminal ; then + echo "" + echo -e " [ \033[32m\033[1mInfo\033[m ]: $*" + echo "" + fi +} + +ok (){ + echo "" + if $terminal ; then + echo -e " [ \033[32m\033[1mOk\033[m ]: $*" + else + echo "[ Ok ]: $*" + fi + echo "" +} + + +# ------------- +# - Check some prerequisites +# ------------- + +# - Is this script running on terminal ? +# - +if [[ -t 1 ]] ; then + terminal=true +else + terminal=false +fi + +if [[ -z "$(which basename)" ]]; then + fatal 'It seems "basename" is not installed, but needed!' +fi + +if [[ -z "$(which realpath)" ]]; then + fatal 'It seems "realpath" is not installed, but needed!' +fi + + + +# ------------- +# - Jobhandling +# ------------- + +# - If job already runs, stop execution.. +# - +if mkdir "$LOCK_DIR" 2> /dev/null ; then + + ## - Remove lockdir when the script finishes, or when it receives a signal + trap clean_up SIGHUP SIGINT SIGTERM + +else + + datum="$(date +"%d.%m.%Y %H:%M")" + + fatal "A previos instance of that script \"$(basename $0)\" seems already be running." + + exit 1 + +fi + + +# ------------- +# - Read Commanline Arguments +# ------------- + +while getopts hu: opt ; do + case $opt in + h) usage ;; + u) CHECK_USER=$OPTARG ;; + *) usage + esac +done + +if [[ -z "$CHECK_USER" ]]; then + usage "No user (option -u) given" +fi + +shift $(expr $OPTIND - 1) +[[ "$#" -gt 0 ]] && usage "Wrong number of arguments given!" + + +# ------------- +# Checking .. +# ------------- + +if $terminal ; then + echo "" + echo -e " \033[1mCheck for zombie (defunct) child prozesses owned by a given user\033[m" + echo " ================================================================" +fi + + +if $(ps -Ao"stat,user,command" | grep "${CHECK_USER}" | grep -v grep | grep -e '^[zZ]' > /dev/null 2>&1) +then + + warn "Found Zombie Processes '${CHECK_USER}' on '$(hostname -f)':" + + # - Print out the concerning lines frp 'ps' output. + # - + ps -Ao"stat,user,pid,ppid,command" | grep "$(basename ${CHECK_USER})" | grep -v grep | grep -e '^[zZ]' + + membefore=$(cat /proc/meminfo | grep Committed_AS | awk '{print $2}') + + info "Trying a graceful kill to the concerning parents with signal '$KILL_SIGNAL' .." + + # - Process ID(s) of the zombie process(es) + # - + ZOMBIE_PIDS="$(ps -Ao"stat,user,pid,ppid,command" | grep "${CHECK_USER}" | grep -v grep | grep -e '^[zZ]' \ + | awk '{ print $3 }' | sort -u)" + + # - Sending the kill signal ($KILL_SIGNAL) to the parent process ID(s) + # - + ps -Ao"stat,user,pid,ppid,command" | grep "${CHECK_USER}" | grep -v grep | grep -e '^[zZ]' \ + | awk '{ print $4 }' | sort -u | xargs --no-run-if-empty kill -$KILL_SIGNAL + + if [[ "$?" -eq 0 ]];then + + declare -i count=1 + for _PID in $ZOMBIE_PIDS ; do + if [[ $count -eq 1 ]]; then + KILLED_PIDS="$_PID" + else + KILLED_PIDS="$KILLED_PIDS $_PID" + fi + ((count++)) + done + + sleep 10 + + ok "Cleaning up zombie processes owned by user '${CHECK_USER}' seems succsessfully finisched" + + ok "$count zombie process(es) with PID(s) '${KILLED_PIDS}' removed from process list" + + memafter=`cat /proc/meminfo | grep Committed_AS | awk '{print $2}'` + + info "`expr $membefore - $memafter` KB RAM has been freed" + else + error "Cleaning up zombie processes owned by user '${CHECK_USER}' failed!" + fi +else + info_terminal "No zombie prossses owned by user '${CHECK_USER}' found." +fi + +if $terminal ; then + echo "" +fi +clean_up 0 From e416ed6f1c6cdaafa346b6a621b0f8905159e0b9 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 10 Jan 2018 18:07:28 +0100 Subject: [PATCH 19/45] Fix minor bug: number of pids must be initialised by '0'. --- remove_zombies_user.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remove_zombies_user.sh b/remove_zombies_user.sh index 37ab892..76979b0 100755 --- a/remove_zombies_user.sh +++ b/remove_zombies_user.sh @@ -233,7 +233,7 @@ then if [[ "$?" -eq 0 ]];then - declare -i count=1 + declare -i count=0 for _PID in $ZOMBIE_PIDS ; do if [[ $count -eq 1 ]]; then KILLED_PIDS="$_PID" From 2d04457f3deeeda497b121f68f8f6174bf6d1a06 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 10 Jan 2018 22:25:57 +0100 Subject: [PATCH 20/45] Add monitoring script for sympa service. --- check_sympa_service.sh | 286 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100755 check_sympa_service.sh diff --git a/check_sympa_service.sh b/check_sympa_service.sh new file mode 100755 index 0000000..f2e94c0 --- /dev/null +++ b/check_sympa_service.sh @@ -0,0 +1,286 @@ +#!/usr/bin/env bash + +working_dir="$(dirname $(realpath $0))" + + +# ------------- +# - Some Variables +# ------------- + +LOCK_DIR="/tmp/$(basename $0).LOCK" + +service_name="sympa" +alert_email_arr="ckubu@oopen.de ckubu@gmx.de" +sender_address="check_sympa@$(hostname -f)" + +sympa_commands=" +/usr/local/sympa/bin/sympa_msg.pl +/usr/local/sympa/bin/bulk.pl +/usr/local/sympa/bin/archived.pl +/usr/local/sympa/bin/bounced.pl +/usr/local/sympa/bin/task_manager.pl +" + +check_string_ps="(/usr/local/sympa/bin/sympa_msg.pl|/usr/local/sympa/bin/bulk.pl|/usr/local/sympa/bin/archived.pl|/usr/local/sympa/bin/bounced.pl|/usr/local/sympa/bin/task_manager.pl)" + +restart_needed=false + +# ------------- +# - Job is already running? +# ------------- + +# - If job already runs, stop execution.. +# - +if mkdir "$LOCK_DIR" 2> /dev/null ; then + + ## - Remove lockdir when the script finishes, or when it receives a signal + trap clean_up SIGHUP SIGINT SIGTERM + +else + + datum="$(date +"%d.%m.%Y %H:%M")" + + msg="[ Error ]: A previos instance of \"`basename $0`\" seems already be running.\n\n Exiting now.." + + echo "" + echo "[ Error ]: A previos instance of that script \"`basename $0`\" seems already be running." + echo "" + echo -e " Exiting now.." + echo "" + + for _email in ${alert_email_arr[@]} ; do + echo -e "To:${_email}\n${content_type}\nSubject:Error cronjob `basename $0` -- $datum\n${msg}\n" \ + | sendmail -F "Error `hostname -f`" -f $sender_address $_email + done + + exit 1 + +fi + + +# ------------- +# - Some functions +# ------------- + +clean_up() { + + # Perform program exit housekeeping + rm -rf "$LOCK_DIR" + exit $1 +} + +echononl(){ + if $terminal ; then + echo X\\c > /tmp/shprompt$$ + if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then + echo -e -n "$*\\c" 1>&2 + else + echo -e -n "$*" 1>&2 + fi + rm /tmp/shprompt$$ + fi +} + +fatal(){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ]: $*" + echo "" + echo -e " \033[31m\033[1mScript was interupted\033[m!" + else + echo " [ Fatal ]: $*" + echo "" + echo " Script was terminated...." + fi + echo "" + clean_up 1 +} + +error (){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ]: $*" + else + echo "[ Error ]: $*" + fi + echo "" +} + +warn (){ + echo "" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarning\033[m ]: $*" + else + echo "[ Warning ]: $*" + fi + echo "" +} + +info (){ + if $terminal ; then + echo "" + echo -e " [ \033[32m\033[1mInfo\033[m ]: $*" + echo "" + fi +} + +echo_done() { + if $terminal ; then + echo -e "\033[75G[ \033[32mdone\033[m ]" + fi +} +echo_failed(){ + if $terminal && $LOGGING ; then + echo -e "\033[75G[ \033[1;31mfailed\033[m ]" + fi +} +echo_skipped() { + if $terminal && $LOGGING ; then + echo -e "\033[75G[ \033[33m\033[1mskipped\033[m ]" + fi +} + + +# ------------- +# - Check some prerequisites +# ------------- + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true +else + terminal=false +fi + +# - Systemd supported ? +# - +systemd=$(which systemd) +systemctl=$(which systemctl) + +systemd_supported=false +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +fi + +# - Check How to start/stop service +# - +SYSTEMD_UNIT_FILE="" +SYSY_INIT_SCRIPT="" +if $systemd_supported ; then + SYSTEMD_UNIT_FILE="$(systemctl list-unit-files | grep -E "${service_name}[^@]*\.service" | grep "enabled" | cut -d' ' -f1)" +fi + +if [[ -z "$SYSTEMD_UNIT_FILE" ]]; then + SYSY_INIT_SCRIPT="$(service --status-all | awk '{print$4}' | grep ${service_name} | head -1)" +fi + +if [[ -z "$SYSTEMD_UNIT_FILE" ]] && [[ -z "$SYSY_INIT_SCRIPT" ]] ; then + fatal "Neither an init-script nor a service file for ${service_name} service found!" +fi + + +# ------------- +# - Main Part of Script +# ------------- + +if $terminal ; then + echo -e "\n Check if ${service_name} service is running.." + echo -e " ===================================" +fi + +for _command in $sympa_commands ; do + PIDS="$(ps ax | grep -E "${_command}" | grep -v grep | awk '{print$1}')" + if [[ -z "$PIDS" ]]; then + restart_needed=true + break + fi +done + +if $restart_needed ;then + + error "${service_name} service seems to be down. Try to (re)start .." + + echononl " Stop service '${service_name}' first .." + if [[ -n "$SYSTEMD_UNIT_FILE" ]] ; then + systemctl stop $SYSTEMD_UNIT_FILE > /dev/null 2>&1 + if [[ $? -eq 0 ]] ; then + echo_done + else + echo_failed + fi + else + /etc/init.d/$SYSY_INIT_SCRIPT stop > /dev/null 2>&1 + if [[ $? -eq 0 ]] ; then + echo_done + else + echo_failed + fi + fi + + sleep 2 + + echononl " Start Service '${service_name}' .." + if [[ -n "$SYSTEMD_UNIT_FILE" ]] ; then + systemctl start $SYSTEMD_UNIT_FILE > /dev/null 2>&1 + if [[ $? -eq 0 ]] ; then + echo_done + else + echo_failed + fi + else + /etc/init.d/$SYSY_INIT_SCRIPT start > /dev/null 2>&1 + if [[ $? -eq 0 ]] ; then + echo_done + else + echo_failed + fi + fi + + + declare -i count=0 + + restart_sucessfully=false + while [[ $count -lt 10 ]] && ! $restart_sucessfully ; do + + ((count++)) + + sleep 1 + + PIDS="" + NEW_PIDS="" + for _command in $sympa_commands ; do + PIDS="$(ps ax | grep -E "${_command}" | grep -v grep | awk '{print$1}')" + if [[ -z "$PIDS" ]]; then + continue + else + if [[ $count -eq 1 ]] ; then + NEW_PIDS="$PIDS" + else + NEW_PIDS="$NEW_PIDS $PIDS" + fi + fi + done + restart_sucessfully=true + + done + + if $restart_sucessfully ; then + error "Restarting service '${service_name}' failed." + else + + info "the new PIDs are $NEW_PIDS" + + echo "" + echo "[ Success ]: Service '${service_name}' was restarted and is now up and running." + echo " The new PIDs are $NEW_PIDS" + echo "" + + fi + +else + info "Service ${service_name} is up and running." +fi + +clean_up 0 + From cd25de5628c6a14b52a332f455302c02df6be2e0 Mon Sep 17 00:00:00 2001 From: Christoph Date: Thu, 11 Jan 2018 17:04:28 +0100 Subject: [PATCH 21/45] - Fix error in detecting apach2 start method. --- check_webservice_load.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index d67c81e..8e7c87d 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -252,7 +252,7 @@ if $check_apache ; then fi fi - if [[ -z "$APACHE_INIT_SCRIPT" ]] && [[ -z "$APACHE_SERVICE_FILE" ; then + if [[ -z "$APACHE_INIT_SCRIPT" ]] && [[ -z "$APACHE_SERVICE_FILE" ]] ; then fatal 'Neither an init-script nor a service file for apache2 found!' fi fi From 19f7eb063e772a62736243cf7a165a77aeba5f66 Mon Sep 17 00:00:00 2001 From: ckubu Date: Fri, 12 Jan 2018 02:10:52 +0100 Subject: [PATCH 22/45] Add check service script for 'nginx': check_nginx_service.sh --- check_nginx_service.sh | 269 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 269 insertions(+) create mode 100755 check_nginx_service.sh diff --git a/check_nginx_service.sh b/check_nginx_service.sh new file mode 100755 index 0000000..9277edb --- /dev/null +++ b/check_nginx_service.sh @@ -0,0 +1,269 @@ +#!/usr/bin/env bash + +working_dir="$(dirname $(realpath $0))" + + +# ------------- +# - Some Variables +# ------------- + +LOCK_DIR="/tmp/$(basename $0).LOCK" + +service_name="nginx" +alert_email_arr="ckubu@oopen.de ckubu@gmx.de" +sender_address="check_${service_name}@$(hostname -f)" + +check_string_ps="nginx: master" + +restart_needed=false + +# ------------- +# - Job is already running? +# ------------- + +# - If job already runs, stop execution.. +# - +if mkdir "$LOCK_DIR" 2> /dev/null ; then + + ## - Remove lockdir when the script finishes, or when it receives a signal + trap clean_up SIGHUP SIGINT SIGTERM + +else + + datum="$(date +"%d.%m.%Y %H:%M")" + + msg="[ Error ]: A previos instance of \"`basename $0`\" seems already be running.\n\n Exiting now.." + + echo "" + echo "[ Error ]: A previos instance of that script \"`basename $0`\" seems already be running." + echo "" + echo -e " Exiting now.." + echo "" + + for _email in ${alert_email_arr[@]} ; do + echo -e "To:${_email}\n${content_type}\nSubject:Error cronjob `basename $0` -- $datum\n${msg}\n" \ + | sendmail -F "Error `hostname -f`" -f $sender_address $_email + done + + exit 1 + +fi + + +# ------------- +# - Some functions +# ------------- + +clean_up() { + + # Perform program exit housekeeping + rm -rf "$LOCK_DIR" + exit $1 +} + +echononl(){ + if $terminal ; then + echo X\\c > /tmp/shprompt$$ + if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then + echo -e -n "$*\\c" 1>&2 + else + echo -e -n "$*" 1>&2 + fi + rm /tmp/shprompt$$ + fi +} + +fatal(){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ]: $*" + echo "" + echo -e " \033[31m\033[1mScript was interupted\033[m!" + else + echo " [ Fatal ]: $*" + echo "" + echo " Script was terminated...." + fi + echo "" + clean_up 1 +} + +error (){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ]: $*" + else + echo "[ Error ]: $*" + fi + echo "" +} + +warn (){ + echo "" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarning\033[m ]: $*" + else + echo "[ Warning ]: $*" + fi + echo "" +} + +info (){ + if $terminal ; then + echo "" + echo -e " [ \033[32m\033[1mInfo\033[m ]: $*" + echo "" + fi +} + +echo_done() { + if $terminal ; then + echo -e "\033[75G[ \033[32mdone\033[m ]" + fi +} +echo_failed(){ + if $terminal && $LOGGING ; then + echo -e "\033[75G[ \033[1;31mfailed\033[m ]" + fi +} +echo_skipped() { + if $terminal && $LOGGING ; then + echo -e "\033[75G[ \033[33m\033[1mskipped\033[m ]" + fi +} + + +# ------------- +# - Check some prerequisites +# ------------- + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true +else + terminal=false +fi + +# - Systemd supported ? +# - +systemd=$(which systemd) +systemctl=$(which systemctl) + +systemd_supported=false +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +fi + +# - Check How to start/stop service +# - +SYSTEMD_UNIT_FILE="" +SYSY_INIT_SCRIPT="" +if $systemd_supported ; then + SYSTEMD_UNIT_FILE="$(systemctl list-unit-files | grep -E "${service_name}[^@]*\.service" | grep "enabled" | cut -d' ' -f1)" +fi + +if [[ -z "$SYSTEMD_UNIT_FILE" ]]; then + SYSY_INIT_SCRIPT="$(service --status-all | awk '{print$4}' | grep ${service_name} | head -1)" +fi + +if [[ -z "$SYSTEMD_UNIT_FILE" ]] && [[ -z "$SYSY_INIT_SCRIPT" ]] ; then + fatal "Neither an init-script nor a service file for ${service_name} service found!" +fi + + +# ------------- +# - Main Part of Script +# ------------- + +if $terminal ; then + echo -e "\n Check if ${service_name} service is running.." + echo -e " ===================================" +fi + +PIDS="$(ps ax | grep -E "${check_string_ps}" | grep -v grep | awk '{print$1}')" +if [[ -z "$PIDS" ]]; then + restart_needed=true +fi + +if $restart_needed ;then + + error "${service_name} service seems to be down. Try to (re)start .." + + echononl " Stop service '${service_name}' first .." + if [[ -n "$SYSTEMD_UNIT_FILE" ]] ; then + systemctl stop $SYSTEMD_UNIT_FILE > /dev/null 2>&1 + if [[ $? -eq 0 ]] ; then + echo_done + else + echo_failed + fi + else + /etc/init.d/$SYSY_INIT_SCRIPT stop > /dev/null 2>&1 + if [[ $? -eq 0 ]] ; then + echo_done + else + echo_failed + fi + fi + + sleep 2 + + echononl " Start Service '${service_name}' .." + if [[ -n "$SYSTEMD_UNIT_FILE" ]] ; then + systemctl start $SYSTEMD_UNIT_FILE > /dev/null 2>&1 + if [[ $? -eq 0 ]] ; then + echo_done + else + echo_failed + fi + else + /etc/init.d/$SYSY_INIT_SCRIPT start > /dev/null 2>&1 + if [[ $? -eq 0 ]] ; then + echo_done + else + echo_failed + fi + fi + + + declare -i count=0 + + restart_sucessfully=false + while [[ $count -lt 10 ]] && ! $restart_sucessfully ; do + + ((count++)) + + sleep 1 + + NEW_PID="$(ps ax | grep -E "${check_string_ps}" | grep -v grep | awk '{print$1}')" + if [[ -z "$NEW_PID" ]]; then + continue + fi + restart_sucessfully=true + break + + done + + if ! $restart_sucessfully ; then + error "Restarting service '${service_name}' failed." + else + + info "Service '${service_name}' was restarted and is now up and running. + The new PID is $NEW_PID" + + if ! $terminal ; then + echo "" + echo "[ Success ]: Service '${service_name}' was restarted and is now up and running." + echo " The new PID is $NEW_PID" + echo "" + fi + + fi + +else + info "Service ${service_name} is up and running." +fi + +clean_up 0 + From 63b2fa45a807ae050adec8b4721b9a94156bc8bf Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 12 Jan 2018 02:43:07 +0100 Subject: [PATCH 23/45] Fix bug in determin new pids. --- check_sympa_service.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/check_sympa_service.sh b/check_sympa_service.sh index f2e94c0..900437d 100755 --- a/check_sympa_service.sh +++ b/check_sympa_service.sh @@ -11,7 +11,7 @@ LOCK_DIR="/tmp/$(basename $0).LOCK" service_name="sympa" alert_email_arr="ckubu@oopen.de ckubu@gmx.de" -sender_address="check_sympa@$(hostname -f)" +sender_address="check_${service_name}@$(hostname -f)" sympa_commands=" /usr/local/sympa/bin/sympa_msg.pl @@ -249,12 +249,16 @@ if $restart_needed ;then PIDS="" NEW_PIDS="" + declare -i count_2=0 for _command in $sympa_commands ; do + + ((count_2++)) + PIDS="$(ps ax | grep -E "${_command}" | grep -v grep | awk '{print$1}')" if [[ -z "$PIDS" ]]; then continue else - if [[ $count -eq 1 ]] ; then + if [[ $count_2 -eq 1 ]] ; then NEW_PIDS="$PIDS" else NEW_PIDS="$NEW_PIDS $PIDS" @@ -262,19 +266,23 @@ if $restart_needed ;then fi done restart_sucessfully=true + break done - if $restart_sucessfully ; then + if ! $restart_sucessfully ; then error "Restarting service '${service_name}' failed." else - info "the new PIDs are $NEW_PIDS" + info "Service '${service_name}' was restarted and is now up and running. + The new PIDs are $NEW_PIDS" - echo "" - echo "[ Success ]: Service '${service_name}' was restarted and is now up and running." - echo " The new PIDs are $NEW_PIDS" - echo "" + if ! $terminal ; then + echo "" + echo "[ Success ]: Service '${service_name}' was restarted and is now up and running." + echo " The new PIDs are $NEW_PIDS" + echo "" + fi fi From 4bfd9b87f60e10f14b4d006657c40afb85e059f8 Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 12 Jan 2018 04:42:51 +0100 Subject: [PATCH 24/45] Support of Debian 9 (stretch) samba installation. --- check_samba4_service.sh | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/check_samba4_service.sh b/check_samba4_service.sh index f91d328..16c6439 100755 --- a/check_samba4_service.sh +++ b/check_samba4_service.sh @@ -3,6 +3,9 @@ working_dir="$(dirname $(realpath $0))" +service_name="samba" +check_string_ps="(sbin/smbd| sbin/samba )" + # ------------- # - Some Variables # ------------- @@ -148,22 +151,20 @@ if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then systemd_supported=true fi -check_string_ps="(sbin/smbd | sbin/samba )" - # - Check How to start/stop service # - SYSTEMD_UNIT_FILE="" SYSY_INIT_SCRIPT="" if $systemd_supported ; then - SYSTEMD_UNIT_FILE="$(systemctl list-unit-files | grep -E "samba[^@]*\.service" | grep "enabled" | cut -d' ' -f1)" + SYSTEMD_UNIT_FILE="$(systemctl list-unit-files | grep -E "${service_name}[^@]*\.service" | grep "enabled" | cut -d' ' -f1)" fi if [[ -z "$SYSTEMD_UNIT_FILE" ]]; then - SYSY_INIT_SCRIPT="$(service --status-all | awk '{print$4}' | grep samba | head -1)" + SYSY_INIT_SCRIPT="$(service --status-all | awk '{print$4}' | grep ${service_name} | head -1)" fi if [[ -z "$SYSTEMD_UNIT_FILE" ]] && [[ -z "$SYSY_INIT_SCRIPT" ]] ; then - fatal 'Neither an init-script nor a service file for samba service found!' + fatal "Neither an init-script nor a service file for ${service_name} service found!" fi @@ -172,17 +173,17 @@ fi # ------------- if $terminal ; then - echo -e "\n Check if Samba Service is running.." - echo -e " ===================================" + echo -e "\n Check if Service '${service_name}' is running.." + echo -e " =====================================" fi PIDS="$(ps ax | grep -E "$check_string_ps" | grep -v grep | awk '{print$1}')" if [[ -z "$PIDS" ]];then - error "Samba Service seems to be down. Try to (re)start .." + error "$service_name service seems to be down. Try to (re)start .." - echononl " Stop Samba Service first .." + echononl " Stop Service '${service_name}' first .." if [[ -n "$SYSTEMD_UNIT_FILE" ]] ; then systemctl stop $SYSTEMD_UNIT_FILE > /dev/null 2>&1 if [[ $? -eq 0 ]] ; then @@ -201,7 +202,7 @@ if [[ -z "$PIDS" ]];then sleep 2 - echononl " Start Samba Service .." + echononl " Start Service '${service_name}' .." if [[ -n "$SYSTEMD_UNIT_FILE" ]] ; then systemctl start $SYSTEMD_UNIT_FILE > /dev/null 2>&1 if [[ $? -eq 0 ]] ; then @@ -228,11 +229,11 @@ if [[ -z "$PIDS" ]];then done if [[ -z "${PIDS}" ]] ; then - error "Restarting Samba Service failed" + error "Restarting Service '${service_name}' failed" else NEW_PIDS="" - count=0 + count=1 for _pid in $PIDS ; do if [[ $count -eq 1 ]] ; then NEW_PIDS="$_pid" @@ -242,17 +243,20 @@ if [[ -z "$PIDS" ]];then ((count++)) done - info "the new PIDs are $NEW_PIDS" + info "Service '${service_name}' was restarted and is now up and running. + The new PID is $NEW_PIDS" - echo "" - echo "[ Success ]: Samba Service was restarted and is now up and running." - echo " The new PIDs are $NEW_PIDS" - echo "" + if ! $terminal ; then + echo "" + echo "[ Success ]: Service '${service_name}' was restarted and is now up and running." + echo " The new PIDs are $NEW_PIDS" + echo "" + fi fi else - info "Samba Service is up and running." + info "Service '${service_name}' is up and running." fi clean_up 0 From 9b7ec42f6eee92c396eeb4a8b5956b570ad007bd Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 29 Jan 2018 03:05:17 +0100 Subject: [PATCH 25/45] Fix error in determin systemd script for mysql and apache2. --- check_webservice_load.sh | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index 8e7c87d..fa32ec5 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -148,7 +148,7 @@ if $check_mysql ; then # - if systemctl -t service list-unit-files \ | grep -e "^mysql" \ - | grep -q enabled 2> /devnull ; then + | grep -q -E "(enabled|disabled)" 2> /devnull ; then MYSQLD_SERVICE_FILE=$(systemctl -t service list-unit-files \ | grep -e "^mysql" \ @@ -214,20 +214,6 @@ if $check_apache ; then fi fi - if $systemd_supported ; then - # - Is Service exclusive controlled by systemd - # - - if systemctl -t service list-unit-files \ - | grep -e "^mysql" \ - | grep -q enabled 2> /devnull ; then - - MYSQLD_SERVICE_FILE=$(systemctl -t service list-unit-files \ - | grep -e "^mysql" \ - | awk '{print$1}') - fi - - fi - APACHE_SERVICE_FILE="" APACHE_INIT_SCRIPT="" if $systemd_supported ; then @@ -235,7 +221,7 @@ if $check_apache ; then # - if systemctl -t service list-unit-files \ | grep -e "^apache" \ - | grep -q enabled 2> /devnull ; then + | grep -q -E "(enabled|disabled)" 2> /devnull ; then APACHE_SERVICE_FILE=$(systemctl -t service list-unit-files \ | grep -e "^apache" \ From 8d7d71fef2f4981a0c425bf0e98781836c9c1cb9 Mon Sep 17 00:00:00 2001 From: Christoph Date: Thu, 22 Feb 2018 17:24:02 +0100 Subject: [PATCH 26/45] Add support for MariaDB. --- check_webservice_load.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index fa32ec5..fbb877e 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -152,7 +152,8 @@ if $check_mysql ; then MYSQLD_SERVICE_FILE=$(systemctl -t service list-unit-files \ | grep -e "^mysql" \ - | awk '{print$1}') + | awk '{print$1}'\ + | head -1) fi fi From 1f3c5e5fddba36c290d9116b78b8de597ca7b8bb Mon Sep 17 00:00:00 2001 From: Christoph Date: Sat, 24 Feb 2018 13:08:33 +0100 Subject: [PATCH 27/45] Fix (spelling in) error message. --- check_remote_websites.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check_remote_websites.sh b/check_remote_websites.sh index b92aae7..a4e769d 100755 --- a/check_remote_websites.sh +++ b/check_remote_websites.sh @@ -219,8 +219,8 @@ if [[ ${#websites_failed_arr[@]} -gt 0 ]] ; then # err_msg="\n[ Error ]: Website ${websites_failed_arr[0]} does NOT respond as exspected\n" # error "Website ${websites_failed_arr[0]} does NOT respond as exspected" #else - error "Some Websites does not respond as expected:" - err_msg="\n[ Error ]: Some Websites does not respond as expected:\n\n" + error "Some Websites do not respond as expected:" + err_msg="\n[ Error ]: Some Websites do not respond as expected:\n\n" for _site in ${websites_failed_arr[@]} ; do err_msg+=" $_site\n" if $LOGGING ; then From f66029fe95ffc2010b0d3e435dbebf9ef7b7f849 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sat, 24 Feb 2018 13:56:55 +0100 Subject: [PATCH 28/45] Add script: 'check_ssh.sh'. --- check_ssh.sh | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100755 check_ssh.sh diff --git a/check_ssh.sh b/check_ssh.sh new file mode 100755 index 0000000..5485b16 --- /dev/null +++ b/check_ssh.sh @@ -0,0 +1,185 @@ +#!/usr/bin/env bash + +sshd_binary="$(which sshd)" + +check_string_ps="$sshd_binary" + +LOCK_DIR=`mktemp -d` + + +#--------------------------------------- +#----------------------------- +# Base Function(s) +#----------------------------- +#--------------------------------------- + +fatal(){ + echo "" + echo -e " [ Fatal ] $*" + echo "" + echo -e "\tScript terminated.." + echo "" + rm -rf $LOCK_DIR + exit 1 +} + +error (){ + echo "" + echo -e " [ Error ] $*" + echo "" +} + +warn (){ + echo "" + echo -e " [ Warn ] $*" + echo "" +} + +info (){ + echo "" + echo -e " [ Info ] $*" + echo "" +} + +ok (){ + echo "" + echo -e " [ Ok ] $*" + echo "" +} + +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + + +#--------------------------------------- +#----------------------------- +# Check some prerequisites +#----------------------------- +#--------------------------------------- + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true + LOGGING=true +else + terminal=false + LOGGING=false +fi + +# - Is SSH Service installed ? +# - +if [[ -z "$sshd_binary" ]]; then + fatal "$(basename $0): SSH Service seems NOT to be installed" +else + check_string_ps="$sshd_binary" +fi + + +# - Systemd supported ? +# - +systemd=$(which systemd) +systemctl=$(which systemctl) + +systemd_supported=false +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +fi + +SSHD_SERVICE_FILE= +SSHD_SYSV_INIT_SCRIPT= + +if $systemd_supported ; then + if systemctl -t service list-unit-files \ + | grep -e "^ssh" \ + | grep -q -E "(enabled|disabled)" 2> /devnull ; then + + SSHD_SERVICE_FILE="$(systemctl -t service list-unit-files | grep -e "^ssh" | awk '{print$1}' | head -1)" + fi +fi + +if [[ -z "$SSHD_SERVICE_FILE" ]]; then + if [[ -x "/etc/init.d/ssh" ]]; then + SSHD_SYSV_INIT_SCRIPT="/etc/init.d/ssh" + elif [[ -x "/etc/init.d/sshd" ]]; then + SSHD_SYSV_INIT_SCRIPT="/etc/init.d/sshd" + fi +fi + +if [[ -z "$SSHD_SERVICE_FILE" ]] && [[ -z "$SSHD_SYSV_INIT_SCRIPT" ]] ; then + fatal 'Neither an init-script nor a service file for SSH found!' +fi + + +#--------------------------------------- +#----------------------------- +# Check if SSH service is running +#----------------------------- +#--------------------------------------- + +if $LOGGING ; then + echo -e "\n Check if SSH service is running.." + echo -e " =================================" +fi +if ! ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}" | grep -v grep > /dev/null ; then + error "SSH service seems to be down! Trying to restart service now.." + + if [[ -n "$SSHD_SERVICE_FILE" ]] ; then + $systemctl daemon-reload > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + sleep 2 + $systemctl stop $SSHD_SERVICE_FILE > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + sleep 10 + $systemctl start $SSHD_SERVICE_FILE > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + else + $SSHD_SYSV_INIT_SCRIPT stop > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Stopping SSH service failed!" + fi + sleep 10 + $SSHD_SYSV_INIT_SCRIPT start > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Starting SSH service failed!" + fi + fi + + declare -i counter=0 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + while [[ "X${PID}" = "X" ]]; do + sleep 1 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + if [[ $counter -gt 10 ]]; then + break + else + ((counter++)) + fi + done + + if [[ "X${PID}" = "X" ]] ; then + error "Restarting SSH service failed!" + else + ok "SSH service is up and running." + fi + +else + if $LOGGING ; then + ok "SSH service is up and running." + fi +fi + +rm -rf $LOCK_DIR +exit 0 + + From 68f1cc8248d5e9a48611037cfa39139b431a1052 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 12 Mar 2018 10:51:46 +0100 Subject: [PATCH 29/45] check_remote_websites.sh: Check until 3 times before reporting an error. --- check_remote_websites.sh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/check_remote_websites.sh b/check_remote_websites.sh index a4e769d..f320f23 100755 --- a/check_remote_websites.sh +++ b/check_remote_websites.sh @@ -198,17 +198,29 @@ fi if [[ -n "$WEBSITES_TO_CHECK" ]] ; then for _site in $WEBSITES_TO_CHECK ; do echononl " Check site \033[1m$_site\033[m .." - response="$(curl --max-time $TIME_OUT --connect-timeout 30 \ - -I -k -L --write-out %{http_code} --silent --output /dev/null $_site 2> ${LOCK_DIR}/err.msg)" - if [[ "$response" -eq 200 ]]; then - echo_ok - else + + declare -i i=0 + _sucess=false + while [[ $i -lt 3 ]] ; do + response="$(curl --max-time $TIME_OUT --connect-timeout 30 \ + -I -k -L --write-out %{http_code} --silent --output /dev/null $_site 2> ${LOCK_DIR}/err.msg)" + if [[ "$response" -eq 200 ]]; then + echo_ok + _sucess=true + break + fi + sleep 2 + ((i++)) + done + + if ! $_success ; then echo_failed if [[ -s "$(cat ${LOCK_DIR}/err.msg)" ]] ; then error "$(cat ${LOCK_DIR}/err.msg)" fi websites_failed_arr+=("$_site") fi + done else warn "No Website to check given (empty var 'WEBSITES_TO_CHECK')" From 673503204bc96f17016bd3b2117b797fb9c3b366 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 18 Mar 2018 13:58:58 +0100 Subject: [PATCH 30/45] Add script 'check_service.sh'. --- check_service.sh | 221 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100755 check_service.sh diff --git a/check_service.sh b/check_service.sh new file mode 100755 index 0000000..c9ede3e --- /dev/null +++ b/check_service.sh @@ -0,0 +1,221 @@ +#!/usr/bin/env bash + + +#--------------------------------------- +#----------------------------- +# Base Function(s) +#----------------------------- +#--------------------------------------- + +fatal(){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ] $*" + else + echo -e " [ Fatal ] $*" + fi + echo "" + if $terminal ; then + echo -e " \033[1mScript terminated\033[m.." + else + echo -e " Script terminated.." + fi + echo "" + rm -rf $LOCK_DIR + exit 1 +} + +error (){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ] $*" + else + echo " [ Error ] $*" + fi + echo "" +} + +warn (){ + echo "" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarn\033[m ] $*" + else + echo " [ Warn ] $*" + fi + echo "" +} + +info (){ + echo "" + if $terminal ; then + echo -e " [ \033[32m\033[1mInfo\033[m ] $*" + else + echo " [ Info ] $*" + fi + echo "" +} + +ok (){ + echo "" + if $terminal ; then + echo -e " [ \033[32m\033[1mOk\033[m ] $*" + else + echo " [ Ok ] $*" + fi + echo "" +} + +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + + +#--------------------------------------- +#----------------------------- +# Check some prerequisites +#----------------------------- +#--------------------------------------- + +LOCK_DIR=`mktemp -d` + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true + LOGGING=true +else + terminal=false + LOGGING=false +fi + +if [[ -n "$1" ]] ; then + service_name=$1 +else + fatal "$(basename $0): No Service given" +fi + +# - Is Service installed ? +# - +_check_binary="$(which ${service_name,,}d)" +if [[ -z "$_check_binary" ]] ; then + _check_binary="$(which ${service_name,,})" +fi + + +if [[ -z "$_check_binary" ]]; then + fatal "$(basename $0): $service_name Service seems NOT to be installed" +else + check_binary="$_check_binary" + check_string_ps="$check_binary" +fi + + +# - Systemd supported ? +# - +systemd=$(which systemd) +systemctl=$(which systemctl) + +systemd_supported=false +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +fi + +SYSTEMD_SERVICE= +SYSV_INIT_SCRIPT= + +if $systemd_supported ; then + if systemctl -t service list-unit-files \ + | grep -e "^${service_name,,}d" \ + | grep -q -E "(enabled|disabled)" 2> /devnull ; then + + SYSTEMD_SERVICE="$(systemctl -t service list-unit-files | grep -e "^${service_name,,}d" | awk '{print$1}' | head -1)" + elif systemctl -t service list-unit-files \ + | grep -e "^${service_name,,}" \ + | grep -q -E "(enabled|disabled)" 2> /devnull ; then + + SYSTEMD_SERVICE="$(systemctl -t service list-unit-files | grep -e "^${service_name,,}" | awk '{print$1}' | head -1)" + fi +fi + +if [[ -z "$SYSTEMD_SERVICE" ]]; then + if [[ -x "/etc/init.d/${service_name,,}" ]]; then + SYSV_INIT_SCRIPT="/etc/init.d/${service_name,,}" + elif [[ -x "/etc/init.d/${service_name,,}d" ]]; then + SYSV_INIT_SCRIPT="/etc/init.d/${service_name,,}d" + fi +fi + +if [[ -z "$SYSTEMD_SERVICE" ]] && [[ -z "$SYSV_INIT_SCRIPT" ]] ; then + fatal "Neither an init-script nor a service file for $service_name found!" +fi + + +#--------------------------------------- +#----------------------------- +# Check if SSH service is running +#----------------------------- +#--------------------------------------- + +if $LOGGING ; then + echo -e "\n Check if $service_name service is running.." + echo -e " =================================" +fi +if ! ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}" | grep -v grep > /dev/null ; then + error "$service_name service seems to be down! Trying to restart service now.." + + if [[ -n "$SYSTEMD_SERVICE" ]] ; then + $systemctl daemon-reload > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + sleep 2 + $systemctl stop $SYSTEMD_SERVICE > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + sleep 10 + $systemctl start $SYSTEMD_SERVICE > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + else + $SYSV_INIT_SCRIPT stop > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Stopping $service_name service failed!" + fi + sleep 10 + $SYSV_INIT_SCRIPT start > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Starting $service_name service failed!" + fi + fi + + declare -i counter=0 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + while [[ "X${PID}" = "X" ]]; do + sleep 1 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + if [[ $counter -gt 10 ]]; then + break + else + ((counter++)) + fi + done + + if [[ "X${PID}" = "X" ]] ; then + error "Restarting $service_name service failed!" + else + ok "$service_name service is up and running." + fi + +else + if $LOGGING ; then + ok "$service_name service is up and running." + fi +fi + +rm -rf $LOCK_DIR +exit 0 From b65a7bc69dec375bde5d55cef35d617a68eb6b37 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 18 Mar 2018 14:00:19 +0100 Subject: [PATCH 31/45] Redesign script 'check_ntpd.sh'. --- check_ntpd.sh | 263 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 252 insertions(+), 11 deletions(-) diff --git a/check_ntpd.sh b/check_ntpd.sh index 4307ea4..744adf5 100755 --- a/check_ntpd.sh +++ b/check_ntpd.sh @@ -1,22 +1,263 @@ #!/usr/bin/env bash -## - Check if ntp service is running. (Re)start service, if -## - it is down. -## - +# - Which Service should be checkked +# - +# - This parameter MUST be given +# - +_service_name="NTP" -PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +# - The binary of the service +# - +# - If not given, script dries to determin it. +# - +_check_binary="$(which ntpd)" -if ! ps ax | grep /usr/sbin/ntpd | grep -v grep > /dev/null ; then +# - The systemd service file +# - +# - If not given, script dries to determin it. +# +_SYSTEMD_SERVICE="ntp" - echo -e "\n\tNTP Daemon is not running. so i'm going to (re)start the ntp service..\n" +# - The sysv init script of the service +# - +# - If not given, script dries to determin it. +# +#_SYSV_INIT_SCRIPT="ntp" - /etc/init.d/ntp stop - kill -9 `cat /var/run/ntpd.pid 2>/dev/null` > /dev/null 2>&1 - rm -f /var/run/ntpd.pid +#--------------------------------------- +#----------------------------- +# Base Function(s) +#----------------------------- +#--------------------------------------- - ## - Start ntp daemon - /etc/init.d/ntp start +fatal(){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ] $*" + else + echo -e " [ Fatal ] $*" + fi + echo "" + if $terminal ; then + echo -e " \033[1mScript terminated\033[m.." + else + echo -e " Script terminated.." + fi + echo "" + rm -rf $LOCK_DIR + exit 1 +} + +error (){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ] $*" + else + echo " [ Error ] $*" + fi + echo "" +} + +warn (){ + echo "" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarn\033[m ] $*" + else + echo " [ Warn ] $*" + fi + echo "" +} + +info (){ + echo "" + if $terminal ; then + echo -e " [ \033[32m\033[1mInfo\033[m ] $*" + else + echo " [ Info ] $*" + fi + echo "" +} + +ok (){ + echo "" + if $terminal ; then + echo -e " [ \033[32m\033[1mOk\033[m ] $*" + else + echo " [ Ok ] $*" + fi + echo "" +} + +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + + +#--------------------------------------- +#----------------------------- +# Check some prerequisites +#----------------------------- +#--------------------------------------- + +LOCK_DIR=`mktemp -d` + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true + LOGGING=true +else + terminal=false + LOGGING=false fi +if [[ -n "$_service_name" ]]; then + service_name=$_service_name +else + fatal "$(basename $0): No Service given" +fi + +# - Is Service installed ? +# - +if [[ -z "$_check_binary" ]]; then + _check_binary="$(which ${service_name,,}d)" + if [[ -z "$_check_binary" ]] ; then + _check_binary="$(which ${service_name,,})" + fi +fi + + +if [[ -z "$_check_binary" ]]; then + fatal "$(basename $0): $service_name Service seems NOT to be installed" +else + check_binary="$_check_binary" + check_string_ps="$check_binary" +fi + + +# - Systemd supported ? +# - +systemd=$(which systemd) +systemctl=$(which systemctl) + +systemd_supported=false +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +fi + +SYSTEMD_SERVICE= +SYSV_INIT_SCRIPT= + +if $systemd_supported ; then + if [[ -n "$_SYSTEMD_SERVICE" ]] ; then + if systemctl -t service list-unit-files \ + | grep -e "^$_SYSTEMD_SERVICE" \ + | grep -q -E "(enabled|disabled)" 2> /devnull ; then + + SYSTEMD_SERVICE="$(systemctl -t service list-unit-files | grep -e "^$_SYSTEMD_SERVICE" | awk '{print$1}' | head -1)" + fi + else + if systemctl -t service list-unit-files \ + | grep -e "^${service_name,,}d" \ + | grep -q -E "(enabled|disabled)" 2> /devnull ; then + + SYSTEMD_SERVICE="$(systemctl -t service list-unit-files | grep -e "^${service_name,,}d" | awk '{print$1}' | head -1)" + elif systemctl -t service list-unit-files \ + | grep -e "^${service_name,,}" \ + | grep -q -E "(enabled|disabled)" 2> /devnull ; then + + SYSTEMD_SERVICE="$(systemctl -t service list-unit-files | grep -e "^${service_name,,}" | awk '{print$1}' | head -1)" + fi + fi +fi + +if [[ -z "$SYSTEMD_SERVICE" ]]; then + if [[ -n "$_SYSV_INIT_SCRIPT" ]]; then + if [[ -x "$_SYSV_INIT_SCRIPT" ]]; then + SYSV_INIT_SCRIPT="$_SYSV_INIT_SCRIPT" + fi + fi + if [[ -z "$SYSV_INIT_SCRIPT" ]] ; then + if [[ -x "/etc/init.d/${service_name,,}" ]]; then + SYSV_INIT_SCRIPT="/etc/init.d/${service_name,,}" + elif [[ -x "/etc/init.d/${service_name,,}d" ]]; then + SYSV_INIT_SCRIPT="/etc/init.d/${service_name,,}d" + fi + fi +fi + +if [[ -z "$SYSTEMD_SERVICE" ]] && [[ -z "$SYSV_INIT_SCRIPT" ]] ; then + fatal "Neither an init-script nor a service file for $service_name found!" +fi + + +#--------------------------------------- +#----------------------------- +# Check if SSH service is running +#----------------------------- +#--------------------------------------- + +if $LOGGING ; then + echo -e "\n Check if $service_name service is running.." + echo -e " =================================" +fi +if ! ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}" | grep -v grep > /dev/null ; then + error "$service_name service seems to be down! Trying to restart service now.." + + if [[ -n "$SYSTEMD_SERVICE" ]] ; then + $systemctl daemon-reload > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + sleep 2 + $systemctl stop $SYSTEMD_SERVICE > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + sleep 10 + $systemctl start $SYSTEMD_SERVICE > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + else + $SYSV_INIT_SCRIPT stop > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Stopping $service_name service failed!" + fi + sleep 10 + $SYSV_INIT_SCRIPT start > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Starting $service_name service failed!" + fi + fi + + declare -i counter=0 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + while [[ "X${PID}" = "X" ]]; do + sleep 1 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + if [[ $counter -gt 10 ]]; then + break + else + ((counter++)) + fi + done + + if [[ "X${PID}" = "X" ]] ; then + error "Restarting $service_name service failed!" + else + ok "$service_name service is up and running." + fi + +else + if $LOGGING ; then + ok "$service_name service is up and running." + fi +fi + +rm -rf $LOCK_DIR exit 0 From e376c1ab4bc6b45191ac4e13b72f640142fba784 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 18 Mar 2018 14:02:08 +0100 Subject: [PATCH 32/45] Some minor changes on output of script 'check_postfix.sh'. --- check_postfix.sh | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/check_postfix.sh b/check_postfix.sh index 62dd085..2629e21 100755 --- a/check_postfix.sh +++ b/check_postfix.sh @@ -23,11 +23,20 @@ LOCK_DIR=`mktemp -d` #----------------------------- #--------------------------------------- + fatal(){ echo "" - echo -e " [ Fatal ] $*" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ] $*" + else + echo -e " [ Fatal ] $*" + fi echo "" - echo -e "\tScript terminated.." + if $terminal ; then + echo -e " \033[1mScript terminated\033[m.." + else + echo -e " Script terminated.." + fi echo "" rm -rf $LOCK_DIR exit 1 @@ -35,25 +44,41 @@ fatal(){ error (){ echo "" - echo -e " [ Error ] $*" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ] $*" + else + echo " [ Error ] $*" + fi echo "" } warn (){ echo "" - echo -e " [ Warn ] $*" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarn\033[m ] $*" + else + echo " [ Warn ] $*" + fi echo "" } info (){ echo "" - echo -e " [ Info ] $*" + if $terminal ; then + echo -e " [ \033[32m\033[1mInfo\033[m ] $*" + else + echo " [ Info ] $*" + fi echo "" } ok (){ echo "" - echo -e " [ Ok ] $*" + if $terminal ; then + echo -e " [ \033[32m\033[1mOk\033[m ] $*" + else + echo " [ Ok ] $*" + fi echo "" } From d58b7cc683777ee7a4cea0a50c927ab8d4b6926e Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 18 Mar 2018 14:56:21 +0100 Subject: [PATCH 33/45] check_dns.sh: some minor changes on script output. --- check_dns.sh | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/check_dns.sh b/check_dns.sh index 7e1d155..79045e0 100755 --- a/check_dns.sh +++ b/check_dns.sh @@ -29,9 +29,17 @@ LOCK_DIR=`mktemp -d` fatal(){ echo "" - echo -e " [ Fatal ] $*" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ] $*" + else + echo -e " [ Fatal ] $*" + fi echo "" - echo -e "\tScript terminated.." + if $terminal ; then + echo -e " \033[1mScript terminated\033[m.." + else + echo -e " Script terminated.." + fi echo "" rm -rf $LOCK_DIR exit 1 @@ -39,28 +47,54 @@ fatal(){ error (){ echo "" - echo -e " [ Error ] $*" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ] $*" + else + echo " [ Error ] $*" + fi echo "" } warn (){ echo "" - echo -e " [ Warn ] $*" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarn\033[m ] $*" + else + echo " [ Warn ] $*" + fi echo "" } info (){ echo "" - echo -e " [ Info ] $*" + if $terminal ; then + echo -e " [ \033[32m\033[1mInfo\033[m ] $*" + else + echo " [ Info ] $*" + fi echo "" } ok (){ echo "" - echo -e " [ Ok ] $*" + if $terminal ; then + echo -e " [ \033[32m\033[1mOk\033[m ] $*" + else + echo " [ Ok ] $*" + fi echo "" } +fatal(){ + echo "" + echo -e " [ Fatal ] $*" + echo "" + echo -e "\tScript terminated.." + echo "" + rm -rf $LOCK_DIR + exit 1 +} + trim() { local var="$*" var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters @@ -78,8 +112,8 @@ trim() { # - Running in a terminal? # - if [[ -t 1 ]] ; then - terminal=true - LOGGING=true + terminal=true + LOGGING=true else terminal=false LOGGING=false From 3ce0e5e1709008c2295f440ae5e75de5ae83c3ed Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 18 Mar 2018 19:40:17 +0100 Subject: [PATCH 34/45] check_vpn.sh: some minor changes on script output. --- check_vpn.sh | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/check_vpn.sh b/check_vpn.sh index 9342e4a..f0d644d 100755 --- a/check_vpn.sh +++ b/check_vpn.sh @@ -36,34 +36,59 @@ clean_up() { fatal(){ echo "" - echo -e " [ Fatal ] $*" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ] $*" + else + echo -e " [ Fatal ] $*" + fi echo "" - echo -e "\tScript terminated.." + if $terminal ; then + echo -e " \033[1mScript terminated\033[m.." + else + echo -e " Script terminated.." + fi echo "" - clean_up 1 + rm -rf $LOCK_DIR + exit 1 } error (){ echo "" - echo -e " [ Error ] $*" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ] $*" + else + echo " [ Error ] $*" + fi echo "" } warn (){ echo "" - echo -e " [ Warn ] $*" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarn\033[m ] $*" + else + echo " [ Warn ] $*" + fi echo "" } info (){ echo "" - echo -e " [ Info ] $*" + if $terminal ; then + echo -e " [ \033[32m\033[1mInfo\033[m ] $*" + else + echo " [ Info ] $*" + fi echo "" } ok (){ echo "" - echo -e " [ Ok ] $*" + if $terminal ; then + echo -e " [ \033[32m\033[1mOk\033[m ] $*" + else + echo " [ Ok ] $*" + fi echo "" } From db0077fdbfedbd37e45e063baccd499905ffadea Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 18 Mar 2018 23:05:22 +0100 Subject: [PATCH 35/45] Add script 'check_dhcp.sh'. --- check_dhcp.sh | 263 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100755 check_dhcp.sh diff --git a/check_dhcp.sh b/check_dhcp.sh new file mode 100755 index 0000000..3b4de0f --- /dev/null +++ b/check_dhcp.sh @@ -0,0 +1,263 @@ +#!/usr/bin/env bash + +# - Which Service should be checkked +# - +# - This parameter MUST be given +# - +_service_name="DHCP" + +# - The binary of the service +# - +# - If not given, script dries to determin it. +# - +_check_binary="$(which dhcpd)" + +# - The systemd service file +# - +# - If not given, script dries to determin it. +# +#_SYSTEMD_SERVICE="isc-dhcp-server" + +# - The sysv init script of the service +# - +# - If not given, script dries to determin it. +# +_SYSV_INIT_SCRIPT="isc-dhcp-server" + + +#--------------------------------------- +#----------------------------- +# Base Function(s) +#----------------------------- +#--------------------------------------- + +fatal(){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ] $*" + else + echo -e " [ Fatal ] $*" + fi + echo "" + if $terminal ; then + echo -e " \033[1mScript terminated\033[m.." + else + echo -e " Script terminated.." + fi + echo "" + rm -rf $LOCK_DIR + exit 1 +} + +error (){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ] $*" + else + echo " [ Error ] $*" + fi + echo "" +} + +warn (){ + echo "" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarn\033[m ] $*" + else + echo " [ Warn ] $*" + fi + echo "" +} + +info (){ + echo "" + if $terminal ; then + echo -e " [ \033[32m\033[1mInfo\033[m ] $*" + else + echo " [ Info ] $*" + fi + echo "" +} + +ok (){ + echo "" + if $terminal ; then + echo -e " [ \033[32m\033[1mOk\033[m ] $*" + else + echo " [ Ok ] $*" + fi + echo "" +} + +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + + +#--------------------------------------- +#----------------------------- +# Check some prerequisites +#----------------------------- +#--------------------------------------- + +LOCK_DIR=`mktemp -d` + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true + LOGGING=true +else + terminal=false + LOGGING=false +fi + +if [[ -n "$_service_name" ]]; then + service_name=$_service_name +else + fatal "$(basename $0): No Service given" +fi + +# - Is Service installed ? +# - +if [[ -z "$_check_binary" ]]; then + _check_binary="$(which ${service_name,,}d)" + if [[ -z "$_check_binary" ]] ; then + _check_binary="$(which ${service_name,,})" + fi +fi + + +if [[ -z "$_check_binary" ]]; then + fatal "$(basename $0): $service_name Service seems NOT to be installed" +else + check_binary="$_check_binary" + check_string_ps="$check_binary" +fi + + +# - Systemd supported ? +# - +systemd=$(which systemd) +systemctl=$(which systemctl) + +systemd_supported=false +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +fi + +SYSTEMD_SERVICE= +SYSV_INIT_SCRIPT= + +if $systemd_supported ; then + if [[ -n "$_SYSTEMD_SERVICE" ]] ; then + if systemctl -t service list-unit-files \ + | grep -e "^$_SYSTEMD_SERVICE" \ + | grep -q -E "(enabled|disabled)" 2> /devnull ; then + + SYSTEMD_SERVICE="$(systemctl -t service list-unit-files | grep -e "^$_SYSTEMD_SERVICE" | awk '{print$1}' | head -1)" + fi + else + if systemctl -t service list-unit-files \ + | grep -e "^${service_name,,}d" \ + | grep -q -E "(enabled|disabled)" 2> /devnull ; then + + SYSTEMD_SERVICE="$(systemctl -t service list-unit-files | grep -e "^${service_name,,}d" | awk '{print$1}' | head -1)" + elif systemctl -t service list-unit-files \ + | grep -e "^${service_name,,}" \ + | grep -q -E "(enabled|disabled)" 2> /devnull ; then + + SYSTEMD_SERVICE="$(systemctl -t service list-unit-files | grep -e "^${service_name,,}" | awk '{print$1}' | head -1)" + fi + fi +fi + +if [[ -z "$SYSTEMD_SERVICE" ]]; then + if [[ -n "$_SYSV_INIT_SCRIPT" ]]; then + if [[ -x "/etc/init.d/$_SYSV_INIT_SCRIPT" ]]; then + SYSV_INIT_SCRIPT="/etc/init.d/$_SYSV_INIT_SCRIPT" + fi + fi + if [[ -z "$SYSV_INIT_SCRIPT" ]] ; then + if [[ -x "/etc/init.d/${service_name,,}" ]]; then + SYSV_INIT_SCRIPT="/etc/init.d/${service_name,,}" + elif [[ -x "/etc/init.d/${service_name,,}d" ]]; then + SYSV_INIT_SCRIPT="/etc/init.d/${service_name,,}d" + fi + fi +fi + +if [[ -z "$SYSTEMD_SERVICE" ]] && [[ -z "$SYSV_INIT_SCRIPT" ]] ; then + fatal "Neither an init-script nor a service file for $service_name found!" +fi + + +#--------------------------------------- +#----------------------------- +# Check if SSH service is running +#----------------------------- +#--------------------------------------- + +if $LOGGING ; then + echo -e "\n Check if $service_name service is running.." + echo -e " =================================" +fi +if ! ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}" | grep -v grep > /dev/null ; then + error "$service_name service seems to be down! Trying to restart service now.." + + if [[ -n "$SYSTEMD_SERVICE" ]] ; then + $systemctl daemon-reload > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + sleep 2 + $systemctl stop $SYSTEMD_SERVICE > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + sleep 10 + $systemctl start $SYSTEMD_SERVICE > /dev/null 2> ${LOCK_DIR}/err_msg.log + if [[ $? -ne 0 ]]; then + error "$(cat ${LOCK_DIR}/err_msg.log)" + fi + else + $SYSV_INIT_SCRIPT stop > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Stopping $service_name service failed!" + fi + sleep 10 + $SYSV_INIT_SCRIPT start > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + error "Starting $service_name service failed!" + fi + fi + + declare -i counter=0 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + while [[ "X${PID}" = "X" ]]; do + sleep 1 + PID=$(ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}"| grep -v grep | awk '{print$2}') + if [[ $counter -gt 10 ]]; then + break + else + ((counter++)) + fi + done + + if [[ "X${PID}" = "X" ]] ; then + error "Restarting $service_name service failed!" + else + ok "$service_name service is up and running." + fi + +else + if $LOGGING ; then + ok "$service_name service is up and running." + fi +fi + +rm -rf $LOCK_DIR +exit 0 From 36389fdc023fde267af094ed01dd8a8f5dba364b Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 13 Apr 2018 18:28:53 +0200 Subject: [PATCH 36/45] Add script 'check_cert_for_service.sh'. --- check_cert_for_service.sh | 411 ++++++++++++++++++++++++ conf/check_cert_for_service.conf.sample | 97 ++++++ 2 files changed, 508 insertions(+) create mode 100755 check_cert_for_service.sh create mode 100644 conf/check_cert_for_service.conf.sample diff --git a/check_cert_for_service.sh b/check_cert_for_service.sh new file mode 100755 index 0000000..2007c7e --- /dev/null +++ b/check_cert_for_service.sh @@ -0,0 +1,411 @@ +#!/usr/bin/env bash + +# =============================================================== +# - Don't make definitions here! Do this at the configuration file +# ================================================================ + +working_dir="$(dirname $(realpath $0))" +conf_file="${working_dir}/conf/check_cert_for_service.conf" + +# ---------- +# - +# - Script checks, whether the certificate for mumble services are up to date. If +# - newer versions than the installed one found, script changes the installed +# - key/cert to the latest version. +# - +# - Note !! +# - This script is very special to the server environment of machine 'o13-il.oopen.de' +# - +# ---------- + +LOCK_DIR="/tmp/check_cert_${service_name}.sh.LOCK" +log_file="${LOCK_DIR}/check_cert_${service_name}.log" + +restart_service=false + + +# ------------- +# --- Some functions +# ------------- + +clean_up() { + + # Perform program exit housekeeping + rm -rf "$LOCK_DIR" + exit $1 +} + +echononl(){ + if $terminal ; then + echo X\\c > /tmp/shprompt$$ + if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then + echo -e -n "$*\\c" 1>&2 + else + echo -e -n "$*" 1>&2 + fi + rm /tmp/shprompt$$ + fi +} + +fatal(){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ]: $*" + echo "" + echo -e " \033[31m\033[1mScript was interupted\033[m!" + else + echo " [ Fatal ]: $*" + echo "" + echo " Script was terminated...." + fi + echo "" + clean_up 1 +} + +error() { + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ]: $*" + else + echo " [ Error ]: $*" + fi + echo "" +} + +warn() { + echo "" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarning\033[m ]: $*" + else + echo " [ Warning ]: $*" + fi + echo "" +} + +info() { + if $terminal ; then + echo "" + echo -e " [ \033[32m\033[1mInfo\033[m ]: $*" + echo "" + fi +} + +echo_failed(){ + if $terminal ; then + echo -e "\033[75G[ \033[1;31mfailed\033[m ]" + fi +} + +echo_done() { + if $terminal ; then + echo -e "\033[75G[ \033[32mok\033[m ]" + fi +} + + +# ------------- +# - Job is already running? +# ------------- + +# - If job already runs, stop execution.. +# - +if mkdir "$LOCK_DIR" 2> /dev/null ; then + + # - Remove lockdir when the script finishes, or when it receives a signal + # - + trap clean_up SIGHUP SIGINT SIGTERM + +else + + msg="A previos instance of script \"`basename $0`\" seems already be running." + + echo "" + if $terminal ; then + echo -e "[ \033[31m\033[1mFatal\033[m ]: $msg" + echo "" + echo -e " \033[31m\033[1mScript was interupted\033[m!" + else + echo " [ Fatal ]: $msg" + echo "" + echo " Script was interupted!" + fi + echo + + exit 1 + +fi + + +# ------------- +# --- Some checks +# ------------- + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true +else + terminal=false +fi + + +# - Read Configurations from $conf_file +# - +if [[ ! -f "$conf_file" ]]; then + fatal " Configuration file '$(basename ${conf_file})' not found!" +else + source $conf_file +fi + +# - Systemd supported ? +# - +systemd_supported=false +systemd=$(which systemd) +systemctl=$(which systemctl) + +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +fi + +SYSTEMD_SERVICE= +SYSV_INIT_SCRIPT= + +if $systemd_supported ; then + if systemctl -t service list-unit-files \ + | grep -e "^${service_name,,}d" \ + | grep -q -E "(enabled|disabled|generated)" 2> /devnull ; then + + SYSTEMD_SERVICE="$(systemctl -t service list-unit-files | grep -e "^${service_name,,}d" | awk '{print$1}' | head -1)" + elif systemctl -t service list-unit-files \ + | grep -e "^${service_name,,}-server" \ + | grep -q -E "(enabled|disabled|generated)" 2> /devnull ; then + + SYSTEMD_SERVICE="$(systemctl -t service list-unit-files | grep -e "^${service_name,,}-server" | awk '{print$1}' | head -1)" + elif systemctl -t service list-unit-files \ + | grep -e "^${service_name,,}" \ + | grep -q -E "(enabled|disabled|generated)" 2> /devnull ; then + + SYSTEMD_SERVICE="$(systemctl -t service list-unit-files | grep -e "^${service_name,,}" | awk '{print$1}' | head -1)" + fi +fi + +if [[ -z "$SYSTEMD_SERVICE" ]]; then + if [[ -x "/etc/init.d/${service_name,,}" ]]; then + SYSV_INIT_SCRIPT="/etc/init.d/${service_name,,}" + elif [[ -x "/etc/init.d/${service_name,,}d" ]]; then + SYSV_INIT_SCRIPT="/etc/init.d/${service_name,,}d" + elif [[ -x "/etc/init.d/${service_name,,}-server" ]]; then + SYSV_INIT_SCRIPT="/etc/init.d/${service_name,,}-server" + fi +fi + +if [[ -z "$SYSTEMD_SERVICE" ]] && [[ -z "$SYSV_INIT_SCRIPT" ]] ; then + fatal "Neither an init-script nor a service file for $service_name found!" +fi + +#echo "SYSTEMD_SERVICE: $SYSTEMD_SERVICE" +#echo "SYSV_INIT_SCRIPT: $SYSV_INIT_SCRIPT" +#clean_up 0 + + + +# ------------- +# - Don't run script, if any give path for cert/key does not exists +# ------------- + +if [[ ! -f "$cert_installed" ]] ; then + fatal "Installed Certificate '$cert_installed' for service '${service_name}' not found!" +elif [[ ! -f "$cert_newest" ]] ; then + fatal "Newest Certificate '$cert_newest' for service '${service_name}' not found!" +elif [[ ! -f "$key_installed" ]]; then + fatal "Installed Key '$key_installed' for service '${service_name}' not found!" +elif [[ ! -f "$key_newest" ]] ; then + fatal "Newest Key '$key_newest' for service '${service_name}' not found!" +fi + + +# ------------- +# - Check if key/cert are up to date, change them if needed. +# ------------- + +if ! diff "$(realpath "$cert_installed")" "$(realpath "$cert_newest")" > /dev/null 2>&1 ; then + + _failed=false + + warn "Certificate for service '${service_name}' is outdated! + + Try to update certificate and key.." + + echononl " Update certificat for for service '${service_name}' .." + > $log_file + if [[ -h "$cert_installed" ]] ; then + rm "$(realpath "$cert_installed")" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi + + rm "$cert_installed" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + cp -a "$(realpath "$cert_newest")" "$(dirname "$cert_installed")" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + chown ${service_user}:$service_group "$(dirname "$cert_installed")/$(basename "$(realpath "$cert_newest")")" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + ln -s "$(basename "$(realpath "$cert_newest")")" "$cert_installed" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + if $_failed ; then + echo_failed + error "$(cat "$log_file")" + else + echo_done + fi + + if ! $_failed ; then + + _failed=false + + echononl " Update key for service '${service_name}' .." + if [[ -h "$key_installed" ]] ; then + rm "$(realpath "$key_installed")" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi + + rm "$key_installed" > $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + cp -a "$(realpath "$key_newest")" "$(dirname "$key_installed")" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + chown ${service_user}:$service_group "$(dirname "$key_installed")/$(basename "$(realpath "$key_newest")")" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + ln -s "$(basename "$(realpath "$key_newest")")" "$key_installed" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + if $_failed ; then + echo_failed + error "$(cat "$log_file")" + else + echo_done + restart_service=true + fi + + fi + + if ! $_failed ; then + if $terminal ; then + info "Certificate/Key for service '${service_name}' is now up to date" + else + echo "" + echo " [ Info ]: Certificate/Key for service '${service_name}' is now up to date" + echo "" + fi + else + error "Updating Certificate/Key for service '${service_name}' failed!" + fi + +else + up_to_date=true + info "Certificate for service '${service_name}' is up to date!" +fi + +if $restart_service ; then + + _failed=false + echononl "Going to restart Service '${service_name}' .." + if [[ -n "$SYSTEMD_SERVICE" ]] ; then + $systemctl daemon-reload > $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + sleep 2 + + $systemctl stop $SYSTEMD_SERVICE >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + sleep 10 + + $systemctl start $SYSTEMD_SERVICE >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + if $_failed ; then + echo_failed + error "$($log_file)" + else + echo_done + fi + else + $SYSV_INIT_SCRIPT stop > $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + sleep 10 + $SYSV_INIT_SCRIPT start >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + if $_failed ; then + echo_failed + error "$($log_file)" + else + echo_done + fi + fi + + if ! $_failed ; then + + declare -i counter=0 + PID=$(ps -e f | grep -E "${check_string_ps}"| grep -v grep | awk '{print$1}') + while [[ "X${PID}" = "X" ]]; do + if [[ $counter -gt 10 ]]; then + _failed=true + break + else + ((counter++)) + fi + sleep 1 + PID=$(ps -e f | grep -E "${check_string_ps}"| grep -v grep | awk '{print$1}') + done + + fi + + if $_failed ; then + error "Restarting service '${service_name}' failed!" + else + if $terminal ; then + info "'${service_name}' Service was restarted. the new pid is '$PID'." + else + echo "" + echo " '${service_name}' Service was restarted. the new pid is '$PID'." + echo "" + fi + fi + +fi + +clean_up 0 + diff --git a/conf/check_cert_for_service.conf.sample b/conf/check_cert_for_service.conf.sample new file mode 100644 index 0000000..d7c3ac0 --- /dev/null +++ b/conf/check_cert_for_service.conf.sample @@ -0,0 +1,97 @@ +#--------------------------------------- +#----------------------------- +# Settings for script check_cert_for_service.sh +#----------------------------- +#--------------------------------------- + + +# - service_name +# - +# - Name of service. +# - +# - Note: this var will also be used to determin systemd service file +# - or sysVinit script. +# - +# - Example: +# - service_name="Mumble" +# - service_name="Prosody" +# - +#service_name="" + + +# - check_string_ps +# - +# - String wich (clearly) identifies the service at the process list (ps) +# - +# - Example: +# - check_string_ps="[[:digit:]]\ /usr/sbin/murmurd" +# - check_string_ps="" +# - +#check_string_ps="" + + +# - service_user +# - +# - User under which the service is running. +# - +# - Example: +# - service_user="mumble-server" +# - service_user="prosody" +# - +#service_user="" + + +# - service_group +# - +# - Group under which the service is running. +# - +# - Example: +# - service_group="mumble-server" +# - service_group="prosody" +# - +#service_user="" + + +# - cert_installed +# - +# - Locataion of certificate read by service +# - +# - Example: +# - cert_installed="/var/lib/mumble-server/fullchain.pem" +# - cert_installed="/var/lib/dehydrated/certs/jabber.so36.net/fullchain.pem" +# - +#cert_installed="" + + +# - key_installed +# - +# - Location of the key read by service +# - +# - Example: +# - key_installed="/var/lib/mumble-server/privkey.pem" +# - key_installed="/etc/prosody/certs/privkey_jabber.so36.pem" +# - +#key_installed="" + + +# - cert_newest +# - +# - Location of the newest certificate. +# - +# - Example: +# - cert_newest="/var/lib/dehydrated/certs/il-mumble.oopen.de/fullchain.pem" +# - cert_newest="/var/lib/dehydrated/certs/jabber.so36.net/fullchain.pem" +# - +#cert_newest="" + + +# - key_newest +# - +# - Location of the newest Key +# - +# - Example: +# - key_newest="/var/lib/dehydrated/certs/il-mumble.oopen.de/privkey.pem" +# - key_newest="/var/lib/dehydrated/certs/jabber.so36.net/privkey.pem" +# - +#key_newest="" + From b62e83549240c7f068718e707846447306881c54 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 23 Apr 2018 01:34:05 +0200 Subject: [PATCH 37/45] Correct comment. --- check_service.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_service.sh b/check_service.sh index c9ede3e..e9d1995 100755 --- a/check_service.sh +++ b/check_service.sh @@ -155,7 +155,7 @@ fi #--------------------------------------- #----------------------------- -# Check if SSH service is running +# Check if service is running #----------------------------- #--------------------------------------- From 968915712168f2aed80076ec46ad295cd595a553 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 23 Apr 2018 02:24:38 +0200 Subject: [PATCH 38/45] check_webservice_load.sh: add support for 'nginx' and 'redis'. Change output on terminal. --- check_webservice_load.sh | 478 ++++++++++++++++++++++++- conf/check_webservice_load.conf.sample | 2 + 2 files changed, 470 insertions(+), 10 deletions(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index fbb877e..e98a13f 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -10,6 +10,16 @@ conf_file="${working_dir}/conf/check_webservice_load.conf" #----------------------------- #--------------------------------------- +# - Defaults +# - +check_load=false +check_mysql=false +check_apache=false +check_nginx=false +check_php_fpm=false +check_redis=false +check_website=false + if [[ ! -f "$conf_file" ]]; then echo "" echo -e " [ Fatal ] Configuration file '$(basename ${conf_file})' not found!" @@ -40,34 +50,53 @@ LOCK_DIR=`mktemp -d` fatal(){ echo "" - echo -e " [ Fatal ] $*" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ] $*" + else + echo -e " [ Fatal ] $*" + fi echo "" - echo -e "\tScript terminated.." - echo "" - exit 1 + rm -rf $LOCK_DIR + exit 1 } error (){ echo "" - echo -e " [ Error ] $*" + if $terminal ; then + echo -e " [ \033[31m\033[1mError\033[m ] $*" + else + echo " [ Error ] $*" + fi echo "" } warn (){ echo "" - echo -e " [ Warn ] $*" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarn\033[m ] $*" + else + echo " [ Warn ] $*" + fi echo "" } info (){ echo "" - echo -e " [ Info ] $*" + if $terminal ; then + echo -e " [ \033[32m\033[1mInfo\033[m ] $*" + else + echo " [ Info ] $*" + fi echo "" } ok (){ echo "" - echo -e " [ Ok ] $*" + if $terminal ; then + echo -e " [ \033[32m\033[1mOk\033[m ] $*" + else + echo " [ Ok ] $*" + fi echo "" } @@ -86,8 +115,8 @@ trim() { #--------------------------------------- if [[ -t 1 ]] ; then - terminal=true - LOGGING=true + terminal=true + LOGGING=true else terminal=false LOGGING=false @@ -113,6 +142,12 @@ if [ -z "`which realpath`" ]; then fatal 'It seems "realpath" is not installed, but needed!' fi +if $check_apache || $check_nginxA ; then + if [ -z "$(which curl)" ]; then + fatal 'It seems "curls" is not installed, but needed!' + fi +fi + if $check_load ; then if [ -z "`which bc`" ]; then fatal 'It seems "bc" is not installed, but needed!' @@ -244,6 +279,46 @@ if $check_apache ; then fi fi +if $check_nginx ; then + + NGINXD="$(realpath $(which nginx))" + if [ -z "$NGINXD" ]; then + if [ -x "/usr/local/nginx/bin/nginx" ]; then + NGINXD="$(realpath "/usr/local/nginx/bin/nginx")" + elif [ -x "/usr/local/nginx/sbin/nginx" ]; then + NGINXD="$(realpath "/usr/local/nginx/sbin/nginx")" + else + fatal 'Command \"nginx\" not found!' + fi + fi + + NGINX_SERVICE_FILE="" + NGINX_INIT_SCRIPT="" + if $systemd_supported ; then + # - Is Service exclusive controlled by systemd + # - + if systemctl -t service list-unit-files \ + | grep -e "^nginx" \ + | grep -q -E "(enabled|disabled)" 2> /devnull ; then + + NGINX_SERVICE_FILE=$(systemctl -t service list-unit-files \ + | grep -e "^nginx" \ + | awk '{print$1}') + fi + fi + + if [[ -z "$NGINX_SERVICE_FILE" ]] ; then + if [ -x "/etc/init.d/nginx" ]; then + NGINX_INIT_SCRIPT="/etc/init.d/nginx" + fi + fi + + if [[ -z "$NGINX_INIT_SCRIPT" ]] && [[ -z "$NGINX_SERVICE_FILE" ]] ; then + fatal "Neither an init-script nor a service file for 'nginx' webservice found!" + fi + +fi + declare -A start_stop_method_php_fpm declare -A start_stop_file_php_fpm declare -A php_fpm_ping_path @@ -319,6 +394,44 @@ if $check_php_fpm ; then done fi +if $check_redis ; then + + REDISD="$(realpath $(which redis-server))" + if [ -z "$REDISD" ]; then + if [ -x "/usr/sbin/redis-server" ]; then + REDISD="/usr/sbin/redis-server" + else + fatal 'Command \"redis-server\" not found!' + fi + fi + + REDIS_SERVICE_FILE="" + REDIS_INIT_SCRIPT="" + if $systemd_supported ; then + # - Is Service exclusive controlled by systemd + # - + if systemctl -t service list-unit-files \ + | grep -e "^redis-server" \ + | grep -q -E "(enabled|disabled)" 2> /devnull ; then + + REDIS_SERVICE_FILE=$(systemctl -t service list-unit-files \ + | grep -e "^redis-server" \ + | awk '{print$1}') + fi + fi + + if [[ -z "$REDIS_SERVICE_FILE" ]] ; then + if [ -x "/etc/init.d/redis-server" ]; then + REDIS_INIT_SCRIPT="/etc/init.d/redis-server" + fi + fi + + if [[ -z "$REDIS_INIT_SCRIPT" ]] && [[ -z "$REDIS_SERVICE_FILE" ]] ; then + fatal "Neither an init-script nor a service file for 'nginx' webservice found!" + fi + +fi + if $check_website ; then if [[ -n "$php_version_of_working_url" ]] && [[ "$php_version_of_working_url" != "None" ]] ; then @@ -468,6 +581,69 @@ stop_apache() { i=i+1 done +} + +stop_nginx() { + + send_msg=$1 + send_msg=${send_msg:=true} + + ## - Stop Nginx Webservice + ## - + if [[ -n "$NGINX_SERVICE_FILE" ]] ; then + systemctl stop "$NGINX_SERVICE_FILE" > /dev/null 2>&1 + else + $NGINX_INIT_SCRIPT stop > /dev/null 2>&1 + fi + + sleep 12 + + declare -i i=0 + PIDS=$(ps aux | grep "$NGINXD" | grep -v grep | awk '{print$2}') + + while [ "X$PIDS" != "X" ]; do + + if [ $i -eq 0 ]; then + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Error ]: Stopping Nginx Webservice failed !!!" >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Info ]; Going to kill remaining nginx-processes.." >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + error "Stopping Nginx Webservice failed !!!" + info "Going to kill remaining nginx-processes.." + fi + + if [ $i -gt 10 ]; then + + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Error ]: Killing remaining nginx-processes failed !!!" >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + error "Killing remaining nginx-processes failed !!!" + + if $send_msg ; then + + subject="[ Error ]: Stopping Nginx Webservice on `hostname -f` failed -- $datum" + msg="\n\n`cat $LOCK_DIR/extra_msg.txt`\n" + + for _to_address in $to_addresses ; do + echo -e "To:${_to_address}\n${content_type}\nSubject:$subject\n\n${msg}\n" \ + | /usr/sbin/sendmail -F "Webservice Monitor" -f $from_address $_to_address + done + + fi + + break + fi + + for _PID in $PIDS ; do + kill -9 $_PID > /dev/null 2>&1 + done + sleep 2 + PIDS=$(ps aux | grep "$NGINXD" | grep -v grep | awk '{print$2}') + i=i+1 + done } @@ -654,6 +830,70 @@ stop_php_fpm() { } +stop_redis() { + + send_msg=$1 + send_msg=${send_msg:=true} + + ## - Stop Redis Caching Service + ## - + if [[ -n "$REDIS_SERVICE_FILE" ]] ; then + systemctl stop "$REDIS_SERVICE_FILE" > /dev/null 2>&1 + else + $REDIS_INIT_SCRIPT stop > /dev/null 2>&1 + fi + + sleep 12 + + declare -i i=0 + PIDS=$(ps aux | grep "$REDISD" | grep -v grep | awk '{print$2}') + + while [ "X$PIDS" != "X" ]; do + + if [ $i -eq 0 ]; then + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Error ]: Stopping Redis Caching Sservice failed !!!" >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Info ]; Going to kill remaining 'redis-server'-processes.." >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + error "Stopping Redis Caching Service failed !!!" + info "Going to kill remaining 'redis-server'-processes.." + fi + + if [ $i -gt 10 ]; then + + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Error ]: Killing remaining 'redis-server'-processes failed !!!" >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + error "Killing remaining 'redis-server'-processes failed !!!" + + if $send_msg ; then + + subject="[ Error ]: Stopping Redis Caching Service on `hostname -f` failed -- $datum" + msg="\n\n`cat $LOCK_DIR/extra_msg.txt`\n" + + for _to_address in $to_addresses ; do + echo -e "To:${_to_address}\n${content_type}\nSubject:$subject\n\n${msg}\n" \ + | /usr/sbin/sendmail -F "Webservice Monitor" -f $from_address $_to_address + done + + fi + + break + fi + + for _PID in $PIDS ; do + kill -9 $_PID > /dev/null 2>&1 + done + sleep 2 + PIDS=$(ps aux | grep "$REDISD" | grep -v grep | awk '{print$2}') + i=i+1 + done + +} + start_mysql() { send_msg=$1 @@ -765,6 +1005,63 @@ start_apache() { fi } +start_nginx() { + + send_msg=$1 + send_msg=${send_msg:=true} + + + ## - Start Nginx Webservice + ## - + if [[ -n "$NGINX_SERVICE_FILE" ]] ; then + systemctl start "$NGINX_SERVICE_FILE" > /dev/null 2>&1 + else + $NGINX_INIT_SCRIPT start > /dev/null 2>&1 + fi + sleep 2 + + NEWPID=$(ps aux | grep "$NGINXD" | grep -v grep | grep root | awk '{print$2}') + + if [ "X${NEWPID}X" = "XX" ]; then + + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Error ]: I started the 'Nginx' webserver, but service is not running !!!" >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + error "I started the 'Nginx' webserver, but service is not running !!!" + + datum=`date +"%d.%m.%Y %H:%Mh"` + + subject="[ Error ]: Nginx Webservice on `hostname -f` NOT RUNNING -- $datum" + msg="\n\n`cat $LOCK_DIR/extra_msg.txt`\n" + + for _to_address in $to_addresses ; do + echo -e "To:${_to_address}\n${content_type}\nSubject:$subject\n\n${msg}\n" \ + | /usr/sbin/sendmail -F "Webservice Monitor" -f $from_address $_to_address + done + + else + + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\tI started the 'Nginx' webserver. the new PID is $NEWPID" >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + ok "I started the 'NGINX' webserver. the new PID is $NEWPID" + + fi + + if $send_msg ; then + datum=`date +"%d.%m.%Y %H:%Mh"` + subject="Restarting Nginx on `hostname -f` invoked -- $datum" + msg=`cat $LOCK_DIR/extra_msg.txt` + + for _to_address in $to_addresses ; do + echo -e "To:${_to_address}\n${content_type}\nSubject:$subject\n\n${msg}\n" \ + | /usr/sbin/sendmail -F "Webservice Monitor" -f $from_address $_to_address + done + fi +} + start_php_fpm() { __version=$1 @@ -833,6 +1130,63 @@ start_php_fpm() { fi } +start_redis() { + + send_msg=$1 + send_msg=${send_msg:=true} + + + ## - Start Redis Caching Service + ## - + if [[ -n "$REDIS_SERVICE_FILE" ]] ; then + systemctl start "$REDIS_SERVICE_FILE" > /dev/null 2>&1 + else + $REDIS_INIT_SCRIPT start > /dev/null 2>&1 + fi + sleep 2 + + NEWPID=$(ps aux | grep "$REDISD" | grep -v grep | awk '{print$2}') + + if [ "X${NEWPID}X" = "XX" ]; then + + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Error ]: I started the 'Redis' Server, but service is not running !!!" >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + error "I started the 'Redis' Server, but service is not running !!!" + + datum=`date +"%d.%m.%Y %H:%Mh"` + + subject="[ Error ]: Redis Caching Service on `hostname -f` NOT RUNNING -- $datum" + msg="\n\n`cat $LOCK_DIR/extra_msg.txt`\n" + + for _to_address in $to_addresses ; do + echo -e "To:${_to_address}\n${content_type}\nSubject:$subject\n\n${msg}\n" \ + | /usr/sbin/sendmail -F "Webservice Monitor" -f $from_address $_to_address + done + + else + + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\tI started the 'Redis' Server. the new PID is $NEWPID" >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + ok "I started the 'Redis' Server. the new PID is $NEWPID" + + fi + + if $send_msg ; then + datum=`date +"%d.%m.%Y %H:%Mh"` + subject="Restarting Redis Server on `hostname -f` invoked -- $datum" + msg=`cat $LOCK_DIR/extra_msg.txt` + + for _to_address in $to_addresses ; do + echo -e "To:${_to_address}\n${content_type}\nSubject:$subject\n\n${msg}\n" \ + | /usr/sbin/sendmail -F "Webservice Monitor" -f $from_address $_to_address + done + fi +} + restart_apache() { ## - Stop Apache Webservice @@ -846,6 +1200,19 @@ restart_apache() { start_apache } +restart_nginx() { + + ## - Stop Apache Webservice + ## - + stop_nginx + + sleep 2 + + ## - Start Apache Webservice + ## - + start_nginx +} + restart_mysql(){ ## - Stop MySQL Servive @@ -872,6 +1239,19 @@ restart_php_fpm(){ start_php_fpm $1 } +restart_redis(){ + + ## - Stop MySQL Servive + ## - + stop_redis + + sleep 2 + + ## - Start MySQL Service + ## - + start_redis +} + graceful_restart_php_fpm() { __version=$1 @@ -1176,6 +1556,50 @@ if $check_apache ; then fi +#--------------------------------------- +#----------------------------- +# Check Nginx webservice.. +#----------------------------- +#--------------------------------------- + +if $check_nginx ; then + + echo "" > $LOCK_DIR/extra_msg.txt + + if $LOGGING ; then + echo -e "\nChecking Nginx webservice on \"`hostname -f`\".." + fi + + PID=`ps aux | grep "$NGINXD " | grep -e "^root" | grep -v grep | awk '{print$2}'` + if [ "X${PID}X" = "XX" ];then + + echo -e "\nNginx Webservice is not running! - Try to start it.." > $LOCK_DIR/extra_msg.txt + echo -e "====================================================" >> $LOCK_DIR/extra_msg.txt + + error "Nginx webservice is not running! - Try to start it.." + + restart_nginx + + else + + if ! $(curl -Is -m 10 http://$curl_check_host | head -n 1 | grep "200 OK" > /dev/null) ; then + echo -e "\nNginx Webservice seems to be running, but is NOT responding! - Try to restart service.." >> $LOCK_DIR/extra_msg.txt + echo -e "=======================================================================================" >> $LOCK_DIR/extra_msg.txt + + error "Nginx Webservice seems to be running, but is NOT responding! - Try to restart service.." + + restart_nginx + + else + + if $LOGGING ; then + ok "Nginx Webserver on \"`hostname -f`\" seems to be running.." + fi + fi + fi +fi + + #--------------------------------------- #----------------------------- # Check PHP-FPM engine.. @@ -1223,6 +1647,40 @@ if $check_php_fpm ; then fi +#--------------------------------------- +#----------------------------- +# Check Redis Caching Service.. +#----------------------------- +#--------------------------------------- + +if $check_nginx ; then + + echo "" > $LOCK_DIR/extra_msg.txt + + if $LOGGING ; then + echo -e "\nChecking Redis Caching Service on \"`hostname -f`\".." + fi + + PID=`ps aux | grep "$REDISD " | grep -v grep | awk '{print$2}'` + if [ "X${PID}X" = "XX" ];then + + echo -e "\nRedis Caching Service is not running! - Try to start it.." > $LOCK_DIR/extra_msg.txt + echo -e "=========================================================" >> $LOCK_DIR/extra_msg.txt + + error "Redis Caching Service is not running! - Try to start it.." + + restart_redis + + else + + if $LOGGING ; then + ok "Redis Caching Service on \"`hostname -f`\" seems to be running.." + fi + + fi +fi + + #--------------------------------------- #----------------------------- # Check website.. diff --git a/conf/check_webservice_load.conf.sample b/conf/check_webservice_load.conf.sample index a686268..8bb4df7 100644 --- a/conf/check_webservice_load.conf.sample +++ b/conf/check_webservice_load.conf.sample @@ -19,7 +19,9 @@ check_load=true check_mysql=true check_apache=true +check_nginx=false check_php_fpm=true +check_redis=false check_website=false From e8b48b9bb352c2ee78d12e1e30bba75673866b62 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 23 Apr 2018 02:28:26 +0200 Subject: [PATCH 39/45] check_webservice_load.sh: fix typo. --- check_webservice_load.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index e98a13f..06d99e4 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -144,7 +144,7 @@ fi if $check_apache || $check_nginxA ; then if [ -z "$(which curl)" ]; then - fatal 'It seems "curls" is not installed, but needed!' + fatal 'It seems "curl" is not installed, but needed!' fi fi From 8d199d4c5753d13c585bf3f2f65aedc69947f342 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 23 Apr 2018 03:44:29 +0200 Subject: [PATCH 40/45] check_webservice_load.sh: fix error for nginx service. --- conf/check_webservice_load.conf.sample | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/conf/check_webservice_load.conf.sample b/conf/check_webservice_load.conf.sample index 8bb4df7..2b07663 100644 --- a/conf/check_webservice_load.conf.sample +++ b/conf/check_webservice_load.conf.sample @@ -24,6 +24,17 @@ check_php_fpm=true check_redis=false check_website=false +# - If service is not listen on 127.0.0.1/loclhost, curl check must +# - be ommited +# - +ommit_curl_check_nginx=false + +# - Is this a vserver guest machine? +# - +# - Not VSerber guest host does not support systemd! +# - +vserver_guest=false + # - Additional Settings for check_mysql # - From 32cfd87a79cfa640a8c7c3bda8c994d7ae216b81 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 23 Apr 2018 03:57:21 +0200 Subject: [PATCH 41/45] Adjust check_webservice_load.conf.sample. --- conf/check_webservice_load.conf.sample | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/conf/check_webservice_load.conf.sample b/conf/check_webservice_load.conf.sample index 2b07663..e7db7cd 100644 --- a/conf/check_webservice_load.conf.sample +++ b/conf/check_webservice_load.conf.sample @@ -27,13 +27,17 @@ check_website=false # - If service is not listen on 127.0.0.1/loclhost, curl check must # - be ommited # - -ommit_curl_check_nginx=false +# - Defaults to: ommit_curl_check_nginx=false +# - +#ommit_curl_check_nginx=false # - Is this a vserver guest machine? # - # - Not VSerber guest host does not support systemd! # - -vserver_guest=false +# - defaults to: vserver_guest=false +# - +#vserver_guest=false # - Additional Settings for check_mysql From d02b25089e55895ac00b2f470de9495f3b574fd7 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 23 Apr 2018 11:20:18 +0200 Subject: [PATCH 42/45] check_webservice_load.sh: - support of parameter ommit_curl_check_nginx (don't make additional curl check) - fix error for VServer guet systems (set 'systemd_supported* to false). - fix error at stopping nginx (kill remaining subprocesses 'nginx:'). --- check_webservice_load.sh | 60 ++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index 06d99e4..de20f05 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -20,6 +20,9 @@ check_php_fpm=false check_redis=false check_website=false +ommit_curl_check_nginx=false +vserver_guest=false + if [[ ! -f "$conf_file" ]]; then echo "" echo -e " [ Fatal ] Configuration file '$(basename ${conf_file})' not found!" @@ -156,12 +159,16 @@ fi # - Systemd supported ? ## - -systemd=$(which systemd) -systemctl=$(which systemctl) - systemd_supported=false -if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then - systemd_supported=true + +if ! $vserver_guest ; then + + systemd=$(which systemd) + systemctl=$(which systemctl) + + if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true + fi fi @@ -638,13 +645,32 @@ stop_nginx() { fi for _PID in $PIDS ; do - kill -9 $_PID > /dev/null 2>&1 + kill $_PID > /dev/null 2>&1 done + sleep 2 PIDS=$(ps aux | grep "$NGINXD" | grep -v grep | awk '{print$2}') i=i+1 done + SUB_PIDS=$(ps aux | grep "$(basename $NGINXD):" | grep -v grep | awk '{print$2}') + + if [[ "X${SUB_PIDS}X" != 'XX' ]]; then + + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Error ]: Found processes '$(basename $NGINXD):'." >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Info ]; Going to kill remaining nginx-processes.." >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + error "Found processes '$(basename $NGINXD):'." + info "Going to kill processes '$(basename $NGINXD):'.." + + for _PID in $SUB_PIDS ; do + kill $_PID > /dev/null 2>&1 + done + fi + } stop_mysql() { @@ -1570,7 +1596,7 @@ if $check_nginx ; then echo -e "\nChecking Nginx webservice on \"`hostname -f`\".." fi - PID=`ps aux | grep "$NGINXD " | grep -e "^root" | grep -v grep | awk '{print$2}'` + PID=`ps aux | grep "$NGINXD" | grep -e "^root" | grep -v grep | awk '{print$2}'` if [ "X${PID}X" = "XX" ];then echo -e "\nNginx Webservice is not running! - Try to start it.." > $LOCK_DIR/extra_msg.txt @@ -1581,20 +1607,30 @@ if $check_nginx ; then restart_nginx else + if ! $ommit_curl_check_nginx ; then - if ! $(curl -Is -m 10 http://$curl_check_host | head -n 1 | grep "200 OK" > /dev/null) ; then - echo -e "\nNginx Webservice seems to be running, but is NOT responding! - Try to restart service.." >> $LOCK_DIR/extra_msg.txt - echo -e "=======================================================================================" >> $LOCK_DIR/extra_msg.txt + if ! $(curl -Is -m 10 http://$curl_check_host | head -n 1 | grep "200 OK" > /dev/null) ; then + echo -e "\nNginx Webservice seems to be running, but is NOT responding! - Try to restart service.." >> $LOCK_DIR/extra_msg.txt + echo -e "=======================================================================================" >> $LOCK_DIR/extra_msg.txt - error "Nginx Webservice seems to be running, but is NOT responding! - Try to restart service.." + error "Nginx Webservice seems to be running, but is NOT responding! - Try to restart service.." - restart_nginx + restart_nginx + + else + + if $LOGGING ; then + ok "Nginx Webserver on \"`hostname -f`\" seems to be running.." + fi + + fi else if $LOGGING ; then ok "Nginx Webserver on \"`hostname -f`\" seems to be running.." fi + fi fi fi From 96bdb83da0633f89bcdacc2bdadf18399e142b45 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 23 Apr 2018 13:10:46 +0200 Subject: [PATCH 43/45] check_webservice_load.sh: fix errors for redis-server check. --- check_webservice_load.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index de20f05..4b79c9f 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -403,7 +403,7 @@ fi if $check_redis ; then - REDISD="$(realpath $(which redis-server))" + REDISD="$(which redis-server)" if [ -z "$REDISD" ]; then if [ -x "/usr/sbin/redis-server" ]; then REDISD="/usr/sbin/redis-server" @@ -1689,7 +1689,7 @@ fi #----------------------------- #--------------------------------------- -if $check_nginx ; then +if $check_redis ; then echo "" > $LOCK_DIR/extra_msg.txt @@ -1697,7 +1697,7 @@ if $check_nginx ; then echo -e "\nChecking Redis Caching Service on \"`hostname -f`\".." fi - PID=`ps aux | grep "$REDISD " | grep -v grep | awk '{print$2}'` + PID=`ps aux | grep "$REDISD" | grep -v grep | awk '{print$2}'` if [ "X${PID}X" = "XX" ];then echo -e "\nRedis Caching Service is not running! - Try to start it.." > $LOCK_DIR/extra_msg.txt From 51a38fc061fd3bd93dde86a600c8c9b9b296b00e Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 23 Apr 2018 17:49:42 +0200 Subject: [PATCH 44/45] check_webservice_load.sh: add support for PostgreSQL Service --- check_webservice_load.sh | 224 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 223 insertions(+), 1 deletion(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index 4b79c9f..ec663cb 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -14,6 +14,7 @@ conf_file="${working_dir}/conf/check_webservice_load.conf" # - check_load=false check_mysql=false +check_postgresql=false check_apache=false check_nginx=false check_php_fpm=false @@ -243,6 +244,35 @@ if $check_mysql ; then fi +if $check_postgresql ; then + + PSQL_SERVICE_FILE="" + PSQL_INIT_SCRIPT="" + if $systemd_supported ; then + # - Is Service exclusive controlled by systemd + # - + if systemctl -t service list-unit-files \ + | grep -e "^ postgresql" \ + | grep -q -E "(enabled|disabled)" 2> /devnull ; then + + PSQL_SERVICE_FILE=$(systemctl -t service list-unit-files \ + | grep -e "^postgresql" \ + | awk '{print$1}') + fi + fi + + if [[ -z "$PSQL_SERVICE_FILE" ]] ; then + if [ -x "/etc/init.d/postgresql" ]; then + PSQL_INIT_SCRIPT="/etc/init.d/postgresql" + fi + fi + + if [[ -z "$PSQL_INIT_SCRIPT" ]] && [[ -z "$PSQL_SERVICE_FILE" ]] ; then + fatal "Neither an init-script nor a service file for 'postgesql' databaseservice found!" + fi + +fi + if $check_apache ; then HTTPD=`realpath $(which httpd) 2>/dev/null` @@ -739,6 +769,91 @@ stop_mysql() { fi } +stop_postgresql() { + + send_msg=$1 + send_msg=${send_msg:=true} + + ## - Stop PostgreSQL database service + ## - + if [[ -n "$PSQL_SERVICE_FILE" ]] ; then + systemctl stop "$PSQL_SERVICE_FILE" > /dev/null 2>&1 + else + $PSQL_INIT_SCRIPT stop > /dev/null 2>&1 + fi + + sleep 12 + + declare -i i=0 + + CHILD_PID="$(ps aux | grep -E "\ postgres:\ " | grep -v grep | tail -n 1 | awk '{print$2}')" + PSQL_MAIN_PID="$(ps -o ppid= -p $CHILD_PID 2> /dev/null)" + + while [ "X$PSQL_MAIN_PID" != "X" ]; do + + if [ $i -eq 0 ]; then + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Error ]: Stopping PostgreSQL database service failed !!!" >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Info ]; Going to kill remaining postgres-processes.." >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + error "Stopping PostgreSQL database service failed !!!" + info "Going to kill remaining postgres-processes.." + fi + + if [ $i -gt 10 ]; then + + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Error ]: Killing remaining postgres-processes failed !!!" >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + error "Killing remaining postgres-processes failed !!!" + + if $send_msg ; then + + subject="[ Error ]: Stopping PostgreSQL database service on `hostname -f` failed -- $datum" + msg="\n\n`cat $LOCK_DIR/extra_msg.txt`\n" + + for _to_address in $to_addresses ; do + echo -e "To:${_to_address}\n${content_type}\nSubject:$subject\n\n${msg}\n" \ + | /usr/sbin/sendmail -F "Webservice Monitor" -f $from_address $_to_address + done + + fi + + break + fi + + kill $PSQL_MAIN_PID > /dev/null 2>&1 + + sleep 2 + + CHILD_PID="$(ps aux | grep -E "\ postgres:\ " | grep -v grep | tail -n 1 | awk '{print$2}')" + PSQL_MAIN_PID="$(ps -o ppid= -p $CHILD_PID)" + i=i+1 + done + + CHILD_PIDS=$(ps aux | grep -E "postgres:" | grep -v grep | awk '{print$2}') + + if [[ "X${CHILD_PIDS}X" != 'XX' ]]; then + + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Error ]: Found processes 'postgres:'." >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Info ]; Going to kill remaining postgres-processes.." >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + error "Found processes 'postgres:'." + info "Going to kill processes 'postgres:'.." + + for _PID in $CHILD_PIDS ; do + kill $_PID > /dev/null 2>&1 + done + fi + +} + stop_php_fpm() { __version=$1 @@ -974,6 +1089,64 @@ start_mysql() { fi } +start_postgresql() { + + send_msg=$1 + send_msg=${send_msg:=true} + + + ## - Start PostgreSQL Webservice + ## - + if [[ -n "$PSQL_SERVICE_FILE" ]] ; then + systemctl start "$PSQL_SERVICE_FILE" > /dev/null 2>&1 + else + $PSQL_INIT_SCRIPT start > /dev/null 2>&1 + fi + sleep 2 + + CHILD_PID="$(ps aux | grep -E "\ postgres:\ " | grep -v grep | tail -n 1 | awk '{print$2}')" + NEWPID="$(ps -o ppid= -p $CHILD_PID 2> /dev/null)" + + if [ "X${NEWPID}X" = "XX" ]; then + + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\t[ Error ]: I started the 'PostgreSQL' database server, but service is not running !!!" >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + error "I started the 'PostgreSQL' database server, but service is not running !!!" + + datum=`date +"%d.%m.%Y %H:%Mh"` + + subject="[ Error ]: PostgreSQL database service on `hostname -f` NOT RUNNING -- $datum" + msg="\n\n`cat $LOCK_DIR/extra_msg.txt`\n" + + for _to_address in $to_addresses ; do + echo -e "To:${_to_address}\n${content_type}\nSubject:$subject\n\n${msg}\n" \ + | /usr/sbin/sendmail -F "Webservice Monitor" -f $from_address $_to_address + done + + else + + echo "" >> $LOCK_DIR/extra_msg.txt + echo -e "\tI started the 'PostgreSQL' database server. the new PID is $NEWPID" >> $LOCK_DIR/extra_msg.txt + echo "" >> $LOCK_DIR/extra_msg.txt + + ok "I started the 'PostgreSQL' database server. the new PID is $NEWPID" + + fi + + if $send_msg ; then + datum=`date +"%d.%m.%Y %H:%Mh"` + subject="Restarting PostgreSQL on `hostname -f` invoked -- $datum" + msg=`cat $LOCK_DIR/extra_msg.txt` + + for _to_address in $to_addresses ; do + echo -e "To:${_to_address}\n${content_type}\nSubject:$subject\n\n${msg}\n" \ + | /usr/sbin/sendmail -F "Webservice Monitor" -f $from_address $_to_address + done + fi +} + start_apache() { send_msg=$1 @@ -1241,7 +1414,7 @@ restart_nginx() { restart_mysql(){ - ## - Stop MySQL Servive + ## - Stop MySQL Service ## - stop_mysql @@ -1252,6 +1425,19 @@ restart_mysql(){ start_mysql } +restart_postgresql(){ + + ## - Stop PostgreSQL Service + ## - + stop_postgresql + + sleep 2 + + ## - Start MySQL Service + ## - + start_postgresql +} + restart_php_fpm(){ ## - Stop MySQL Servive @@ -1532,6 +1718,42 @@ if $check_mysql ; then fi +#--------------------------------------- +#----------------------------- +# Check Postgresql database service.. +#----------------------------- +#--------------------------------------- + +if $check_postgresql ; then + + echo "" > $LOCK_DIR/extra_msg.txt + + if $LOGGING ; then + echo -e "\nChecking PostgreSQL database service on \"`hostname -f`\".." + fi + + CHILD_PID="$(ps aux | grep -E "\ postgres:\ " | grep -v grep | tail -n 1 | awk '{print$2}')" + PSQL_MAIN_PID="$(ps -o ppid= -p $CHILD_PID 2> /dev/null)" + + if [ "X${PSQL_MAIN_PID}X" = "XX" ];then + + echo -e "\nPostgreSQL database service is not running! - Try to start it.." > $LOCK_DIR/extra_msg.txt + echo -e "===============================================================" >> $LOCK_DIR/extra_msg.txt + + error "PostgeSQL database service is not running! - Try to start it.." + + restart_postgresql + + else + + if $LOGGING ; then + ok "PostgreSQL database server on \"`hostname -f`\" seems to be running.." + fi + + fi +fi + + #--------------------------------------- #----------------------------- # Check Apache webservice.. From 912c69a735b7022c0664fcbf2015c4190d3a3b33 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 23 Apr 2018 17:55:02 +0200 Subject: [PATCH 45/45] Adjust 'check_webservice_load.conf.sample', add 'check_postgresql'. --- conf/check_webservice_load.conf.sample | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/conf/check_webservice_load.conf.sample b/conf/check_webservice_load.conf.sample index e7db7cd..8df392f 100644 --- a/conf/check_webservice_load.conf.sample +++ b/conf/check_webservice_load.conf.sample @@ -18,6 +18,13 @@ # - check_load=true check_mysql=true + +# - PostgreSQL +# - +# - NOT useful, if more than one PostgreSQL instances are running! +# - +check_postgresql=false + check_apache=true check_nginx=false check_php_fpm=true