check_webservice_load.sh: add support of 'MariaDB'.
This commit is contained in:
parent
b6bbf99bea
commit
d633fdc223
@ -20,6 +20,7 @@ LOCK_DIR="/tmp/${script_name%%.*}.LOCK"
|
||||
# -
|
||||
check_load=false
|
||||
check_mysql=false
|
||||
check_mariadb=false
|
||||
check_postgresql=false
|
||||
check_apache=false
|
||||
check_nginx=false
|
||||
@ -179,6 +180,9 @@ DEFAULT_CONFLICTING_SCRIPTS="/root/bin/monitoring/check_local_webservice.sh"
|
||||
DEFAULT_TIMEOUT_CHECK_WEBSITE=10
|
||||
DEFAULT_TIMEOUT_CHECK_PHP=10
|
||||
|
||||
DEFAULT_mysql_credential_args="--login-path=local"
|
||||
DEFAULT_mariadb_credential_args=""
|
||||
|
||||
if [[ ! -f "$conf_file" ]]; then
|
||||
echo ""
|
||||
echo -e " [ Fatal ] Configuration file '$(basename ${conf_file})' not found!"
|
||||
@ -195,6 +199,9 @@ fi
|
||||
|
||||
[[ -n "$CONFLICTING_SCRIPTS" ]] || CONFLICTING_SCRIPTS="$DEFAULT_CONFLICTING_SCRIPTS"
|
||||
|
||||
[[ -n "$mysql_credential_args" ]] || mysql_credential_args="$DEFAULT_mysql_credential_args"
|
||||
[[ -n "$mariadb_credential_args" ]] || mariadb_credential_args="$DEFAULT_mariadb_credential_args"
|
||||
|
||||
|
||||
# - Stop here, if these give scripts are running
|
||||
# -
|
||||
@ -340,6 +347,77 @@ if ! $vserver_guest ; then
|
||||
fi
|
||||
|
||||
|
||||
if $check_mariadb ; then
|
||||
|
||||
MARIADBD="$(realpath $(which mariadbd) 2>/dev/null)"
|
||||
if [ -z "$MARIADBD" ]; then
|
||||
if [ -x "/usr/local/mysql/bin/mariadbd" ]; then
|
||||
MARIADBD="$(realpath "/usr/local/mysql/bin/mariadbd")"
|
||||
else
|
||||
fatal 'Command \"mariadbd\" not found!'
|
||||
fi
|
||||
fi
|
||||
|
||||
MARIADB_INIT_SCRIPT=""
|
||||
MARIADBD_SERVICE_FILE=""
|
||||
if $systemd_supported ; then
|
||||
# - Is Service exclusive controlled by systemd
|
||||
# -
|
||||
if systemctl -t service list-unit-files \
|
||||
| grep -e "^mariadb" \
|
||||
| grep -q -E "(enabled|disabled)" 2> /dev/null ; then
|
||||
MARIADBD_SERVICE_FILE=$(systemctl -t service list-unit-files \
|
||||
| grep -e "^mariadb.*.service" \
|
||||
| grep -E " enabled" \
|
||||
| awk '{print$1}'\
|
||||
| head -1)
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if [[ -z "$MARIADBD_SERVICE_FILE" ]] ; then
|
||||
if [ -x "$(realpath /etc/init.d/mariadb.server)" ]; then
|
||||
MARIADB_INIT_SCRIPT="/etc/init.d/mariadb.server"
|
||||
elif [ -x "$(realpath /etc/init.d/mariadb)" ]; then
|
||||
MARIADB_INIT_SCRIPT="/etc/init.d/mariadb"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$MARIADB_INIT_SCRIPT" ]] && [[ -z "$MARIADBD_SERVICE_FILE" ]]; then
|
||||
fatal 'Neither an init-script nor a service file for MariaDB found!'
|
||||
else
|
||||
MARIADB_PS_CHECK_STRING="$MARIADBD"
|
||||
fi
|
||||
|
||||
echo "MARIADB_PS_CHECK_STRING: $MARIADB_PS_CHECK_STRING"
|
||||
|
||||
if [[ -z "$MARIADB_PS_CHECK_STRING" ]]; then
|
||||
fatal "Cannot determin a check string for output of command 'ps ax'"
|
||||
fi
|
||||
|
||||
if [[ -n "$MARIADB_INIT_SCRIPT" ]] ; then
|
||||
MARIADBD_SAFE="$(realpath $(which mariadbd-safe) 2>/dev/null)"
|
||||
if [ -z "$MARIADBD_SAFE" ]; then
|
||||
if [ -x "/usr/local/mysql/bin/mariadbd-safe" ]; then
|
||||
MARIADBD_SAFE="$(realpath "/usr/local/mysql/bin/mariadbd-safe")"
|
||||
else
|
||||
fatal 'Command \"\mariadbd-safe" not found!'
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
MYADMIN="$(realpath $(which mariadb-admin) 2>/dev/null)"
|
||||
if [ -z "$MYADMIN" ]; then
|
||||
if [ -x "/usr/local/mysql/bin/mariadb-admin" ]; then
|
||||
MYADMIN="$(realpath "/usr/local/mysql/bin/mariadb-admin")"
|
||||
else
|
||||
fatal 'Command \"mariadb-admin\" not found!'
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
|
||||
if $check_mysql ; then
|
||||
|
||||
MYSQLD=`realpath $(which mysqld) 2>/dev/null`
|
||||
@ -851,6 +929,81 @@ stop_nginx() {
|
||||
|
||||
}
|
||||
|
||||
stop_mariadb() {
|
||||
|
||||
|
||||
send_msg=$1
|
||||
send_msg=${send_msg:=true}
|
||||
|
||||
# - Don't Start/Stop Services if package management is running (apt,aptitude,dpkg)
|
||||
# -
|
||||
if ( [[ "${os_dist,,}" = "debian" ]] || [[ "${os_dist,,}" = "ubuntu" ]] ) \
|
||||
&& $(lsof /var/lib/dpkg/lock >/dev/null 2>&1) ; then
|
||||
warn "It seems that package management (apt,dpkg) is running. Exiting '${FUNCNAME[0]}' now.."
|
||||
return 1
|
||||
fi
|
||||
|
||||
## - Stop MariaDB Service
|
||||
## -
|
||||
if [[ -n "$MARIADB_INIT_SCRIPT" ]]; then
|
||||
$MARIADB_INIT_SCRIPT stop > /dev/null 2>&1
|
||||
else
|
||||
systemctl stop "$MARIADBD_SERVICE_FILE" > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
_msg=false
|
||||
|
||||
sleep 5
|
||||
|
||||
declare -i i=0
|
||||
PIDS="$(ps aux | grep -E "${MARIADB_PS_CHECK_STRING}" | 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 MARIADB Service failed !!!" >> $LOCK_DIR/extra_msg.txt
|
||||
echo "" >> $LOCK_DIR/extra_msg.txt
|
||||
echo -e "\t[ Info ]; Going to kill MARIADB Processes .." >> $LOCK_DIR/extra_msg.txt
|
||||
echo "" >> $LOCK_DIR/extra_msg.txt
|
||||
|
||||
error "Stopping MARIADB Service failed !!!"
|
||||
info "Going to kill MARIADB Processes .."
|
||||
fi
|
||||
|
||||
if [ $i -gt 10 ]; then
|
||||
|
||||
echo "" >> $LOCK_DIR/extra_msg.txt
|
||||
echo -e "\t[ Error ]: Killing MARIADB Processes failed !!!" >> $LOCK_DIR/extra_msg.txt
|
||||
echo "" >> $LOCK_DIR/extra_msg.txt
|
||||
|
||||
error "Killing MARIADB Processes failed !!!"
|
||||
|
||||
_msg=true
|
||||
|
||||
break
|
||||
fi
|
||||
|
||||
for _PID in $PIDS ; do
|
||||
kill -15 $_PID > /dev/null 2>&1
|
||||
done
|
||||
|
||||
sleep 5
|
||||
|
||||
PIDS="$(ps aux | grep -E "${MARIADB_PS_CHECK_STRING}" | grep -v grep | awk '{print$2}')"
|
||||
i=i+1
|
||||
done
|
||||
|
||||
if $send_msg && $_msg ; then
|
||||
subject="[ Error ]: Stopping MARIADB Engine 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
|
||||
}
|
||||
|
||||
stop_mysql() {
|
||||
|
||||
|
||||
@ -885,11 +1038,11 @@ stop_mysql() {
|
||||
echo "" >> $LOCK_DIR/extra_msg.txt
|
||||
echo -e "\t[ Error ]: Stopping MySQL Service failed !!!" >> $LOCK_DIR/extra_msg.txt
|
||||
echo "" >> $LOCK_DIR/extra_msg.txt
|
||||
echo -e "\t[ Info ]; Going to kill MySQL Processes (mysqld_safe).." >> $LOCK_DIR/extra_msg.txt
|
||||
echo -e "\t[ Info ]; Going to kill MySQL Processes .." >> $LOCK_DIR/extra_msg.txt
|
||||
echo "" >> $LOCK_DIR/extra_msg.txt
|
||||
|
||||
error "Stopping MySQL Service failed !!!"
|
||||
info "Going to kill MySQL Processes (mysqld_safe).."
|
||||
info "Going to kill MySQL Processes .."
|
||||
fi
|
||||
|
||||
if [ $i -gt 10 ]; then
|
||||
@ -1255,6 +1408,68 @@ stop_redis() {
|
||||
|
||||
}
|
||||
|
||||
start_mariadb() {
|
||||
|
||||
send_msg=$1
|
||||
send_msg=${send_msg:=true}
|
||||
|
||||
# - Don't Start/Stop Services if package management is running (apt,aptitude,dpkg)
|
||||
# -
|
||||
if ( [[ "${os_dist,,}" = "debian" ]] || [[ "${os_dist,,}" = "ubuntu" ]] ) \
|
||||
&& $(lsof /var/lib/dpkg/lock >/dev/null 2>&1) ; then
|
||||
warn "It seems that package management (apt,dpkg) is running. Exiting '${FUNCNAME[0]}' now.."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -n "$MARIADB_INIT_SCRIPT" ]]; then
|
||||
$MARIADB_INIT_SCRIPT start > /dev/null 2>&1
|
||||
else
|
||||
systemctl start "$MARIADBD_SERVICE_FILE" > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
sleep 5
|
||||
|
||||
NEWPID="$(ps aux | grep -E "${MARIADB_PS_CHECK_STRING}" | grep -v grep | awk '{print$2}' | head -1) "
|
||||
|
||||
if [ "X${NEWPID}X" = "XX" ]; then
|
||||
|
||||
echo "" >> $LOCK_DIR/extra_msg.txt
|
||||
echo -e "\t[ Error ]: I have started the MARIADB server, but the services is not running !!!" >> $LOCK_DIR/extra_msg.txt
|
||||
echo "" >> $LOCK_DIR/extra_msg.txt
|
||||
|
||||
error "I have started the MARIADB server, but the service is not running !!!"
|
||||
|
||||
datum=`date +"%d.%m.%Y %H:%Mh"`
|
||||
|
||||
subject="[ Error ]: MARIADB 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 have started MARIADB service. The new PID is $NEWPID" >> $LOCK_DIR/extra_msg.txt
|
||||
echo "" >> $LOCK_DIR/extra_msg.txt
|
||||
|
||||
ok "I have started MARIADB service. The new PID is $NEWPID"
|
||||
fi
|
||||
|
||||
if $send_msg ; then
|
||||
datum=`date +"%d.%m.%Y %H:%Mh"`
|
||||
subject="Restarting MARIADB 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_mysql() {
|
||||
|
||||
send_msg=$1
|
||||
@ -1682,6 +1897,20 @@ restart_nginx() {
|
||||
fi
|
||||
}
|
||||
|
||||
restart_mariadb(){
|
||||
|
||||
## - Stop MySQL Service
|
||||
## -
|
||||
if stop_mariadb ; then
|
||||
|
||||
sleep 2
|
||||
|
||||
## - Start MySQL Service
|
||||
## -
|
||||
start_mariadb
|
||||
fi
|
||||
}
|
||||
|
||||
restart_mysql(){
|
||||
|
||||
## - Stop MySQL Service
|
||||
@ -1929,11 +2158,19 @@ EOF
|
||||
EOF
|
||||
|
||||
stop_apache
|
||||
if $check_mysql ; then
|
||||
stop_mysql
|
||||
elif $check_mariadb ; then
|
||||
stop_mariadb
|
||||
fi
|
||||
|
||||
sleep 60
|
||||
|
||||
if $check_mysql ; then
|
||||
start_mysql
|
||||
elif $check_mariadb ; then
|
||||
start_mariadb
|
||||
fi
|
||||
start_apache
|
||||
|
||||
else
|
||||
@ -1955,6 +2192,60 @@ EOF
|
||||
fi # End: check_load
|
||||
|
||||
|
||||
#---------------------------------------
|
||||
#-----------------------------
|
||||
# Checking MariaDB Database server..
|
||||
#-----------------------------
|
||||
#---------------------------------------
|
||||
|
||||
if $check_mariadb ; then
|
||||
|
||||
echo "" > $LOCK_DIR/extra_msg.txt
|
||||
|
||||
if $terminal ; then
|
||||
echo -e "\nChecking MariaDB databse service on \"`hostname -f`\".."
|
||||
fi
|
||||
|
||||
|
||||
PID="$(ps aux | grep -E "${MARIADB_PS_CHECK_STRING}" | grep -v grep | awk '{print$2}')"
|
||||
|
||||
echo ""
|
||||
echo "MARIADB_PS_CHECK_STRING: $MARIADB_PS_CHECK_STRING"
|
||||
echo "PID: $PID"
|
||||
echo "MYADMIN: $MYADMIN"
|
||||
echo ""
|
||||
echo "$MYADMIN $mariadb_credential_args ping 2>/dev/null"
|
||||
echo ""
|
||||
|
||||
if [ "X${PID}X" = "XX" ];then
|
||||
|
||||
echo -e "\nMariaDB is not running! - Try to restart service.." >> $LOCK_DIR/extra_msg.txt
|
||||
echo -e "=================================================" >> $LOCK_DIR/extra_msg.txt
|
||||
|
||||
error "MariaDB is not running! - Try to restart it.."
|
||||
|
||||
restart_mariadb
|
||||
|
||||
else
|
||||
if [ -z "`$MYADMIN $mariadb_credential_args ping 2>/dev/null`" ]; then
|
||||
|
||||
echo -e "\nMariaDB seems to be running, but NOT responding! - Try to restart service.." >> $LOCK_DIR/extra_msg.txt
|
||||
echo -e "=======================================================================" >> $LOCK_DIR/extra_msg.txt
|
||||
|
||||
error "MariaDB seems to be running, but NOT responding! - Try to restart service.."
|
||||
|
||||
restart_mariadb
|
||||
|
||||
else
|
||||
|
||||
if $terminal ; then
|
||||
ok "MariaDB database service on \"`hostname -f`\" seems to be running.."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
#---------------------------------------
|
||||
#-----------------------------
|
||||
# Checking MySQL Database server..
|
||||
|
@ -44,7 +44,8 @@
|
||||
# - What to check
|
||||
# -
|
||||
check_load=true
|
||||
check_mysql=true
|
||||
check_mysql=false
|
||||
check_mariadb=false
|
||||
|
||||
# - PostgreSQL
|
||||
# -
|
||||
@ -108,7 +109,7 @@ check_website=false
|
||||
# - encrypted file.
|
||||
# -
|
||||
# - Create (encrypted) option file:
|
||||
# - $ mysql_config_editor set --login-path=local --socket=/run/mysqld/mysqld.sock --user=root --password
|
||||
# - $ mysql_config_editor set --login-path=local --socket=/tmp/mysql.sock --user=root --password
|
||||
# - $ Password:
|
||||
# -
|
||||
# - Use of option file:
|
||||
@ -120,7 +121,42 @@ check_website=false
|
||||
# - mysql_credential_args="--defaults-file=/etc/mysql/debian.cnf" (Debian default)
|
||||
# - mysql_credential_args="--defaults-file=/usr/local/mysql/sys-maint.cnf"
|
||||
# -
|
||||
mysql_credential_args=""
|
||||
# - defaults to:
|
||||
# - mysql_credential_args="--login-path=local"
|
||||
# -
|
||||
#mysql_credential_args="--login-path=local"
|
||||
|
||||
|
||||
# - Additional Settings for check_mariadb
|
||||
# -
|
||||
# - MariaDB credentials
|
||||
# -
|
||||
# - Giving password on command line is insecure an sind mysql 5.5
|
||||
# - you will get a warning doing so.
|
||||
# -
|
||||
# - Reading username/password fro file ist also possible, using MySQL/MariaDB
|
||||
# - commandline parameter '--defaults-file'.
|
||||
# -
|
||||
# - Since Mysql Version 5.6, you can read username/password from
|
||||
# - encrypted file.
|
||||
# -
|
||||
# - Create (encrypted) option file:
|
||||
# - $ mysql_config_editor set --login-path=local --socket=/tmp/mysql.sock --user=root --password
|
||||
# - $ Password:
|
||||
# -
|
||||
# - Use of option file:
|
||||
# - $ mysql --login-path=local ...
|
||||
# -
|
||||
# - Example
|
||||
# - mariadb_credential_args="-u root -S /run/mysqld/mysqld.sock"
|
||||
# - mariadb_credential_args="--login-path=local"
|
||||
# - mariadb_credential_args="--defaults-file=/etc/mysql/debian.cnf" (Debian default)
|
||||
# - mariadb_credential_args="--defaults-file=/usr/local/mysql/sys-maint.cnf"
|
||||
# -
|
||||
# - defaults to empty string
|
||||
# - mariadb_credential_args=""
|
||||
# -
|
||||
#mariadb_credential_args=""
|
||||
|
||||
|
||||
# - Additional Settings for check_php_fpm
|
||||
|
Loading…
Reference in New Issue
Block a user