222 lines
6.8 KiB
Bash
Executable File
222 lines
6.8 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
|
|
|
|
IFS=','
|
|
node_hosts=(${node_hosts})
|
|
unset IFS
|
|
|
|
# ========================================================= #
|
|
|
|
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
|
|
|
|
echo ""
|
|
STA="$(tr '[:lower:]' '[:upper:]' <<< ${3:0:1})${3:1}"
|
|
echo -e "${idsCL[LightGreen]}[[${SER} ${STA}ing]]${idsCL[Default]}"
|
|
|
|
for i in "${node_hosts}"
|
|
do
|
|
echo "Here: ${i}"
|
|
done
|
|
|
|
echo -en "${idsCL[Cyan]}${STA}ing Node 1...${idsCL[Default]}"
|
|
ssh root@10.5.10.51 systemctl $3 $2
|
|
if [[ $(ssh root@10.5.10.51 ps -ef | grep -c ${2}) -ne 1 ]]; then
|
|
echo -e "${idsCL[Green]}OK${idsCL[Default]}"
|
|
else echo -e "${idsCL[Red]}ERROR${idsCL[Default]}"
|
|
fi
|
|
|
|
echo -en "${idsCL[Cyan]}${STA}ing Node 2...${idsCL[Default]}"
|
|
ssh root@10.5.10.52 systemctl $3 $2
|
|
if [[ $(ssh root@10.5.10.52 ps -ef | grep -c ${2}) -ne 1 ]]; then
|
|
echo -e "${idsCL[Green]}OK${idsCL[Default]}"
|
|
else echo -e "${idsCL[Red]}ERROR${idsCL[Default]}"
|
|
fi
|
|
|
|
echo -en "${idsCL[Cyan]}${STA}ing Node 3...${idsCL[Default]}"
|
|
ssh root@10.5.10.53 systemctl $3 $2
|
|
if [[ $(ssh root@10.5.10.53 ps -ef | grep -c ${2}) -ne 1 ]]; then
|
|
echo -e "${idsCL[Green]}OK${idsCL[Default]}"
|
|
else echo -e "${idsCL[Red]}ERROR${idsCL[Default]}"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${idsCL[Green]}${SER} has been ${STA}ed${idsCL[Default]}"
|
|
echo ""
|
|
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 |