Files
NodeMgmt/defaults.inc
2019-02-07 09:42:25 -06:00

109 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
VERS='1.02052019'
NODE_HOSTS=10.5.10.51,10.5.10.52,10.5.10.53
NODE_SERVICES=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=(${NODE_HOSTS})
NODE_SERVICES=(${NODE_SERVICES})
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'
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'
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'
NM_SRVCOPT=(start stop restart reload enable disable)
DISP_HEADER(){
if [ "$1" = true ]; then
clear
fi
echo ""
echo -e "${idsCL[Yellow]} NodeMgmt - Galera/NGINX Node Management${idsCL[Default]} ${idsCL[DarkGray]}(ver-${VERS})${idsCL[Default]}"
DIVIDER
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
if [[ "mysql,nginx,gitea,haproxy,keepalived,maxscale" = *"${srvc}"* ]]; then spc=" "; else spc=""; fi
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
}