Files
NodeMgmt/nodemgmt-scripts.sh

266 lines
8.1 KiB
Bash
Executable File

#!/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
service)
if [ "$2" = "nginx" ]; then SER='NGINX'
elif [ "$2" = "haproxy" ]; then SER='HAProxy'
elif [ "$2" = "gogs" ]; then SER='Gogs'
fi
if [ "$3" = "start" ]; then STA='Starting'
elif [ "$3" = "stop" ]; then STA='Stopping'
elif [ "$3" = "restart" ]; then STA='Restarting'
elif [ "$3" = "reload" ]; then STA='Reloading'
fi
echo -e "${idsCL[LightBlue]}${SER} ${STA}...${idsCL[Default]}"
ssh root@10.5.10.51 systemctl $3 $2
ssh root@10.5.10.52 systemctl $3 $2
ssh root@10.5.10.53 systemctl $3 $2
exit 0
;;
haproxy-start)
sleep 15
echo -e "${idsCL[LightBlue]}HAProxy Starting...${idsCL[Default]}"
ssh root@10.5.10.51 service haproxy start
ssh root@10.5.10.52 service haproxy start
ssh root@10.5.10.53 service haproxy start
exit 0;;
haproxy-stop)
echo -e "${idsCL[LightBlue]}HAProxy Stopping...${idsCL[Default]}"
ssh root@10.5.10.51 service haproxy stop
ssh root@10.5.10.52 service haproxy stop
ssh root@10.5.10.53 service haproxy stop
exit 0;;
haproxy-restart)
sleep 15
echo -e "${idsCL[LightBlue]}HAProxy Starting...${idsCL[Default]}"
ssh root@10.5.10.51 service haproxy restart
ssh root@10.5.10.52 service haproxy restart
ssh root@10.5.10.53 service haproxy restart
exit 0;;
gogs-start)
echo -e "${idsCL[LightBlue]}Gogs Starting...${idsCL[Default]}"
ssh root@10.5.10.51 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 "${idsCL[LightBlue]}Gogs Stopping...${idsCL[Default]}"
ssh root@10.5.10.51 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 "${idsCL[LightBlue]}Gogs Restarting...${idsCL[Default]}"
ssh root@10.5.10.51 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 "${idsCL[LightBlue]}NGINX Starting...${idsCL[Default]}"
ssh root@10.5.10.51 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 "${idsCL[LightBlue]}NGINX Stopping...${idsCL[Default]}"
ssh root@10.5.10.51 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 "${idsCL[LightBlue]}NGINX Restarting...${idsCL[Default]}"
ssh root@10.5.10.51 service nginx restart
ssh root@10.5.10.52 service nginx restart
ssh root@10.5.10.53 service nginx restart
exit 0;;
nginx-reload)
echo -e "${idsCL[LightBlue]}NGINX Reloading...${idsCL[Default]}"
ssh root@10.5.10.51 service nginx reload
ssh root@10.5.10.52 service nginx reload
ssh root@10.5.10.53 service nginx reload
exit 0
;;
newcert)
"$0" haperoxy-stop
echo -e "${Green}Requesting Certificate for '${BBlue}$2${Green}'...${idsCL[Default]}"
# $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" haproxy-start
echo -e "${Green}Waiting for Certificate Replication...${idsCL[Default]}"
sleep 20
"$0" nginx-reload
exit 0
;;
newmass)
echo -e "${Green}Requesting Certificate for '${BBlue}$2${Green}'...${idsCL[Default]}"
# $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
exit 0
;;
certrenew)
"$0" haperoxy-stop
echo -e "${Green}Renewing Certificates...${idsCL[Default]}"
# $DAEMON renew
$DAEMON renew certonly --webroot -w /var/www/html -d $2
#chown -R root:letsencrypt /etc/letsencrypt
#chmod -R 6775 /etc/letsencrypt
"$0" haperoxy-start
echo -e "${Green}Waiting for Certificate Replication...${idsCL[Default]}"
sleep 20
"$0" nginx-reload
exit 0
;;
nightlyrenew)
rm -f /opt/idssys/nodemgmt/cert-renewal-run-$(hostname)
"$0" stop >> /opt/idssys/nodemgmt/cert-renewal-run-$(hostname)
# $DAEMON renew >> /opt/idssys/nodemgmt/cert-renewal-run-$(hostname)
$DAEMON renew certonly --webroot -w /var/www/html -d $2 >> /opt/idssys/nodemgmt/cert-renewal-run-$(hostname)
#chown -R root:letsencrypt /etc/letsencrypt
#chmod -R 6775 /etc/letsencrypt
"$0" start >> /opt/idssys/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