#!/usr/bin/env bash # MySQL-BU - MySQL Backup Scripts action="$1" VERS='1.01272019' CERT_DAEMON='/usr/bin/certbot' source /opt/idssys/nodemgmt/settings.conf source /opt/idssys/defaults/colors.inc source /opt/idssys/defaults/default.inc # ========================================================= # MAIN_MENU() { while : do clear echo "" echo -e "${idsCL[LightGreen]} NodeMgmt - Galera/NGINX Node Management${idsCL[Default]} ${idsCL[DarkGray]}(ver-${VERS})${idsCL[Default]}" echo -e "${idsCL[LightGreen]}-----------------------------------------------------------------${idsCL[Default]}" echo -e "Node hostname: ${node_hostname}" echo -e "${idsCL[LightGreen]}-----------------------------------------------------------------${idsCL[Default]}" echo "" echo " [1] Change Backup Location" echo " [2] Change MySQL User" echo " [3] Change MySQL Password" echo " [4] Change MySQL Config File Location" echo " [5] Change The Number of Backup Days to Keep" echo "" echo " [B] Run Backup" echo " [L] List Backups" echo " [D] Delete Backups" echo "" echo " [C] Add Crontab Entry to run every 3 Hours" echo -e " ${idsCL[DarkGray]}(edit crontab manually to adjust the backup frequency)${idsCL[Default]}" 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) WEBMIN_INSTALL INSTALL_MENU;; 2) GLANCES_INSTALL INSTALL_MENU;; 3) X11VNC_INSTALL INSTALL_MENU;; 4) FW_INSTALL INSTALL_MENU;; 5) LINUPX_UNINSTALL INSTALL_MENU;; [Bb]) RUN_BACKUP;; [Ll]) LIST_BACKUPS;; [Dd]) DELETE_MENU;; [Cc]) ADD_CRONTAB;; [Qq]) EXIT1 exit 1;; *) echo "Thats an invaild option,"; echo "please select a valid option only."; sleep 1;; esac done } case "$1" in start) sleep 15 echo -e "${BBlue}HAProxy Starting...${Color_Off}" service haproxy start ssh root@10.5.10.52 service haproxy start ssh root@10.5.10.53 service haproxy start echo -e "${BBlue}NGINX Reload...${Color_Off}" service nginx reload ssh root@10.5.10.52 service nginx reload ssh root@10.5.10.53 service nginx reload exit 0 ;; stop) echo -e "${BBlue}HAProxy Stopping...${Color_Off}" service haproxy stop ssh root@10.5.10.52 service haproxy stop ssh root@10.5.10.53 service haproxy stop exit 0;; gogs-start) echo -e "${BBlue}Gogs Starting...${Color_Off}" service gogs start ssh root@10.5.10.52 service gogs start ssh root@10.5.10.53 service gogs start exit 0;; gogs-stop) echo -e "${BBlue}Gogs Stopping...${Color_Off}" service gogs stop ssh root@10.5.10.52 service gogs stop ssh root@10.5.10.53 service gogs stop exit 0;; gogs-restart) echo -e "${BBlue}Gogs Restarting...${Color_Off}" service gogs restart ssh root@10.5.10.52 service gogs restart ssh root@10.5.10.53 service gogs restart exit 0;; nginx-start) echo -e "${BBlue}NGINX Starting...${Color_Off}" service nginx start ssh root@10.5.10.52 service nginx start ssh root@10.5.10.53 service nginx start exit 0;; nginx-stop) echo -e "${BBlue}NGINX Stopping...${Color_Off}" service nginx stop ssh root@10.5.10.52 service nginx stop ssh root@10.5.10.53 service nginx stop exit 0;; nginx-restart) echo -e "${BBlue}NGINX Restarting...${Color_Off}" service nginx restart ssh root@10.5.10.52 service nginx restart ssh root@10.5.10.53 service nginx restart exit 0;; reload) service nginx reload ssh root@10.5.10.52 service nginx reload ssh root@10.5.10.53 service nginx reload exit 0 ;; new) # "$0" stop echo -e "${Green}Requesting Certificate for '${BBlue}$2${Green}'...${Color_Off}" # $DAEMON certonly --standalone -d $2 $DAEMON certonly --webroot -w /var/www/html -d $2 # chown -R root:letsencrypt /etc/letsencrypt # chmod -R 6775 /etc/letsencrypt # "$0" start # redirect_artica-ssl_files exit 0 ;; new-mass) echo -e "${Green}Requesting Certificate for '${BBlue}$2${Green}'...${Color_Off}" # $DAEMON certonly --standalone -d $2 $DAEMON certonly --webroot -w /var/www/html -d $2 # chown -R root:letsencrypt /etc/letsencrypt # chmod -R 6775 /etc/letsencrypt # redirect_artica-ssl_files exit 0 ;; renew) "$0" stop echo -e "${Green}Renewing Certificates...${Color_Off}" # $DAEMON renew $DAEMON renew certonly --webroot -w /var/www/html -d $2 chown -R root:letsencrypt /etc/letsencrypt chmod -R 6775 /etc/letsencrypt "$0" start # redirect_artica-ssl_files exit 0 ;; nightlyrenew) rm -f /opt/nodemgmt/cert-renewal-run-$(hostname) "$0" stop >> /opt/nodemgmt/cert-renewal-run-$(hostname) # $DAEMON renew >> /opt/nodemgmt/cert-renewal-run-$(hostname) $DAEMON renew certonly --webroot -w /var/www/html -d $2 >> /opt/nodemgmt/cert-renewal-run-$(hostname) chown -R root:letsencrypt /etc/letsencrypt chmod -R 6775 /etc/letsencrypt "$0" start >> /opt/nodemgmt/cert-renewal-run-$(hostname) exit 0 ;; redirect-ssl) redirect_artica-ssl_files service nginx restart read -n 1 -t 10 -p "Are you sure you wish to reboot (y/N)?" redirect_choice case "$redirect_choice" in [Yy]) if [ "$EUID" -ne 0 ] then service artica-webservices restart fi exit 0;; esac exit 0;; 'gui') MAIN_MENU;; *) echo echo echo "'new' - Creates a new certificate." echo "---------------------------------------------------------------------------------------" echo "examples:" echo " single-domain = 'nodemgmt new www.example.com'" echo " multiple-domains = 'nodemgmt new www.example.com,dev.example.com,...'" echo echo "'new-mass' - Creates a new certificate, but doesnt go through the" echo " process of stopping and restarting nginx each time" echo "---------------------------------------------------------------------------------------" echo "examples (same as 'new'):" echo " single-domain = 'nodemgmt new-mass www.example.com'" echo " multiple-domains = 'nodemgmt new-mass www.example.com,dev.example.com,...'" echo echo "'renew' - Renews all certificates. This command could be run routinly by adding this" echo " line into crontab: \"0 4 * * 0 /usr/local/bin/nodemgmt renew\"" echo "---------------------------------------------------------------------------------------" echo "examples:" echo " 'nodemgmt renew'" echo echo "'redirect-ssl' - Redirects the configured Artica certificates to use the LetsEncrypt certificates" echo "---------------------------------------------------------------------------------------" echo "examples:" echo " 'nodemgmt redirect-ssl'" echo echo "'stop' - Stops any process that interfere with creating a standalone server" echo "---------------------------------------------------------------------------------------" echo "examples:" echo " 'nodemgmt stop'" echo echo "'start' - Starts any process that had interfered with creating a standalone server" echo "---------------------------------------------------------------------------------------" echo "examples:" echo " 'nodemgmt start'" echo exit 1 ;; esac exit 0