#!/usr/bin/env bash # NodeMgmt - Node Management Scripts NMG_ACTION="${1}" [ "${2}" != "q" ] && source /opt/idssys/defaults/colors.inc source /opt/idssys/defaults/default.inc source /opt/idssys/nodemgmt/conf/settings.conf source /opt/idssys/nodemgmt/defaults.inc [ -f /opt/idssys/nodemgmt/conf/powerwall/settings.conf ] && source /opt/idssys/nodemgmt/conf/powerwall/settings.conf source /opt/idssys/nodemgmt/inc/status.inc source /opt/idssys/nodemgmt/inc/certs.inc source /opt/idssys/nodemgmt/inc/sites.inc source /opt/idssys/nodemgmt/inc/services.inc if [ "${1}" == "report" ] || [ "${2}" == "report" ] || [ "${3}" == "report" ]; then unset idsCL idsBG idsST idsCL=('') idsBG=('') idsST=('') fi [ -f ${NM_BACKUP_FOLDER}/templates/*.config ] && rm -f ${NM_BACKUP_FOLDER}/templates/*.config OFFSITE_STATICROUTE_FIX(){ if [ ! -f ${NM_TMPFOLDER}/vpn-tunnel.down2 ]; then if [ "$(CHECK_HOST_QC 10.10.0.1)" != "true" ]; then if [ "$(CHECK_HOST_QC ${NM_OFFSITE_GW_IP})" != "false" ]; then if [ "$(CHECK_HOST_QC 10.5.0.1)" != "false" ]; then STSVPN_ADAPTER=$(${SSHCMD} root@${NM_OFFSITE_GW_IP} ip r | grep '10.5.0.0/20' | awk '{print $7}') if [ "$(${SSHCMD} root@${NM_OFFSITE_GW_IP} ip r | grep 10.10.0.0)" = "" ] && [ "${STSVPN_ADAPTER}" != "" ]; then RUN=$(${SSHCMD} root@${NM_OFFSITE_GW_IP} ip r add 10.6.1.0/24 dev ${STSVPN_ADAPTER} 2>&1 >/dev/null) RUN=$(${SSHCMD} root@${NM_OFFSITE_GW_IP} ip r add 10.10.0.0/16 dev ${STSVPN_ADAPTER} 2>&1 >/dev/null) if [ "${RUN}" == "" ]; then SENDNOTICE "Static Route to Homesite Missing" "Re-added the static route onto the Offsite UniFi Gateway" else SENDNOTICE "ERROR: Static Route to Homesite Missing" "Cannot add the static route onto the Offsite UniFi Gateway" 1 touch ${NM_TMPFOLDER}/vpn-tunnel.down fi else SENDNOTICE "ERROR: Static Route to Homesite" "The static route exists, but traffic is going nowhere homie" 1 touch ${NM_TMPFOLDER}/vpn-tunnel.down fi else SENDNOTICE "VPN to Homesite Down" "VPN is down, fix your shit first, then I'll fix mine..." 1 touch ${NM_TMPFOLDER}/vpn-tunnel.down fi fi if [ -f ${NM_TMPFOLDER}/vpn-tunnel.down ] && [ $(expr `date +%s` - $(stat -c %Y ${NM_TMPFOLDER}/vpn-tunnel.down)) -ge 630 ]; then mv ${NM_TMPFOLDER}/vpn-tunnel.down ${NM_TMPFOLDER}/vpn-tunnel.down2 fi else if [ -f ${NM_TMPFOLDER}/vpn-tunnel.down ]; then SENDNOTICE "VPN to Homesite is Back Up" "VPN Tunnel is up" rm -f ${NM_TMPFOLDER}/vpn-tunnel.down* fi fi elif [ $(expr `date +%s` - $(stat -c %Y ${NM_TMPFOLDER}/vpn-tunnel.down2)) -ge 3630 ]; then rm -f ${NM_TMPFOLDER}/vpn-tunnel.down2 touch ${NM_TMPFOLDER}/vpn-tunnel.down fi } BACKUP(){ BACKUP_FOLDER=${NM_BACKUP_FOLDER}/node-backup/$(date +%m-%d-%y)/$(date +%H-%M-%S) [ ! -d ${BACKUP_FOLDER} ] && mkdir -p ${BACKUP_FOLDER} echo -e "\n" echo -e "Configured Backup Folder: ${idsCL[Yellow]}${NM_BACKUP_FOLDER}${idsCL[Default]}" echo echo -e "Backup path to use: ${idsCL[Yellow]}${BACKUP_FOLDER}${idsCL[Default]}" echo echo -e "${idsCL[Green]}Backing up Node Settings and Files...${idsCL[Default]}" DIVIDER true for item in "${!NM_BACKUP_ITEMS[@]}"; do c=0; spc=''; spc1=`expr 20 - ${#item}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done echo -en "Backing up '${idsCL[LightCyan]}${item}${idsCL[Default]}'${spc}" if [ -d ${NM_BACKUP_ITEMS[$item]} ]; then tar -czPf ${BACKUP_FOLDER}/${item}.tar.gz -C ${NM_BACKUP_ITEMS[$item]} . --exclude='./data/repository' --exclude='*/.stfolder' --exclude='*/.stversions' --exclude='*/.git' --exclude='*.example.*' >/dev/null 2>&1 echo -e "${idsCL[Green]}Done${idsCL[Default]}" else echo -e "${idsCL[Yellow]}Not found${idsCL[Default]}" fi done touch ${NM_LOGFOLDER}/backup.lastrun echo DIVIDER echo -e "${idsCL[Green]}Backups are completed\n\n" if [ -z ${NMG_ACTION} ] || [ "${NMG_ACTION}" = "gui" ]; then ENTER2CONTINUE fi } SET-PERMISSIONS(){ if [ "${1}" = "gitea" ]; then for nip in "${NM_HOSTS['WEB'][@]}"; do if [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then NCMD='' else NCMD="${SSHCMD} root@${nip}" fi if [ "${2}" != "q" ]; then echo -en "${idsCL[Yellow]}Resetting folder permissions for Gitea on ${NM_HOSTNAMES[${nip}]} (${nip})... ${idsCL[Default]}" fi checkhost=$(CHECK_HOST ${nip}) if [ "${checkhost}" != "false" ]; then ${NCMD} chown -R git:git ${NM_REPL_CHECK_LOC['gitea']} ${NCMD} chmod -R 750 ${NM_REPL_CHECK_LOC['gitea']} ${NCMD} chown -R git:git /home/git ${NCMD} chmod -R 750 /home/git if [ "${2}" != "q" ]; then echo -e "${idsCL[Green]}Complete${idsCL[Default]}" fi elif [ "${2}" != "q" ]; then echo -e "${idsCL[Red]}Node is down${idsCL[Default]}" fi done elif [ "${1}" = "pdnsadmin" ]; then for nip in "${NM_HOSTS['WEB'][@]}"; do if [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then NCMD='' else NCMD="${SSHCMD} root@${nip}" fi if [ "${2}" != "q" ]; then echo -en "${idsCL[Yellow]}Resetting folder permissions for PowerDNS-Admin on ${NM_HOSTNAMES[${nip}]} (${nip})... ${idsCL[Default]}" fi checkhost=$(CHECK_HOST ${nip}) if [ "${checkhost}" != "false" ]; then ${NCMD} chown -R www-data:www-data ${NM_REPL_CHECK_LOC['pdnsadmin']} ${NCMD} chmod -R 775 ${NM_REPL_CHECK_LOC['pdnsadmin']} if [ "${2}" != "q" ]; then echo -e "${idsCL[Green]}Complete${idsCL[Default]}" fi elif [ "${2}" != "q" ]; then echo -e "${idsCL[Red]}Node is down${idsCL[Default]}" fi done elif [ "${1}" = "nextcloud" ]; then nip=${NC_HOSTS[0]} if [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then NCMD='' else NCMD="${SSHCMD} root@${nip}" fi if [ "${2}" != "q" ]; then echo -en "${idsCL[Yellow]}Resetting folder permissions for Nextcloud on ${NM_HOSTNAMES[${nip}]} (${nip})... ${idsCL[Default]}" fi checkhost=$(CHECK_HOST ${nip}) if [ "${checkhost}" != "false" ]; then ${NCMD} chown -R www-data:www-data /mnt/Nextcloud-Data ${NCMD} find /mnt/Nextcloud-Data/ -type d -exec chmod 770 {} \; ${NCMD} find /mnt/Nextcloud-Data/ -type f -exec chmod 660 {} \; if [ "${2}" != "q" ]; then echo -e "${idsCL[Green]}Complete${idsCL[Default]}" fi elif [ "${2}" != "q" ]; then echo -e "${idsCL[Red]}Node is down${idsCL[Default]}" fi else DIVIDER if [ "${1}" != "" ]; then NEW_SITE=${1} echo -e "${idsCL[Yellow]}Setting new site folder permissions for (${NM_WWWPATH}/${NEW_SITE})${idsCL[Default]}" fi if [ "${NEW_SITE}" = "xxx" ]; then for nip in "${MYSQL_HOSTS[@]}"; do checkhost=$(CHECK_HOST ${nip}) if [ "${checkhost}" != "false" ]; then if [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else NCMD="${SSHCMD} root@${nip}" fi echo -e "${idsCL[Yellow]}Setting folder permissions for ${NM_HOSTNAMES[${nip}]} (${nip})${idsCL[Default]}" echo -en "${idsCL[Cyan]}LetsEncrypt Certs ${idsCL[Default]}" ${NCMD} chown -R root:le ${NM_CERTPATH} ${NCMD} chmod -R 6775 ${NM_CERTPATH} echo -e "${idsCL[Green]}Complete${idsCL[Default]}" echo fi done fi [ "${NM_WWWPATHS['WEB']}" != "" ] && WWWPATH=${NM_WWWPATHS['WEB']} || WWWPATH=/var/www for nip in "${NM_HOSTS['WEB'][@]}"; do checkhost=$(CHECK_HOST ${nip}) if [ "${checkhost}" != "false" ]; then if [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else NCMD="${SSHCMD} root@${nip}" fi if [ "${NEW_SITE}" != "" ]; then echo -en "${idsCL[Cyan]}${NM_HOSTNAMES[${nip}]} (${nip}) ${idsCL[Default]}" ${NCMD} chown -R www-data:www-data ${WWWPATH}/$NEW_SITE ${NCMD} chmod -R 7775 ${WWWPATH}/$NEW_SITE ${NCMD} chown -R www-data:www-data /var/lib/php/sessions ${NCMD} chmod -R 7777 /var/lib/php/sessions echo -e "${idsCL[Green]}Complete${idsCL[Default]}" else echo -e "${idsCL[Yellow]}Setting folder permissions for ${NM_HOSTNAMES[${nip}]} (${nip})${idsCL[Default]}" echo -en "${idsCL[Cyan]}Webserver folders ${idsCL[Default]}" ${NCMD} chown -R www-data:www-data ${WWWPATH} ${NCMD} chmod -R 7775 ${WWWPATH} ${NCMD} chown -R www-data:www-data /var/lib/php/sessions ${NCMD} chmod -R 7777 /var/lib/php/sessions echo -e "${idsCL[Green]}Complete${idsCL[Default]}" echo -en "${idsCL[Cyan]}Gitea Folder ${idsCL[Default]}" ${NCMD} chown -R git:git ${NM_REPL_CHECK_LOC['gitea']} ${NCMD} chmod -R 750 ${NM_REPL_CHECK_LOC['gitea']} ${NCMD} chown -R git:git /home/git ${NCMD} chmod -R 750 /home/git echo -e "${idsCL[Green]}Complete${idsCL[Def ault]}" echo fi fi done if [ "${NEW_SITE}" != "" ]; then echo ; fi if [ -z ${NMG_ACTION} ] || [ "${NMG_ACTION}" = "gui" ]; then ENTER2CONTINUE fi fi } HAPROXY-CONFIG() { echo -e "${idsCL[Yellow]}Creating HAProxy Config Files${idsCL[Default]}" DIVIDER false yellow # if [[ "${MYSQLSERVICES_CHECK}" = *"haproxy"* ]]; then if [[ " ${MYSQL_SERVICES_CHECK[*]} " =~ " haproxy " ]]; then for nip in "${MYSQL_HOSTS[@]}"; do if [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else NCMD="${SSHCMD} root@${nip}" fi echo -en "Creating File on ${NM_HOSTNAMES[${nip}]} ($nip)... ${idsCL[Default]}" ${NCMD} "nodemgmt update q" ${NCMD} "rm -f /etc/haproxy/haproxy.cfg" ${NCMD} "sed -e 's;%NIP%;${nip};g' ${NM_FOLDER}/templates/haproxy.config > /etc/haproxy/haproxy.cfg" echo -e "${idsCL[Green]}COMPLETE${idsCL[Default]}" done echo fi # if [[ "${WEBSERVICES_CHECK}" = *"haproxy"* ]]; then if [[ " ${WEB_SERVICES_CHECK[*]} " =~ " haproxy " ]]; then for nip in "${NM_HOSTS['WEB'][@]}"; do if [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else NCMD="${SSHCMD} root@${nip}" fi echo -en "Creating File on ${NM_HOSTNAMES[${nip}]} ($nip)... ${idsCL[Default]}" ${NCMD} "nodemgmt update q" ${NCMD} "rm -f /etc/haproxy/haproxy.cfg" ${NCMD} "sed -e 's;%NIP%;${nip};g' ${NM_FOLDER}/templates/haproxy.config > /etc/haproxy/haproxy.cfg" echo -e "${idsCL[Green]}COMPLETE${idsCL[Default]}" done fi # if [[ "${LBSERVICES_CHECK}" = *"haproxy"* ]]; then if [[ " ${LB_SERVICES_CHECK[*]} " =~ " haproxy " ]]; then for nip in "${LB_HOSTS[@]}"; do if [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else NCMD="${SSHCMD} root@${nip}" fi echo -en "Creating File on ${NM_HOSTNAMES[${nip}]} ($nip)... ${idsCL[Default]}" ${NCMD} "nodemgmt update q" ${NCMD} "rm -f /etc/haproxy/haproxy.cfg" ${NCMD} "sed -e 's;%NIP%;${nip};g' ${NM_FOLDER}/templates/haproxy.config > /etc/haproxy/haproxy.cfg" echo -e "${idsCL[Green]}COMPLETE${idsCL[Default]}" done fi SERVICE_MGMT haproxy reload echo echo -e "${idsCL[Green]}HAProxy Config Files have been created.${idsCL[Default]}" echo } KEEPALIVE-CONFIG() { echo -e "${idsCL[Yellow]}Creating Keepalive Config Files${idsCL[Default]}" DIVIDER false yellow # if [[ "${MYSQLSERVICES_CHECK}" = *"keepalive"* ]]; then if [[ " ${MYSQL_SERVICES_CHECK[*]} " =~ " keepalived " ]]; then for nip in "${MYSQL_HOSTS[@]}"; do if [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else NCMD="${SSHCMD} root@${nip}" fi echo -en "Creating File on ${NM_HOSTNAMES[${nip}]} ($nip)... ${idsCL[Default]}" ${NCMD} "nodemgmt update q" ${NCMD} "rm -f /etc/keepalived/keepalived.conf" ${NCMD} "sed -e 's;%NIP%;${nip};g' ${NM_FOLDER}/templates/keepalived.config > /etc/keepalived/keepalived.conf" echo -e "${idsCL[Green]}COMPLETE${idsCL[Default]}" done echo fi # if [[ "${WEBSERVICES_CHECK}" = *"keepalive"* ]]; then if [[ " ${WEB_SERVICES_CHECK[*]} " =~ " keepalived " ]]; then for nip in "${NM_HOSTS['WEB'][@]}"; do if [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else NCMD="${SSHCMD} root@${nip}" fi echo -en "Creating File on ${NM_HOSTNAMES[${nip}]} ($nip)... ${idsCL[Default]}" ${NCMD} "nodemgmt update q" ${NCMD} "rm -f /etc/keepalived/keepalived.conf" ${NCMD} "sed -e 's;%NIP%;${nip};g' ${NM_FOLDER}/templates/keepalived.config > /etc/keepalived/keepalived.conf" echo -e "${idsCL[Green]}COMPLETE${idsCL[Default]}" done fi SERVICE_MGMT keepalived reload echo echo -e "${idsCL[Green]}Keepalive Config Files have been created.${idsCL[Default]}" echo } NODEUPDATES() { start=`date +%s` cw=40; rm -f /tmp/.nodeupdate.* if [ "${1}" = "report" ]; then unset idsCL idsBG idsST idsCL=('') idsBG=('') idsST=('') else echo fi declare -i spc1; declare -i c echo -e "${idsCL[LightGreen]}Updating All Nodes${idsCL[Default]}" echo -e "${idsCL[LightGreen]}-------------------------------------------${idsCL[Default]}" ncount=0 for NTYPE in "${NM_NODE_TYPES[@]}"; do var=${NTYPE}_HOSTS[@] for nip in "${!var}"; do if [ ! -f /tmp/.nodeupdate.${NM_HOSTNAMES[${nip}]// /-}.running ]; then if [ "${RUN_NODE_IP}" != "${nip}" ]; then touch /tmp/.nodeupdate.${NM_HOSTNAMES[${nip}]// /-}.running NODEUPDATE "${nip}" "${2}" "${NMCMD}" > ${tmpfile}.running fi betacheck=$(BETACHECK) if [ "${nip}" != "100.100.2.1" ] && [ "${nip}" != "${NM_OFFSITE_GW_IP}" ] && [ ! -f ${NM_TMPFOLDER}/${nip}.down ] && [ "$(CHECK_HOST ${nip})" != "false" ]; then if [ "${betacheck}" == "false" ]; then if [ "${2}" != "sync" ]; then if [ "$(ssh -o BatchMode=yes -o ConnectTimeout=3 root@${nip} echo ok 2>&1)" != "ok" ]; then echo -e "${idsCL[Yellow]}[${nip}] New server, needs SSH credentials${idsCL[Default]}" ssh-copy-id root@${nip} fi if ! ${NCMD} command -v nodemgmt > /dev/null 2>&1; then ${NCMD} "bash <(curl -sL https://go.scity.us/install-nodemgmt)" &1 ${NMCMD} rsync -az ${NM_FOLDER}/conf/*.inc --exclude ${NM_FOLDER}/conf/copycerts.sh.inc ${NM_FOLDER}/conf/*.conf root@${nip}:${NM_FOLDER}/conf/ &1 ${NMCMD} rsync -az ${NM_FOLDER}/conf/powerwall ${NM_FOLDER}/conf/*.conf root@${nip}:${NM_FOLDER}/conf/ &1 sleep 2s source /opt/idssys/nodemgmt/conf/settings.conf source /opt/idssys/nodemgmt/defaults.inc # [ "${NM_GITPASS}" != "" ] && [ "${NM_GITUSER^^}" == "VOLTRON" ] && ${NMCMD} "bash <(curl -sL https://go.scity.us/add-linux-pass)" &1 echo -e "${idsCL[Green]}Installed & Synced${idsCL[Default]}" >> ${tmpfile}.running elif [ ${noup} -eq 1 ]; then echo -e "${idsCL[Green]}Already Installed${idsCL[Default]}" >> ${tmpfile}.running else ${NCMD} "nodemgmt update q" >> ${tmpfile}.running fi else ${NMCMD} rsync -az --exclude ${NM_FOLDER}/conf/copycerts.sh.inc ${NM_FOLDER}/conf/*.inc ${NM_FOLDER}/conf/*.conf root@${nip}:${NM_FOLDER}/conf/ & &1 ${NMCMD} rsync -az ${NM_FOLDER}/conf/powerwall ${NM_FOLDER}/conf/*.conf root@${nip}:${NM_FOLDER}/conf/ &1 echo -e "${idsCL[Green]}Files Synced${idsCL[Default]}" >> ${tmpfile}.running fi else echo -e "${idsCL[LightCyan]}Skipping BETA Update${idsCL[Default]}" >> ${tmpfile}.running fi elif [ -f ${NM_TMPFOLDER}/${nip}.down ]; then echo -e "${idsCL[LightCyan]}Skipping, host is offline${idsCL[Default]}" >> ${tmpfile}.running else echo -e "${idsCL[LightCyan]}Skipping${idsCL[Default]}" >> ${tmpfile}.running fi [ -f ${tmpfile}.running ] && mv ${tmpfile}.running ${tmpfile}.done || touch ${tmpfile}.done } ADD_LOGROTATE_CRONTAB(){ if ! crontab -l | grep -q "${NM_FOLDER}/tmp-logrotate"; then (crontab -l ; echo "0 */1 * * * logrotate -f ${NM_FOLDER}/tmp-logrotate") >/dev/null 2>&1 | crontab - fi /bin/chmod 0644 ${NM_FOLDER}/tmp-logrotate echo echo -e "${idsCL[Green]}The crontab entry has been made${idsCL[Default]}" echo read -n 1 -s -p "Press any key to continue" echo } UPDATE_DYNDNS(){ [ "${NM_PDNS_HOST}" != "" ] && PDNS_SERVER=${NM_PDNS_HOST} || PDNS_SERVER=${NM_PDNS_WANDNS} TESTMODE=0; FORCE=0; while [ $# -gt 0 ]; do case "${1}" in -s|-site) FORCE=1;; -f|-force) FORCE=1;; -t|-test) TESTMODE=1;; -h | -help | --help) echo echo -e "Usage: ${idsCL[LightYellow]}[nodemgmt or nmg] update-dyndns ${idsCL[Yellow]}{location}${idsCL[Default]} {" width=35 printf "%-${width}s- %s\n" " {location}" "(site location name to update for)" printf "%-${width}s- %s\n" " -s|-site" "(configured site to run for [NM_DYNDNS_SITES variable])" printf "%-${width}s- %s\n" " -f|-force" "(will force a record update without IP changing)" printf "%-${width}s- %s\n" " -t|-test" "(tests but does not update records)" echo "}" exit 0;; *) [ "${1}" != "q" ] && LOCATION=${1};; esac shift done if [ "${NM_DYNDNS_SITES[${LOCATION,,}]}" != "" ]; then arr DYNDNS_HOSTS IFS=,; hosts=(${NM_DYNDNS_SITES[${LOCATION,,}]}); unset IFS for host in "${hosts[@]}"; do arr_insert DYNDNS_HOSTS ${host} done domain=${DYNDNS_HOSTS[0]#*.} echo cw_spc=10 echo -e "Checking for DYNDNS update at '${idsCL[Green]}${LOCATION^^}${idsCL[Default]}'" echo echo -en "${idsCL[White]}Previous WAN IP : "; OLDIP=`dig +short ${DYNDNS_HOSTS[0]} @${PDNS_SERVER} +time=2`; echo -e "${idsCL[Cyan]}${OLDIP}" echo -en "${idsCL[White]}Current WAN IP : "; NEWIP="$(dig +short myip.opendns.com @resolver1.opendns.com +time=2)" >/dev/null 2>&1 if [ "${NEWIP}" == "" ]; then NEWIP="$(wget -qO- https://ipinfo.io/ip ; echo)" >/dev/null 2>&1 if [ "${NEWIP}" == "" ]; then NEWIP="$(wget -qO- https://ipecho.net/plain ; echo)" >/dev/null 2>&1 [ "${NEWIP}" == "" ] && NEWIP="WAN IP could not be found" fi fi echo -e "${idsCL[LightGreen]}${NEWIP}" echo if ([ "${OLDIP}" != "" ] && [ "${NEWIP}" != "" ] && [[ "${OLDIP}" != *";"* ]] && [[ "${NEWIP}" != *";"* ]] && [[ "${NEWIP}" != "WAN"* ]]) && ([ "${OLDIP}" != "${NEWIP}" ] || [ ${FORCE} -eq 1 ]); then if [ ${TESTMODE} -eq 1 ]; then echo -e "${idsCL[Green]}'${idsCL[LightCyan]}${LOCATION^^}${idsCL[Green]}' WAN IP has changed: ${idsCL[Yellow]}testmode active and will not update records${idsCL[Default]}" else if [ ${FORCE} -eq 1 ]; then echo -en "${idsCL[Yellow]}'${idsCL[LightCyan]}${LOCATION^^}${idsCL[Yellow]}' WAN IP has not changed...\n${idsCL[Green]}but what the heck, lets update the records anyway ehh ... " else SENDNOTICE "${LOCATION^^} WAN IP Changed" "Updated '${LOCATION^}' WAN IP from '${OLDIP}' to '${NEWIP}'" echo -en "${idsCL[Green]}'${idsCL[LightCyan]}${LOCATION^^}${idsCL[Green]}' WAN IP has changed, updating all pre-defined 'A' records ... " fi if [ "${NM_PDNS_USER}" != "" ] && [ "${NM_PDNS_PASS}" != "" ]; then if [ "$(curl -m 3 -sL "https://${NM_PDNS_USER}df:${NM_PDNS_PASS}@${PDNS_SERVER}/domain/${domain}" | grep "HTTP 403 Error")" == "" ]; then for host in ${DYNDNS_HOSTS[@]}; do /usr/bin/curl -s "https://${NM_PDNS_USER}:${NM_PDNS_PASS}@${PDNS_SERVER}/nic/update?hostname=${host}&myip=${NEWIP}" > /dev/null 2>&1 done if [ "${NM_PDNS_USER}" == "systems" ]; then [ "${LOCATION,,}" == "mainsite" ] && /usr/bin/curl -s "https://${NM_PDNS_USER}:${NM_PDNS_PASS}@${NM_PDNS_LANDNS}/nic/update?hostname=sc1.scity.us&myip=${NEWIP}" > /dev/null 2>&1 [ "${LOCATION,,}" == "offsite" ] && /usr/bin/curl -s "https://${NM_PDNS_USER}:${NM_PDNS_PASS}@${NM_PDNS_LANDNS}/nic/update?hostname=wan.offsite.scity.us&myip=${NEWIP}" > /dev/null 2>&1 fi echo -e "${idsCL[Green]}Done${idsCL[Default]}" else echo -e "\n\n${idsCL[LightRed]}INVALID DYNDNS username and/or password (NM_PDNS_USER=${NM_PDNS_USER}) (NM_PDNS_PASS=${NM_PDNS_PASS})\n" # SENDNOTICE "${LOCATION^^} DYNDNS ERROR" "INVALID DYNDNS username or password (NM_PDNS_USER=${NM_PDNS_USER}) (NM_PDNS_PASS=${NM_PDNS_PASS})" 1 exit 1 fi else echo -e "\n\n${idsCL[LightYellow]}Missing DYNDNS username and/or password (NM_PDNS_USER=${NM_PDNS_USER}) (NM_PDNS_PASS=${NM_PDNS_PASS})\n" # SENDNOTICE "${LOCATION^^} DYNDNS ERROR" "MISSING DYNDNS username or password (NM_PDNS_USER=${NM_PDNS_USER}) (NM_PDNS_PASS=${NM_PDNS_PASS})" 1 exit 1 fi fi elif [[ "${NEWIP}" == *";"* ]] || [[ "${OLDIP}" == *";"* ]]; then echo -e "${idsCL[LightRed]}Could not perform DNS Lookups${idsCL[Default]}" # SENDNOTICE "${LOCATION^^} DYNDNS Could not Update" "Connection error, could reach any servers" elif [ "${OLDIP}" == "" ]; then echo -e "${idsCL[LightRed]}Could not get Previous WAN IP${idsCL[Default]}" elif [ "${NEWIP}" == "" ]; then echo -e "${idsCL[LightRed]}Could not get Current WAN IP${idsCL[Default]}" else echo -e "${idsCL[Yellow]}'${idsCL[Green]}${LOCATION^^}${idsCL[Yellow]}' WAN IP has not changed${idsCL[Default]}" fi if [ ${TESTMODE} -eq 1 ]; then echo -en "\nDYNDNS Credential Test: " if [ "$(curl -m 3 -sL "https://${NM_PDNS_USER}df:${NM_PDNS_PASS}@${PDNS_SERVER}/domain/${domain}" | grep "HTTP 403 Error")" == "" ]; then echo -e "${idsCL[Green]}Pass${idsCL[Default]}" else echo -e "${idsCL[LightRed]}Fail${idsCL[Default]}" fi fi else [ "${LOCATION}" == "" ] && echo -e "\n${idsCL[LightYellow]}No DYNDNS location specified" || echo -e "\n${idsCL[Red]}DYNDNS location '${LOCATION}' not recognized" fi echo } BACKUP_OFFSITEPFSENSE(){ BAKFOLDER=/mnt/Veeam-pfSense-Backups if [ "$(CHECK_HOST ${NM_OFFSITE_GW_IP})" != "false" ]; then if [ ! -f ${BAKFOLDER}/mounted ]; then mount -a sleep 2s if [ ! -f ${BAKFOLDER}/mounted ]; then echo "Can't mount backup folder" SENDNOTICE "Offsite pfSense Backup Failed" "Could not mount backup folder" 1 exit 1 fi fi newBAKFOLDER=$(date +%Y%m%d-%H%M%S) mkdir ${BAKFOLDER}/${newBAKFOLDER} DOM='01' DOW='1' DailyBackupsToKeep=14 WeeklyBackupsToKeep=8 MonthlyBackupsToKeep=3 ${SSHCMD} root@${NM_OFFSITE_GW_IP} tar -c -f /cf/conf/conf_backup.tar.gz /cf/conf scp root@${NM_OFFSITE_GW_IP}:/cf/conf/conf* ${BAKFOLDER}/${newBAKFOLDER}/ ${SSHCMD} root@${NM_OFFSITE_GW_IP} rm -f /cf/conf/conf_backup.tar.gz cd ${BAKFOLDER} if [ "$(date +%d)" == "${DOM}" ] && [ "$(date +%u)" == "${DOW}" ]; then mv ${newBAKFOLDER} "${newBAKFOLDER}-M" ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-W" ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-D" elif [ "$(date +%d)" == "${DOM}" ]; then mv ${newBAKFOLDER} "${newBAKFOLDER}-M" ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-D" elif [ "$(date +%u)" == "${DOW}" ]; then mv ${newBAKFOLDER} "${newBAKFOLDER}-W" ln -s "${newBAKFOLDER}-W" "${newBAKFOLDER}-D" else mv ${newBAKFOLDER} "${newBAKFOLDER}-D" fi dailyfilestokeep=(`ls -d ${BAKFOLDER}/*-D 2> /dev/null | tail -${DailyBackupsToKeep}`) weeklyfilestokeep=(`ls -d ${BAKFOLDER}/*-W 2> /dev/null | tail -${WeeklyBackupsToKeep}`) monthlyfilestokeep=(`ls -d ${BAKFOLDER}/*-M 2> /dev/null | tail -${MonthlyBackupsToKeep}`) for folder in $(ls -d ${BAKFOLDER}/*); do if [ "${folder}" != "${BAKFOLDER}/mounted" ]; then if [[ "${folder}" == *"-D"* ]]; then filestokeep=${dailyfilestokeep[@]} elif [[ "${folder}" == *"-W"* ]]; then filestokeep=${weeklyfilestokeep[@]} elif [[ "${folder}" == *"-M"* ]]; then filestokeep=${monthlyfilestokeep[@]} fi keep=0 for file in ${filestokeep}; do if [ "${folder}" == "${file}" ]; then keep=1; break fi done; if [ $keep == 0 ]; then delFolder="V:\\UniFi-Backups\\Offsite-pfSense_Backups\\${folder##*/}" ${SSHCMD} backup@10.10.1.60 cmd /C rmdir /S /Q "${delFolder}" fi fi done else SENDNOTICE "Offsite pfSense Backup Failed" "Could not contact 'pfSense @ ${NM_OFFSITE_GW_IP}' for backup" 1 fi } BACKUP_UNIFIUDM(){ BAKFOLDER=/mnt/Veeam-UniFi-UDM_Backups UNIFIUDM_IP='10.5.1.1' if [ "$(CHECK_HOST ${UNIFIUDM_IP})" != "false" ]; then if [ ! -f ${BAKFOLDER}/mounted ]; then mount -a sleep 2s if [ ! -f ${BAKFOLDER}/mounted ]; then echo "Can't mount backup folder" SENDNOTICE "Unifi-UDM Backup Failed" "Could not mount backup folder" 1 exit 1 fi fi newBAKFOLDER=$(date +%Y%m%d-%H%M%S) mkdir ${BAKFOLDER}/${newBAKFOLDER} DOM='01' DOW='1' DailyBackupsToKeep=3 WeeklyBackupsToKeep=2 MonthlyBackupsToKeep=1 ${SSHCMD} root@${UNIFIUDM_IP} tar -c -f /volume1/data_backup.tar.gz /data ${SSHCMD} root@${UNIFIUDM_IP} tar -c -f /volume1/root_backup.tar.gz /root scp root@${UNIFIUDM_IP}:/volume1/*_backup.tar.gz ${BAKFOLDER}/${newBAKFOLDER}/ ${SSHCMD} root@${UNIFIUDM_IP} rm -f /volume1/*_backup.tar.gz cd ${BAKFOLDER} if [ "$(date +%d)" == "${DOM}" ] && [ "$(date +%u)" == "${DOW}" ]; then mv ${newBAKFOLDER} "${newBAKFOLDER}-M" ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-W" ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-D" elif [ "$(date +%d)" == "${DOM}" ]; then mv ${newBAKFOLDER} "${newBAKFOLDER}-M" ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-D" elif [ "$(date +%u)" == "${DOW}" ]; then mv ${newBAKFOLDER} "${newBAKFOLDER}-W" ln -s "${newBAKFOLDER}-W" "${newBAKFOLDER}-D" else mv ${newBAKFOLDER} "${newBAKFOLDER}-D" fi dailyfilestokeep=(`ls -d ${BAKFOLDER}/*-D 2> /dev/null | tail -${DailyBackupsToKeep}`) weeklyfilestokeep=(`ls -d ${BAKFOLDER}/*-W 2> /dev/null | tail -${WeeklyBackupsToKeep}`) monthlyfilestokeep=(`ls -d ${BAKFOLDER}/*-M 2> /dev/null | tail -${MonthlyBackupsToKeep}`) for folder in $(ls -d ${BAKFOLDER}/*); do if [ "${folder}" != "${BAKFOLDER}/mounted" ]; then if [[ "${folder}" == *"-D"* ]]; then filestokeep=${dailyfilestokeep[@]} elif [[ "${folder}" == *"-W"* ]]; then filestokeep=${weeklyfilestokeep[@]} elif [[ "${folder}" == *"-M"* ]]; then filestokeep=${monthlyfilestokeep[@]} fi keep=0 for file in ${filestokeep}; do if [ "${folder}" == "${file}" ]; then keep=1; break fi done; if [ $keep == 0 ]; then delFolder="D:\\BackupSync\\UniFi-Backups\\UniFi-UDM_Backups\\${folder##*/}" ${SSHCMD} backup@10.10.1.60 cmd /C rmdir /S /Q "${delFolder}" fi fi done else SENDNOTICE "UniFi-UDM Backup Failed" "Could not contact 'UDM @ ${UNIFIUDM_IP}' for backup" 1 fi } BACKUP_UNIFINVR(){ BAKFOLDER=/mnt/Veeam-UniFi-NVR_Backups UNIFINVR_IP='10.10.70.1' if [ "$(CHECK_HOST ${UNIFINVR_IP})" != "false" ]; then if [ ! -f ${BAKFOLDER}/mounted ]; then mount -a sleep 2s if [ ! -f ${BAKFOLDER}/mounted ]; then echo "Can't mount backup folder" SENDNOTICE "Unifi-NVR Backup Failed" "Could not mount backup folder" 1 exit 1 fi fi newBAKFOLDER=$(date +%Y%m%d-%H%M%S) mkdir ${BAKFOLDER}/${newBAKFOLDER} DOM='01' DOW='1' DailyBackupsToKeep=3 WeeklyBackupsToKeep=2 MonthlyBackupsToKeep=1 ${SSHCMD} root@${UNIFINVR_IP} tar -c -f /volume1/data_backup.tar.gz /data ${SSHCMD} root@${UNIFINVR_IP} tar -c -f /volume1/root_backup.tar.gz /root ${SSHCMD} root@${UNIFINVR_IP} tar -c -f /volume1/unifi_backup.tar.gz /volume1/.srv/unifi-protect/backups /volume1/.srv/unifi-protect/data /volume1/.srv/unifi-protect/dbBackups scp root@${UNIFINVR_IP}:/volume1/*_backup.tar.gz ${BAKFOLDER}/${newBAKFOLDER}/ ${SSHCMD} root@${UNIFINVR_IP} rm -f /volume1/*_backup.tar.gz cd ${BAKFOLDER} if [ "$(date +%d)" == "${DOM}" ] && [ "$(date +%u)" == "${DOW}" ]; then mv ${newBAKFOLDER} "${newBAKFOLDER}-M" ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-W" ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-D" elif [ "$(date +%d)" == "${DOM}" ]; then mv ${newBAKFOLDER} "${newBAKFOLDER}-M" ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-D" elif [ "$(date +%u)" == "${DOW}" ]; then mv ${newBAKFOLDER} "${newBAKFOLDER}-W" ln -s "${newBAKFOLDER}-W" "${newBAKFOLDER}-D" else mv ${newBAKFOLDER} "${newBAKFOLDER}-D" fi dailyfilestokeep=(`ls -d ${BAKFOLDER}/*-D 2> /dev/null | tail -${DailyBackupsToKeep}`) weeklyfilestokeep=(`ls -d ${BAKFOLDER}/*-W 2> /dev/null | tail -${WeeklyBackupsToKeep}`) monthlyfilestokeep=(`ls -d ${BAKFOLDER}/*-M 2> /dev/null | tail -${MonthlyBackupsToKeep}`) for folder in $(ls -d ${BAKFOLDER}/*); do if [ "${folder}" != "${BAKFOLDER}/mounted" ]; then if [[ "${folder}" == *"-D"* ]]; then filestokeep=${dailyfilestokeep[@]} elif [[ "${folder}" == *"-W"* ]]; then filestokeep=${weeklyfilestokeep[@]} elif [[ "${folder}" == *"-M"* ]]; then filestokeep=${monthlyfilestokeep[@]} fi keep=0 for file in ${filestokeep}; do if [ "${folder}" == "${file}" ]; then keep=1; break fi done; if [ $keep == 0 ]; then delFolder="D:\\BackupSync\\UniFi-Backups\\UniFi-NVR_Backups\\${folder##*/}" ${SSHCMD} backup@10.10.1.60 cmd /C rmdir /S /Q "${delFolder}" fi fi done else SENDNOTICE "UniFi-NVR Backup Failed" "Could not contact 'NVR @ ${UNIFINVR_IP}' for backup" 1 fi } RUN_COMMAND(){ while [ $# -gt 0 ]; do case "${1}" in -nt) nodetype=${2^^};; -cmd|-c) RUNCMD="${2}";; esac shift done if [ "${nodetype}" == "ALL" ] || [ -z ${nodetype+x} ]; then nodetype=ALL # NT_HOSTS=ALL_HOSTS[@] NTS=(${NM_NODE_TYPES[*]}) elif [ "${nodetype}" != "" ]; then if [ "${NM_HOSTS[${nodetype}]}" != "" ]; then # NT_HOSTS=${nodetype}_HOSTS[@] NTS=("${nodetype}"); else echo -e "${idsCL[Red]}"${nodetype}" is an unknown NodeType.${idsCL[Default]}\n" exit 1 fi fi if [ -z ${RUNCMD+x} ]; then echo -e "${idsCL[Red]}No command specified to run. (Use nmg run -cmd \"command to run\")${idsCL[Default]}\n" exit 1 fi for NTYPE in "${NTS[@]}"; do echo -e "${idsST[Bold]}"; DIVIDER echo -e "${idsCL[Yellow]} ${NM_NODETYPES[$NTYPE]}-Nodes to run command { \`${idsCL[Default]}${RUNCMD}${idsCL[Yellow]}\` }${idsCL[Default]}" DIVIDER; echo -e "${idsST[Reset]}" NT_HOSTS=${NTYPE}_HOSTS[@] for nip in "${!NT_HOSTS}"; do if [ "${RUN_NODE_IP}" == "${nip}" ]; then NCMD='' LH='- localhost' else NCMD="${SSHCMD} root@${nip}" LH='' fi echo -e " ${idsST[Bold]}${idsCL[LightCyan]}${NM_HOSTNAMES[${nip}]}[${nip}]${idsST[Reset]} ${idsCL[LightYellow]}${LH}${idsCL[Default]}" DIVIDER false green if [ ! -f /tmp/nmg.run.${nip} ]; then # echo "Running command: ${NCMD} ${RUNCMD}" [ "${NCMD}" != "" ] && ${NCMD} "${RUNCMD}" || ${RUNCMD} touch /tmp/nmg.run.${nip} else echo "Skipping, already ran command on this host" fi DIVIDER false green echo done echo done rm -f /tmp/nmg.run.* } DOWNLIST(){ declare -i cw; declare -i spc1; declare -i c DOWN_LIST=`find ${NM_TMPFOLDER}/ -maxdepth 1 -iname "*.down"` IFS=$'\n'; read -rd '' -a DOWN_LIST <<<"${DOWN_LIST}"; unset IFS if [ "${1}" == "report" ]; then unset idsCL idsBG idsST idsCL=('') idsBG=('') idsST=('') DOWNLIST=() for dli in "${DOWN_LIST[@]}"; do [ ! -f ${dli//.down/.disable} ] && DOWNLIST+=(${dli}) done else sss=1 DOWNLIST=(${DOWN_LIST[@]}) fi if [ -z ${NMG_ACTION} ] || [ "${NMG_ACTION}" = "gui" ]; then DIVIDER true fi echo if [ "${DOWNLIST}" == "" ]; then [ "${1}" == "report" ] && exit 0 echo -e "${idsCL[LightCyan]}Nothing is down. Hooray for you!!${idsCL[Default]}" echo -en "\nWanna see something great for being so awesome? (y/N) " read -n1 great if [ "${great^^}" == "Y" ]; then function nicetry { echo -e " LOL nice try... you can't stop this shit! DESTROY DESTROY DESTROY" echo -en "Continue formatting local volumes faster." for i in {1..5000}; do sleep 0.2 echo -en "." done echo -e "\n\nAwww, were you expecting some big ending :*(" } trap nicetry EXIT echo -en "\n\nDiscovering local storage volumes ." sleep 1s; echo -en " ." sleep 2s; echo -en " ." sleep 1s; echo -en " ." sleep 2s; echo -e " Done\n" sleep 1s; echo -en "Formatting local volumes." for i in {1..5000}; do sleep 2s; echo -en "." done fi else [ "${1}" == "report" ] && dlen=100 || dlen=110 echo -e "${idsCL[LightGreen]}Current List of Items Down...${idsCL[Default]}" DIVIDER false yellow ${dlen} if [ "${1}" == "report" ]; then echo -e "${idsCL[Yellow]}[Type] [Host/Service/Docker Name] [Host] [Down_Time]${idsCL[Default]}" else echo -e "${idsCL[Yellow]} [Type] [Host/Service/Docker Name] [Host] [Down_Time] [Notifications]${idsCL[Default]}" fi DIVIDER false yellow ${dlen} until [ "${choice^^}" = "E" ]; do if [ "${1}" != "report" ] && [ ${sss} -ne 1 ]; then DOWN_LIST=`find ${NM_TMPFOLDER}/ -maxdepth 1 -iname "*.down"` IFS=$'\n'; read -rd '' -a DOWN_LIST <<<"${DOWN_LIST}"; unset IFS DOWNLIST=(${DOWN_LIST[@]}) elif [ ${sss} -eq 1 ]; then sss=0 fi cw=35; cw1=11; cw2=20; is=1; for downitem in ${DOWNLIST[@]}; do ditem=${downitem##*/} ditem=${ditem//.down} host=${ditem%%~*} item=${ditem#*~}; item=${item/.repl/} # echo "HERE: ${ditem} - ${host} - ${item}" if [[ ${ditem} == *"~"* ]] && [[ ${ditem} == *".repl"* ]] && [ "${NM_REPL_DESC[${item}]}" != "" ]; then itemname=${NM_REPL_DESC[${item}]} itemtype=SYNC elif [[ ${ditem} == *"~"* ]] && [ "${NM_SERVICE_DESC[${item}]}" != "" ]; then itemname=${NM_SERVICE_DESC[${item}]} itemtype=SERVICE elif [[ ${ditem} == *"~"* ]] && [ "${NM_DOCKER_DESC[${item}]}" != "" ]; then itemname=${NM_DOCKER_DESC[${item}]} itemtype=DOCKER elif [ "${NM_HOSTNAMES[${host}]}" != "" ]; then itemname=${NM_HOSTNAMES[${host}]} itemtype=HOST else itemname="${item} DOWN"; itemtype="" [ "${NM_HOSTNAMES[${host}]}" != "" ] && itemname="${itemname}: ${NM_HOSTNAMES[${host}]}" fi if [ -f ${NM_TMPFOLDER}/${ditem}.errtime ]; then toterrtime=$(expr $(date +%s) - $(stat -c %Y ${NM_TMPFOLDER}/${ditem}.errtime)) else toterrtime=$(expr $(date +%s) - $(stat -c %Y ${NM_TMPFOLDER}/${ditem}.down)) fi c=0; spc=''; spc1=`expr ${cw} - ${#itemname}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done c=0; spca=''; spc1=`expr ${cw1} - ${#itemtype}`; until [ $c = ${spc1} ]; do spca="${spca} "; c=`expr $c + 1`; done c=0; spc2=''; spc1=`expr ${cw2} - ${#host}`; until [ $c = ${spc1} ]; do spc2="${spc2} "; c=`expr $c + 1`; done time=$(SHOW_TIME ${toterrtime}) if [ "${1}" == "report" ]; then echo -e "${idsCL[LightRed]}${itemtype}${spca}${itemname}${spc}${host}${spc2}${time}${idsCL[Default]}" else if [ "${choice^^}" == "A" ] || ([[ ${choice} == ?(-)+([0-9]) ]] && [ ${choice} -gt 0 ] 2>/dev/null && [ ${is} -eq ${choice} ]); then [ ! -f ${NM_TMPFOLDER}/${ditem}.disable ] && touch ${NM_TMPFOLDER}/${ditem}.disable || rm -f ${NM_TMPFOLDER}/${ditem}.disable fi [ ${is} -lt 10 ] && ignsel=" ${is}) " || ignsel="${is}) " # ([ -f ${NM_TMPFOLDER}/${ditem}.disable ] || ([[ "${host}" = *"10.2."* ]] && [ -f ${PW_TMPFOLDER}/OFF-vMS-Host1.down ])) && dstatus="OFF" || dstatus="${idsCL[Green]}ON" [ -f ${NM_TMPFOLDER}/${ditem}.disable ] && dstatus="OFF" || dstatus="${idsCL[Green]}ON" c=0; spc3=''; until [ $c = `expr 26 - ${#time}` ]; do spc3="${spc3} "; ((c++)); done echo -e "\033[K${idsCL[LightRed]}${idsST[Bold]}${ignsel}${idsST[Reset]}${idsCL[LightRed]}${itemtype}${spca}${itemname}${spc}${host}${spc2}${time}${spc3}${dstatus}${idsCL[Default]}" fi DIVIDER false darkGray ${dlen} ((is++)) done if [ "${1}" != "report" ]; then echo -en "\n\033[K${idsCL[LightCyan]}Enter # to change notifications [${idsCL[Default]}Change (${idsCL[LightYellow]}A${idsCL[Default]})ll, ${idsCL[Default]}(${idsCL[LightYellow]}E${idsCL[Default]})xit${idsCL[LightCyan]}] : ${idsCL[Default]}" read choice else choice=E fi [ "${choice^^}" == "E" ] && break echo -e "\033[$(echo "scale=1; (${#DOWNLIST[@]}*2)+3" | bc)A" for (( c=1; c<$(echo "scale=1; (${#DOWNLIST[@]}*2)+3" | bc); c++ )); do echo -e "\033[K"; done echo -e "\033[$(echo "scale=1; (${#DOWNLIST[@]}*2)+3" | bc)A" done echo fi if [ -z ${NMG_ACTION} ] || [ "${NMG_ACTION}" = "gui" ]; then DIVIDER true ENTER2CONTINUE fi echo } MAINTENANCE_MODE(){ if [ "${1}" ] && [ "${NM_NODETYPES[${1^^}]}" != "" ]; then ntypesel=(${1^^}) MM_ACTION=${2} else ntypesel=(${NM_NODE_TYPES[@]}) MM_ACTION=${1} fi PRI_CW=40 DV_LEN=70 declare -i cw; declare -i spc1; declare -i c until [ "${choice^^}" = "E" ]; do item_number=1 for NTYPE in "${ntypesel[@]}"; do srvcs=${NTYPE}_SERVICES_CHECK[@]; dockers=${NTYPE}_DOCKERS_CHECK[@] hosts=${NTYPE}_HOSTS[@] repls=${NTYPE}_REPL_CHECK[@] if ([[ ! -v ${NTYPE}_DOCKERS_CHECK ]] && [ "${MM_ACTION}" == "dockers" ]) || ([ "${NM_SERVICES_CHECK[${NTYPE}]}" == "" ] && [ "${MM_ACTION}" == "services" ]); then GOFORCHECK=false; else GOFORCHECK=true; fi if [ ${GOFORCHECK} = true ]; then echo -en "${idsST[Bold]}"; DIVIDER . lightYellow ${DV_LEN} echo -e "${idsCL[LightYellow]} ${NM_NODETYPES[$NTYPE]}-Node Status Checks${idsCL[Default]}" DIVIDER . lightYellow ${DV_LEN}; echo -en "${idsST[Reset]}" for nip in "${!hosts}"; do if [ ${item_number} -lt 10 ]; then isel=" ${item_number})"; elif [ ${item_number} -lt 100 ]; then isel=" ${item_number})"; else isel=" ${item_number})"; fi MSG="${NM_HOSTNAMES[${nip}]} [${nip}]" c=0; spc=''; spc1=`expr ${PRI_CW} + 4 - ${#MSG}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done echo -en "${idsCL[LightYellow]}${isel} ${idsST[Bold]}${idsCL[LightCyan]}${MSG}${idsST[Reset]}${spc}${idsCL[Default]}: " if [ "${choice}" -gt 0 ] 2>/dev/null && [ ${item_number} -eq ${choice} ]; then [ ! -f ${NM_TMPFOLDER}/${nip}.disable ] && touch ${NM_TMPFOLDER}/${nip}.disable || rm -f ${NM_TMPFOLDER}/${nip}.disable fi # ([ -f ${NM_TMPFOLDER}/${nip}.disable ] || ([[ "${nip}" = *"10.2."* ]] && [ -f ${PW_TMPFOLDER}/OFF-vMS-Host1.down ])) && dstatus="${idsCL[LightRed]}OFF" || dstatus="${idsCL[Green]}ON" [ -f ${NM_TMPFOLDER}/${nip}.disable ] && dstatus="${idsCL[LightRed]}OFF" || dstatus="${idsCL[Green]}ON" echo -e "${dstatus}${idsCL[Default]}" ((item_number++)) DIVIDER false lightCyan ${DV_LEN} ######################## ## SERVICES CHECK ######################## if [ "${MM_ACTION}" != "dockers" ] && [ "${NM_SERVICES_CHECK[${NTYPE}]}" != "" ]; then echo -e "${idsCL[Green]} System Service(s)${idsCL[Default]}" DIVIDER . green ${DV_LEN} for srvc in "${!srvcs}"; do if [ ${item_number} -lt 10 ]; then isel=" ${item_number})"; elif [ ${item_number} -lt 100 ]; then isel=" ${item_number})"; else isel=" ${item_number})"; fi c=0; spc=''; spc1=`expr ${PRI_CW} - ${#NM_SERVICE_DESC[${srvc}]}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done echo -en "${idsCL[LightYellow]}${isel} ${idsCL[White]}${NM_SERVICE_DESC[${srvc}]}${spc}${idsCL[Default]}: " if [ "${choice}" -gt 0 ] 2>/dev/null && [ ${item_number} -eq ${choice} ]; then [ ! -f ${NM_TMPFOLDER}/${nip}~${srvc}.disable ] && touch ${NM_TMPFOLDER}/${nip}~${srvc}.disable || rm -f ${NM_TMPFOLDER}/${nip}~${srvc}.disable fi # ([ -f ${NM_TMPFOLDER}/${nip}~${srvc}.disable ] || ([[ "${nip}" = *"10.2."* ]] && [ -f ${PW_TMPFOLDER}/OFF-vMS-Host1.down ])) && dstatus="${idsCL[LightRed]}OFF" || dstatus="${idsCL[Green]}ON" [ -f ${NM_TMPFOLDER}/${nip}~${srvc}.disable ] && dstatus="${idsCL[LightRed]}OFF" || dstatus="${idsCL[Green]}ON" echo -e "${dstatus}${idsCL[Default]}" ((item_number++)) done fi ######################## ## DOCKER CHECK ######################## if [[ -v ${NTYPE}_DOCKERS_CHECK ]] && [ "${MM_ACTION}" != "services" ]; then [ "${MM_ACTION}" == "" ] && [ "${NM_SERVICES_CHECK[${NTYPE}]}" != "" ] && echo echo -e "${idsCL[Green]} Docker Service(s)${idsCL[Default]}" DIVIDER . green ${DV_LEN} for docker in "${!dockers}"; do if [ ${item_number} -lt 10 ]; then isel=" ${item_number})"; elif [ ${item_number} -lt 100 ]; then isel=" ${item_number})"; else isel=" ${item_number})"; fi c=0; spc=''; spc1=`expr ${PRI_CW} - ${#NM_DOCKER_DESC[${docker}]}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done echo -en "${idsCL[LightYellow]}${isel} ${idsCL[White]}${NM_DOCKER_DESC[${docker}]}$spc${idsCL[Default]}: " if [ "${choice}" -gt 0 ] 2>/dev/null && [ ${item_number} -eq ${choice} ]; then [ ! -f ${NM_TMPFOLDER}/${nip}~${docker}.disable ] && touch ${NM_TMPFOLDER}/${nip}~${docker}.disable || rm -f ${NM_TMPFOLDER}/${nip}~${docker}.disable fi # ([ -f ${NM_TMPFOLDER}/${nip}~${docker}.disable ] || ([[ "${nip}" = *"10.2."* ]] && [ -f ${PW_TMPFOLDER}/OFF-vMS-Host1.down ])) && dstatus="${idsCL[LightRed]}OFF" || dstatus="${idsCL[Green]}ON" [ -f ${NM_TMPFOLDER}/${nip}~${docker}.disable ] && dstatus="${idsCL[LightRed]}OFF" || dstatus="${idsCL[Green]}ON" echo -e "${dstatus}${idsCL[Default]}" ((item_number++)) done fi echo done fi ######################## ## REPLICATION CHECK ######################## if ([ "${STATUS_ACTION}" == "repl" ] || [ "${STATUS_ACTION}" == "" ]) && [ ! -z ${!repls+x} ]; then if [ "${MM_ACTION}" != "check" ]; then echo -e "${idsST[Bold]}${idsCL[LightCyan]} ${NM_NODETYPES[${NTYPE}]} Replication Check(s)${idsST[Reset]}${idsCL[Default]}" DIVIDER . lightCyan ${DV_LEN} fi PH=${NTYPE}_HOSTS[0] PH_CMD="${SSHCMD} root@${!PH}" var2=${NTYPE}_HOSTS[@] for nip in "${!hosts}"; do echo -e " ${idsCL[Green]}${NM_HOSTNAMES[${!PH}]}[${!PH}] <--> ${idsST[Bold]}${NM_HOSTNAMES[${nip}]}[${nip}]${idsST[Reset]}${idsCL[Default]}" DIVIDER . green ${DV_LEN} for rcheck in "${!repls}"; do if [ ${item_number} -lt 10 ]; then isel=" ${item_number})"; elif [ ${item_number} -lt 100 ]; then isel=" ${item_number})"; else isel=" ${item_number})"; fi c=0; spc=''; spc1=`expr ${PRI_CW} - ${#NM_REPL_DESC[${rcheck}]}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done echo -en "${idsCL[LightYellow]}${isel} ${idsCL[White]}${NM_REPL_DESC[${rcheck}]}${spc}${idsCL[Default]}: " if [ "${choice}" -gt 0 ] 2>/dev/null && [ ${item_number} -eq ${choice} ]; then [ ! -f ${NM_TMPFOLDER}/${nip}~${rcheck}.repl.disable ] && touch ${NM_TMPFOLDER}/${nip}~${rcheck}.repl.disable || rm -f ${NM_TMPFOLDER}/${nip}~${rcheck}.repl.disable fi #([ -f ${NM_TMPFOLDER}/${nip}~${rcheck}.repl.disable ] || ([[ "${nip}" = *"10.2."* ]] && [ -f ${PW_TMPFOLDER}/OFF-vMS-Host1.down ])) && dstatus="${idsCL[LightRed]}OFF" || dstatus="${idsCL[Green]}ON" [ -f ${NM_TMPFOLDER}/${nip}~${rcheck}.repl.disable ] && dstatus="${idsCL[LightRed]}OFF" || dstatus="${idsCL[Green]}ON" echo -e "${dstatus}${idsCL[Default]}" ((item_number++)) done echo done fi echo done echo -en "\n\033[K${idsCL[LightCyan]}Enter # to change notifications [${idsCL[Default]}(${idsCL[LightYellow]}E${idsCL[Default]})xit${idsCL[LightCyan]}] : ${idsCL[Default]}" read choice [ "${choice^^}" == "E" ] && break done echo } ESXI_ISCSI_STORAGE_RESCAN(){ [ "${1}" != "now" ] && sleep 30s for NIP in "${ESXIHOSTS[@]}"; do if [ $(CHECK_HOST ${NIP}) == true ]; then ${SSHCMD} root@${NIP} esxcli storage core adapter rescan --all & ${SSHCMD} root@${NIP} vmkfstools -V & fi done exit 0 } SETUPSSH(){ echo -e "\n${idsST[Bold]}${idsCL[LightCyan]}Beginning SSH verifiication, you may get prompted for credentials along the way\n" for NTYPE in "${NM_NODE_TYPES[@]}"; do echo -e "${idsST[Bold]}"; DIVIDER echo -e "${idsCL[Yellow]} ${NM_NODETYPES[$NTYPE]}-Nodes - Verifying SSH Connections Between All Nodes${idsCL[Default]}" DIVIDER; echo -e "${idsST[Reset]}" var=${NTYPE}_HOSTS[@] for nip in "${!var}"; do if [ "${RUN_NODE_IP}" != "${nip}" ]; then echo -e " ${idsST[Bold]}${idsCL[LightCyan]}${NM_HOSTNAMES[${nip}]}[${nip}]${idsST[Reset]}${idsCL[Default]}" DIVIDER . lightCyan 40 if [ ! -f ${NM_TMPFOLDER}/${nip}.down ]; then echo -en "\n${idsCL[LightCyan]}Checking for Public SSH Key ... ${idsCL[Default]}" if [ "$(ssh -o BatchMode=yes -o ConnectTimeout=3 root@${nip} echo ok 2>&1)" == "ok" ]; then echo -e "${idsCL[Green]}Already Installed${idsCL[Default]}" else echo -e "${idsCL[Yellow]}Copying to Host ...${idsCL[Default]}" ssh-copy-id root@${nip} fi # ${SSHCMD} root@${nip} "nmg setupssh_back" # echo -en "\n${idsCL[LightCyan]}Verifying NodeMgmt ... ${idsCL[Default]}" # NODEUPDATE ${nip} verify "ssh" else echo -e "\n${idsCL[Yellow]}Host is offline${idsCL[Default]}" fi echo fi done echo done for hostid in "${!host_ip[@]}"; do checkhost=$(CHECK_HOST ${host_ip[$hostid]}) if [ "${checkhost}" != "false" ]; then echo -e "${idsST[Bold]}${idsCL[LightCyan]} ${host_name[$hostid]} - SSH KEY COPY${idsCL[Default]}${idsST[Reset]}" ssh-copy-id root@${host_ip[$hostid]} fi done } SETUPSSH_BACK(){ echo -en "\n${idsCL[LightCyan]}$(hostname): Checking for Public SSH Key back to Node-Manager ... ${idsCL[Default]}" if [ "$(ssh -o BatchMode=yes -o ConnectTimeout=3 root@${NM_NODEMANAGER} echo ok 2>&1)" == "ok" ]; then echo -e "${idsCL[Green]}Already Installed${idsCL[Default]}" else echo -e "${idsCL[Yellow]}Copying to Node-Manager ...${idsCL[Default]}" ssh-copy-id root@${NM_NODEMANAGER} fi } SKIP_SERVER_CHECKS(){ if [ "${1}" == "on" ] || ([ ! -f ${NM_TMPFOLDER}/.skip ] && [ "${1}" == "" ]); then touch ${NM_TMPFOLDER}/.skip echo -e "${idsCL[Yellow]}Server will be skipped from Node-Manager Status Checks${idsCL[Default]}" if systemctl is-active --quiet keepalived; then echo -en "${idsCL[Red]}Stopping${idsCL[LightCyan]} Keepalived ... ${idsCL[Default]}" systemctl stop keepalived >/dev/null 2>&1 echo -e "${idsCL[Green]}Done${idsCL[Default]}" fi elif [ "${1}" == "off" ] || [ "${1}" == "reboot" ] || ([ -f ${NM_TMPFOLDER}/.skip ] && [ "${1}" == "" ]); then rm -f ${NM_TMPFOLDER}/.skip echo -e "${idsCL[LightGreen]}Server has been re-enabled for Node-Manager Status Checks${idsCL[Default]}" if [ "${1}" != "reboot" ] && [ "$(dpkg -l | grep keepalived)" ]; then echo -en "${idsCL[Green]}Starting${idsCL[LightCyan]} Keepalived ... ${idsCL[Default]}" systemctl start keepalived >/dev/null 2>&1 echo -e "${idsCL[Green]}Done${idsCL[Default]}" elif [ "${1}" == "reboot" ]; then reboot fi fi echo } LIST_SKIPPED_SERVERS(){ cw=40; rm -f /tmp/.nodeskipcheck.* echo declare -i spc1; declare -i c echo -e "${idsCL[LightGreen]}Checked for Skipped Nodes${idsCL[Default]}" echo -e "${idsCL[LightGreen]}-------------------------------------------${idsCL[Default]}" ncount=0 for NTYPE in "${NM_NODE_TYPES[@]}"; do var=${NTYPE}_HOSTS[@] for nip in "${!var}"; do if [ ! -f /tmp/.nodeskipcheck.${NM_HOSTNAMES[${nip}]// /-}.running ]; then touch /tmp/.nodeskipcheck.${NM_HOSTNAMES[${nip}]// /-}.running GETSKIP "${nip}" & ((ncount++)) fi done done nc_count=0; completed=false until [ "${completed}" == "true" ]; do for nodecmd in /tmp/.nodeskipcheck.*.done; do if [[ "${nodecmd}" != *"*"* ]]; then nodecmd_output=$(cat ${nodecmd}) [ "${nodecmd_output}" != "" ] && echo -e "${nodecmd_output}" rm -f ${nodecmd} ((nc_count++)) fi done if [ ${nc_count} -eq ${ncount} ]; then completed=true break fi sleep 2s done echo -e "\n${idsCL[Default]}${idsST[Reset]}" } GETSKIP(){ nip="${1}" NCMD="${SSHCMD} root@${nip}" if [ "${2}" == "" ]; then NODE="${NM_HOSTNAMES[${nip}]} [${nip}]" tmpfile=/tmp/.nodeskipcheck.${NM_HOSTNAMES[${nip}]// /-} c=0; spca=''; spc1=`expr ${cw} - ${#NODE}`; until [ $c = ${spc1} ]; do spca="${spca} "; c=`expr $c + 1`; done echo -en "Checking ${NODE}${spca}" >> ${tmpfile}.running if [ $(CHECK_HOST ${nip}) != false ]; then ${NCMD} [ -f ${NM_TMPFOLDER}/.skip ] && echo -e "${idsCL[LightRed]}SKIPPED${idsCL[Default]}" >> ${tmpfile}.running || echo "${idsCL[LightCyan]}NOT Skipped${idsCL[Default]}" >> ${tmpfile}.running else echo -e "${idsCL[Yellow]}OFFLINE${idsCL[Default]}" >> ${tmpfile}.running fi [ -f ${tmpfile}.running ] && mv ${tmpfile}.running ${tmpfile}.done || touch ${tmpfile}.done else RESULT=false if [ $(CHECK_HOST ${nip}) != false ]; then ${NCMD} [ -f ${NM_TMPFOLDER}/.skip ] && RESULT=true fi echo ${RESULT} fi } BETACHECK(){ [ "$(curl -sL https://git.schroedercity.com/voltron/NodeMgmt/raw/branch/master/defaults.inc | grep NM_BETA=true)" != "" ] && echo true || echo false } GUI(){ DISP_HEADER true false while : do echo " [1] Node Status" echo " [2] Node Services" echo echo " [3] New Site" echo " [4] Delete Site" echo echo " [5] New Certificate" echo " [6] Renew Certificates" echo " [7] List Certificates" echo echo " [8] Set folder permissions on nodes" echo " [9] Backup Node Settings and Files" echo echo " [D] Update Primary DNS Records" echo " [R] Add cron task to rotate wtmp & btmp log files" echo echo " [Q] Quit" echo echo echo -e -n "${idsCL[LightYellow]}Please select an [ActionItem] from above:${idsCL[Default]} " read -n 1 opt echo case $opt in 1) STATUS; GUI;; 2) SERVICES; GUI;; 3) NEWSITE; GUI;; 4) DELSITES; GUI;; 5) NEWCERT; GUI;; 6) CERTRENEW; GUI;; 7) LISTCERTS; GUI;; 8) SET-PERMISSIONS; GUI;; 9) BACKUP; GUI;; [Dd]) UPDATE_DYNDNS; GUI;; [Rr]) ADD_LOGROTATE_CRONTAB; GUI;; [Qq]) EXIT1 exit 0;; *) echo "Thats an invaild option,"; echo "please select a valid option only."; sleep 1;; esac done } # if [ ${action-x} ]; then if [[ "${noheader}" != *" ${1} "* ]] && [[ "${noheader}" != *" ${2} "* ]] && [[ "${noheader}" != *" ${3} "* ]] && [ "${2}" != "q" ] && [ "${3}" != "q" ]; then DISP_HEADER fi case ${NMG_ACTION} in newcert) NEWCERT ${2} ${3};; certrenew) CERTRENEW;; delcert) DEL-SSL ${2};; certs) LISTCERTS ${2} ${3} ${4} ${5} ${6};; copycerts) COPYCERTS ${2} ${3} ${4} ${5};; listcerts-npm) LISTCERTS_NPM;; copynpmcerts) COPYCERTS_NPM ${2};; checknpmcerts) CHECK_NPMCERTS;; checkcerts) CHECK-CERTS ${2} ${3} ${4} ${5} ${6};; nightlyrenew) if [ "${2}" == "q" ]; then mv -f ${NM_LOGFOLDER}/cert-renewal1.lastrun ${NM_LOGFOLDER}/cert-renewal2.lastrun mv -f ${NM_LOGFOLDER}/cert-renewal.lastrun ${NM_LOGFOLDER}/cert-renewal1.lastrun exec 3>&1 >>${NM_LOGFOLDER}/cert-renewal.lastrun 2>&1 echo "$(date +%Y-%m-%d-%H-%M-%S) #### Nightly Cert Renewal check Initiated ####" ${NM_SCRIPT} nightlyrenew report echo -e "\n$(date +%Y-%m-%d-%H-%M-%S)" else NIGHTLYRENEW fi ;; delsite) DELSITE ${2} ${3} ${4} ${5};; delsites) DELSITES;; newsite) NEWSITE ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14} ${15} ${16} ${17} ${18} ${19} ${20} ${21} ${22} ${23} ${24} ${25};; sites) SITEINFO ${2} ${3} ${4} ${5} ${6};; update) if [ "${2}" == "nodes" ]; then NODEUPDATES fi ;; update-nodes) if [ "${2}" == "report" ]; then [ "${3}" == "sync" ] && ufile=update-nodes-sync.lastrun || ufile=update-nodes.lastrun rm -f ${NM_LOGFOLDER}/${ufile} NODEUPDATES ${2} ${3} > ${NM_LOGFOLDER}/${ufile} else NODEUPDATES ${2} ${3} fi ;; setupssh) SETUPSSH ${2} ${3} ${4} ${5} ${6};; setupssh_back) SETUPSSH_BACK ${2} ${3} ${4} ${5} ${6};; betacheck) BETACHECK;; update-dyndns) UPDATE_DYNDNS ${2} ${3} ${4} ${5} ${6};; backup) BACKUP;; offsite-staticroute-fix) OFFSITE_STATICROUTE_FIX;; dl|downlist) if [ "${2}" = "report" ]; then if [ "$(find ${NM_FOLDER} -maxdepth 1 -name '*.down')" != "" ]; then rm -f ${NM_LOGFOLDER}/status-downlist.lastrun DOWNLIST report >> ${NM_LOGFOLDER}/status-downlist.lastrun STATUSLOG="$(cat ${NM_LOGFOLDER}/status-downlist.lastrun)" SENDNOTICE "Downlist Report" "Downlist Report\n${STATUSLOG}" fi else DOWNLIST ${2} fi;; mm) MAINTENANCE_MODE ${2} ${3};; status) if [ "${2}" == "freespace" ]; then STATUS freespace ${3} else if [ ! -f ${NM_TMPFOLDER}/.statusclean ] || [ $(expr $(date +%s) - $(stat -c %Y ${NM_TMPFOLDER}/.statusclean)) -ge 300 ]; then for oldstatus_check in ${NM_TMPFOLDER}/status-*; do if ! [[ "${oldstatus_check}" =~ "*" ]] && ! [[ "${oldstatus_check}" =~ ".stuck" ]] && [ $(expr $(date +%s) - $(stat -c %Y ${oldstatus_check})) -ge 60 ]; then rm -Rf ${oldstatus_check} fi done touch ${NM_TMPFOLDER}/.statusclean fi STATUSRUNS=($(find ${NM_TMPFOLDER}/* -maxdepth 1 -type d -iname "status-*" 2>/dev/null)) if [ "${2}" == "-h" ] || [ "${2}" == "-help" ]; then echo -e "Usage: ${idsCL[Yellow]}[nodemgmt or nmg] status {status-check}${idsCL[Default]} {" width=25 printf "%-${width}s- %s\n" " {status-check}" "By default will check everything, otherwise specifically specify item to check:" printf "%-${width}s- %s\n" " services" "Will verify status of all node services" printf "%-${width}s- %s\n" " dockers" "Will verify status of all node dockers" printf "%-${width}s- %s\n" " repl" "Will verify status of all node replications" echo -e "}\n" exit 0 else if [ ${#STATUSRUNS[@]} -lt 3 ] && ([ ! -f ${NM_TMPFOLDER}/.skip ] || ([ -f ${NM_TMPFOLDER}/.skip ] && [ "${2}" != "report" ])); then STATUS_START=$(date +%Y-%m-%d-%H-%M-%S) STATUSRUN_TMPFOLDER="${NM_TMPFOLDER}/status-${STATUS_START}" mkdir ${STATUSRUN_TMPFOLDER} touch "${STATUSRUN_TMPFOLDER}/status-check.running" rm -f ${NM_TMPFOLDER}/.overload if [ "${2}" == "report" ]; then echo "${STATUS_START} - LOCAL - ${NODE_HOSTNAME} - Starting Status Check" >> ${NM_LOGFILE} echo -e "${STATUS_START} - Starting status check #############################\n" > ${STATUSRUN_TMPFOLDER}/status-check.running STATUS report ${3} ${4} >> ${STATUSRUN_TMPFOLDER}/status-check.running echo -e "\n\n$(date +%Y-%m-%d-%H-%M-%S) - Finished status check #############################\n" >> ${STATUSRUN_TMPFOLDER}/status-check.running echo "$(date +%Y-%m-%d-%H-%M-%S) - LOCAL - ${NODE_HOSTNAME} - Completed Status Check" >> ${NM_LOGFILE} rm -f ${NM_LOGFOLDER}/status-check.lastrun if [ $(expr $(date +%s) - $(stat -c %Y ${NM_TMPFOLDER}/.replcheck)) -le 20 ]; then mv ${STATUSRUN_TMPFOLDER}/status-check.running ${NM_LOGFOLDER}/status-check.repl.lastrun else mv ${STATUSRUN_TMPFOLDER}/status-check.running ${NM_LOGFOLDER}/status-check.lastrun fi if [ "${3}" == "email" ]; then echo -e "\n\n" >> ${NM_LOGFOLDER}/status-check.lastrun DOWNLIST report >> ${NM_LOGFOLDER}/status-check.lastrun STATUSLOG="$(cat ${NM_LOGFOLDER}/status-check.lastrun)" SENDNOTICE "Status Report" "Status Report\n${STATUSLOG}" fi else STATUS ${2} ${3} ${4} fi rm -Rf ${STATUSRUN_TMPFOLDER} elif [ -f ${NM_TMPFOLDER}/.skip ]; then echo -e "${idsCL[Yellow]}HOST DISABLED - Not running status checks${idsCL[Default]}\n" rm -f ${NM_TMPFOLDER}/.statusclean ${NM_TMPFOLDER}/.replcheck ${NM_TMPFOLDER}/.replclean else [ "${MM_ACTION}" != "report" ] && echo -e "${idsCL[LightRed]}Whooooaaaaa there cowboy, we got 3 threads running already.... easy killer!${idsCL[Default]}\n" if [ ! -f ${NM_TMPFOLDER}/.overload ]; then SENDNOTICE "NODEMGMT OVERLOAD" "Whooooaaaaa there cowboy, we got 3 threads running already.... easy killer!" 1 touch ${NM_TMPFOLDER}/.overload elif [ $(expr $(date +%s) - $(stat -c %Y ${NM_TMPFOLDER}/.overload)) -ge 900 ]; then SENDNOTICE "NODEMGMT OVERLOAD" "OMG SAVE ME, IM BEING OVERRUN BY STATUS CHECKS!" 1 touch ${NM_TMPFOLDER}/.overload fi exit 1 fi fi fi;; scantimes) STATUS_SCANTIMES ${2} ${3} ${4} ${5};; set-permissions) SET-PERMISSIONS ${2};; service) if [[ ( "${2}" = "giteaxx" ) || ( "${2}" = "powerdns-adminxx" ) ]] && [ "${3}" = "start" ]; then #SET-PERMISSIONS ${2} SERVICE_MGMT ${2} start elif [[ ( "${2}" = "giteaxx" ) || ( "${2}" = "powerdns-adminxx" ) ]] && [ "${3}" = "restart" ]; then SERVICE_MGMT ${2} stop #SET-PERMISSIONS ${2} SERVICE_MGMT ${2} start elif [ "${2}" = "web" ]; then SERVICE_MGMT php5.6-fpm ${3} ${4} ${5} ${6} ${7} ${8} SERVICE_MGMT php7.2-fpm ${3} ${4} ${5} ${6} ${7} ${8} SERVICE_MGMT php7.3-fpm ${3} ${4} ${5} ${6} ${7} ${8} SERVICE_MGMT php7.4-fpm ${3} ${4} ${5} ${6} ${7} ${8} SERVICE_MGMT php8.2-fpm ${3} ${4} ${5} ${6} ${7} ${8} SERVICE_MGMT nginx ${3} ${4} elif [ "${2}" = "glusterdxx" ]; then SERVICE_MGMT glusterd stop else SERVICE_MGMT ${2} ${3} ${4} ${5} ${6} ${7} ${8} fi;; singleservercheck) SINGLE_SERVER_SERVICE_CHECK ${2} ${3} ${4} ${5} ${6};; haproxy-config) HAPROXY-CONFIG;; keepalive-config) KEEPALIVE-CONFIG;; vc-ssl) if [ "${2,,}" == "log" ] || [ "${3,,}" == "log" ]; then exec 3>&1 >>${NM_LOGFOLDER}/vc-ssl.log 2>&1 echo "$(date +%Y-%m-%d-%H-%M-%S) #### vCenter Update Initiated ####" ${NM_SCRIPT} vc-ssl report echo "$(date +%Y-%m-%d-%H-%M-%S) #### vCenter Update Completed #### " else VCENTER-SSL ${2,,} fi ;; run) RUN_COMMAND "${2}" "${3}" "${4}" "${5}" "${6}" "${7}";; backup-offsitepfsense) BACKUP_OFFSITEPFSENSE;; backup-unifiudm) BACKUP_UNIFIUDM;; backup-unifinvr) BACKUP_UNIFINVR;; test) # if [ ! -f /etc/rsyslog.d/01-ignore-session-messages.conf ] && [ -f ${NM_FOLDER}/conf/rsyslog/01-ignore-session-messages.conf ]; then cp -f ${NM_FOLDER}/conf/rsyslog/01-ignore-session-messages.conf /etc/rsyslog.d/01-ignore-session-messages.conf /bin/systemctl restart rsyslog # fi ;; skip) SKIP_SERVER_CHECKS ${2};; get-skips) LIST_SKIPPED_SERVERS;; sync-clean) REMOVE_CONFLICT_SYNC_FILES ${2};; nginxupdate) echo for nfile in ${NM_NGINXPATH}/sites-enabled/*.conf; do echo -en "Converting site: ${nfile##*/} ... " mv -f ${nfile} ${NM_NGINXPATH}/sites-available/${nfile##*/} ln -s ${NM_NGINXPATH}/sites-available/${nfile##*/} ${nfile} echo "Done" done if [[ "${RUN_NODE_IP}" != "10.6.1"* ]]; then SERVICE_MGMT nginx restart else /bin/systemctl restart nginx fi ;; gui) GUI;; *) echo -e "${idsCL[Yellow]}Commands followed by '-h' will show specific command help. {work-in-progress}${idsCL[Default]}" echo echo -e "Usage: ${idsCL[LightCyan]}[nodemgmt or nmg] ${idsCL[Yellow]}{COMMAND} ${idsCL[LightYellow]}{FLAGS}${idsCL[Default]} {" echo echo -e " ${idsCL[Yellow]}sites${idsCL[Default]} - Manage NGINX Sites" echo -e " ${idsCL[Yellow]}newsite${idsCL[Default]} - Create a New Site" echo -e " ${idsCL[Yellow]}delcert${idsCL[Default]} - Delete a Site" echo echo -e " ${idsCL[Yellow]}certs${idsCL[Default]} - Manage SSL Certificates" echo -e " ${idsCL[Yellow]}newcert${idsCL[Default]} - Generate New SSL Certificate" echo -e " ${idsCL[Yellow]}delcert${idsCL[Default]} - Delete SSL Certificate" echo echo -e " ${idsCL[Yellow]}certrenew${idsCL[Default]} - Renew all SSL Certificates" echo -e " ${idsCL[Yellow]}checkcerts${idsCL[Default]} - Check SSL Expirations on Monitored Certs" echo -e " ${idsCL[Yellow]}nightlyrenew${idsCL[Default]} - Renewal of SSL Certs, designed for cron tasks" echo -e " ${idsCL[Yellow]}vc-ssl${idsCL[Default]} - Update vCenter SSL" echo echo -e " ${idsCL[Yellow]}service${idsCL[Default]} - Manage services on all nodes, or nodetypes" echo -e " ${idsCL[Yellow]}downlist | dl${idsCL[Default]} - Displays all down services and/or hosts" echo -e " ${idsCL[Yellow]}run${idsCL[Default]} - Run a command on all Nodes" echo -e " ${idsCL[Yellow]}status${idsCL[Default]} - Check Status of systems" echo echo -e " ${idsCL[Yellow]}backup${idsCL[Default]} - Run backup of node items" echo -e " ${idsCL[Yellow]}haproxy-config${idsCL[Default]} - Push out haproxy config" echo -e " ${idsCL[Yellow]}set-permissions${idsCL[Default]} - Set specific permissions preset for app folders" echo echo -e " ${idsCL[Yellow]}update${idsCL[Default]} - Update nodemgmt" echo -e " ${idsCL[Yellow]}update-nodes${idsCL[Default]} - Update nodemgmt on all nodes" echo -e " ${idsCL[Yellow]}update-dyndns${idsCL[Default]} - Update DYNDNS records" echo echo -e "}" echo echo exit 0;; esac # else # GUI # fi exit 0