check_dns.sh: redesign
check_vpn.sh: redisign check_postfix.sh: Add support for Debian 9 (stretch).
This commit is contained in:
parent
cdaa18f236
commit
762e6116d9
179
check_dns.sh
179
check_dns.sh
@ -1,20 +1,187 @@
|
|||||||
#!/usr/bin/env bash
|
#!/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"
|
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
|
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
|
if [ $? -eq 0 ]; then
|
||||||
|
|
||||||
|
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
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done;
|
done;
|
||||||
|
|
||||||
/etc/init.d/bind9 restart
|
error "Bind Nameservice seems to be down! Trying to restart service now.."
|
||||||
|
|
||||||
echo ""
|
if $systemd_supported ; then
|
||||||
echo "[ Info ]: Restartet Nameservice bind on host `hostname --long` at `date +\"%d.%m.%Y %H:%M:%S\"`"
|
$systemctl stop $service_name > /dev/null 2> ${LOCK_DIR}/err_msg.log
|
||||||
echo ""
|
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;
|
exit 0;
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
check_string_ps=""
|
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"
|
check_string_ps="/usr/lib/postfix/master"
|
||||||
elif [[ -x "/usr/libexec/postfix/master" ]] ; then
|
elif [[ -x "/usr/libexec/postfix/master" ]] ; then
|
||||||
check_string_ps="/usr/libexec/postfix/master"
|
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 "\n Check if Postfix Mailservice is running.."
|
||||||
echo -e " ========================================="
|
echo -e " ========================================="
|
||||||
fi
|
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.."
|
error "Postfix Mailservice seems to be down! Trying to restart service now.."
|
||||||
|
|
||||||
if $systemd_supported ; then
|
if $systemd_supported ; then
|
||||||
@ -133,8 +135,19 @@ if ! ps ax | grep -e "\ ${check_string_ps}" | grep -v grep > /dev/null ; then
|
|||||||
fi
|
fi
|
||||||
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!"
|
error "Restarting Postfix Mailservice failed!"
|
||||||
else
|
else
|
||||||
ok "Postfix Mailservice is up and running."
|
ok "Postfix Mailservice is up and running."
|
||||||
|
178
check_vpn.sh
178
check_vpn.sh
@ -1,13 +1,177 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
check_string_ps=""
|
||||||
|
if [[ -f "/usr/sbin/openvpn" ]] ; then
|
||||||
|
check_string_ps="/usr/sbin/openvpn --daemon"
|
||||||
|
fi
|
||||||
|
|
||||||
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"
|
# - used, if systemd is NOT supported
|
||||||
/etc/init.d/openvpn stop
|
init_script=""
|
||||||
kill -9 `cat /var/run/openvpn.server.pid 2>/dev/null` > /dev/null 2>&1
|
if [[ -x "/etc/init.d/openvpn" ]] ; then
|
||||||
rm -f /var/run/openvpn.server.pid
|
init_script="/etc/init.d/openvpn"
|
||||||
/etc/init.d/openvpn start
|
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
|
fi
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user