Files
NodeMgmt/defaults.inc
2019-02-07 14:27:16 -06:00

129 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
VERS='2.02072019'
NODEHOSTS=10.5.10.51,10.5.10.52,10.5.10.53
NODESERVICES=mysql,nginx,gitea,haproxy,keepalived,maxscale
REPL_CHECKS=
CERT_DAEMON='/usr/bin/certbot'
FOLDER=/opt/idssys/nodemgmt
SCRIPT=${FOLDER}/nodemgmt-scripts.sh
IFS=,
NODE_HOSTS=(${NODEHOSTS})
NODE_SERVICES=(${NODESERVICES})
LOCAL_SERVICES=(${LOCAL_SERVICES})
unset IFS
declare -A NM_SERVICES
NM_SERVICES['mysql']='MySQL'
NM_SERVICES['nginx']='NGINX'
NM_SERVICES['gogs']='Gogs'
NM_SERVICES['gitea']='Gitea'
NM_SERVICES['haproxy']='HAProxy'
NM_SERVICES['keepalived']='Keepalived'
NM_SERVICES['maxscale']='MaxScale'
NM_SERVICES['cmon']='CC-Controller'
NM_SERVICES['cmon-events']='CC-Events Manager'
NM_SERVICES['cmon-cloud']='CC-Cloud Daemon'
declare -A NM_SRVCOPTS
NM_SRVCOPTS['start']='Start'
NM_SRVCOPTS['stop']='Stopp'
NM_SRVCOPTS['restart']='Restart'
NM_SRVCOPTS['reload']='Reload'
NM_SRVCOPTS['enable']='Enabl'
NM_SRVCOPTS['disable']='Disabl'
NM_SRVCOPT=(start stop restart reload enable disable)
declare -A REPL_CHECKS
REPL_CHECKS['nginx']='/etc/nginx'
REPL_CHECKS['ssl']='/etc/letsencrypt'
REPL_CHECKS['php']='/etc/php'
REPL_CHECKS['www']='/var/www'
REPL_CHECKS['git']='/var/lib/gitea'
REPL_CHECKS['gitssh']='/home/git'
REPL_CHECK=(nginx ssl php www git gitssh)
declare -A REPL_DESC
REPL_DESC['nginx']='NGINX Settings'
REPL_DESC['ssl']='SSL Certificates'
REPL_DESC['php']='PHP Settings'
REPL_DESC['www']='Webserver Files'
REPL_DESC['git']='Gitea System'
REPL_DESC['gitssh']='Gitea SSH Keys'
DISP_HEADER(){
declare -i cw; declare -i spc1; declare -i c
if [ "$1" = true ]; then
clear
fi
echo ""
echo -e "${idsCL[LightGreen]} NodeMgmt - Galera/NGINX Node Management${idsCL[Default]} ${idsCL[DarkGray]}(ver-${VERS})${idsCL[Default]}"
DIVIDER . lightGreen
if [ "$2" = true ]; then
echo -e " Node hostname : ${idsST[Bold]}${idsCL[LightCyan]}${NODE_HOSTNAME}${idsCL[Default]}${idsST[Reset]}"
if [ -z ${LOCAL_SERVICES+x} ]; then SERVICES=$( IFS=$','; echo "${NODE_SERVICES[*]}" )
else SERVICES=$( IFS=$','; echo "${LOCAL_SERVICES[*]}" )
fi
IFS=,; SERVICES2=(${SERVICES}); unset IFS
for srvc in "${SERVICES2[@]}"; do
c=0; cw=18; spc=''
spc1=${cw}-${#NM_SERVICES[${srvc}]}
until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
echo -en " ${NM_SERVICES[${srvc}]}$spc: "
if [ $(pgrep ${srvc} | wc -l) -gt "0" ]; then
echo -e "${idsCL[Green]}Running${idsCL[Default]}"
else echo -e "${idsCL[Red]}Not Running${idsCL[Default]}"
fi
done
DIVIDER
fi
echo ""
}
DIVIDER(){
if [ -z ${2+x} ]; then clr='yellow'
else clr=$2
fi
echo -e "${idsCL[${clr~}]}-----------------------------------------------------------------------${idsCL[Default]}"
if [ "$1" = true ]; then
echo ""
fi
}
CERT-CHECK(){
TARGET="mysite.example.net";
RECIPIENT="hostmaster@mysite.example.net";
DAYS=7;
echo "checking if $TARGET expires in less than $DAYS days";
expirationdate=$(date -d "$(: | openssl s_client -connect $TARGET:443 -servername $TARGET 2>/dev/null \
| openssl x509 -text \
| grep 'Not After' \
|awk '{print $4,$5,$7}')" '+%s');
in7days=$(($(date +%s) + (86400*$DAYS)));
if [ $in7days -gt $expirationdate ]; then
echo "KO - Certificate for $TARGET expires in less than $DAYS days, on $(date -d @$expirationdate '+%Y-%m-%d')" \
| mail -s "Certificate expiration warning for $TARGET" $RECIPIENT ;
else
echo "OK - Certificate expires on $expirationdate";
fi
}
CHECK_HOST(){
if [ ! -z ${1+x} ]; then
ping -c 3 ${1} > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo false
else
echo true
fi
else
echo false
fi
}