Files
NodeMgmt/nodemgmt-scripts.sh

160 lines
5.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# MySQL-BU - MySQL Backup Scripts
action="$1"
VERS='1.01272019'
CERT_DAEMON='/usr/bin/certbot'
SCRIUPT=
source /opt/idssys/nodemgmt/settings.conf
source /opt/idssys/defaults/colors.inc
source /opt/idssys/defaults/default.inc
NODE_HOSTS=`$NERE -s -N -e "SELECT value FROM idssys.nodemgmt WHERE var = 'NODE_HOSTS'"`
IFS=,
NODE_HOSTS=(${NODE_HOSTS})
unset IFS
# ========================================================= #
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" = "stop" ]; then ADISP='Stopp'; else ADISP="$(tr '[:lower:]' '[:upper:]' <<< ${3:0:1})${3:1}"; fi
if [ "$3" = "start" ] && [ "$2" = "haproxy" ]; then TACT='restart'; echo "YESSSSSS"; else TACT="${3}"; fi
echo -e "${idsCL[LightGreen]}[[${SER} ${ADSIP}ing]]${idsCL[Default]}"
echo -e "${idsCL[LightGreen]}-------------------------------------------${idsCL[Default]}"
nid=1
for nip in "${NODE_HOSTS[@]}"
do
echo -en "${ADISP}ing Node ${nid} ($nip)...${idsCL[Default]}"
ssh root@${nip} systemctl $3 $2
if [[ $(is_service_running ${nip} ${2}) -gt "1" ]]; then
echo -e "${idsCL[Green]}OK${idsCL[Default]}"
else echo -e "${idsCL[Red]}ERROR${idsCL[Default]}"
fi
nid=`expr $nid + 1`
done
echo ""
echo -e "${idsCL[Green]}${SER} has been ${ADISP}ed${idsCL[Default]}"
echo ""
exit 0
;;
newcert)
"$0" service haproxy stop
echo -e "${idsCL[LightGreen]}Requesting Certificate for '${idsCL[Yellow]}${2}${idsCL[LightGreen]}'...${idsCL[Default]}"
# $DAEMON certonly --standalone -d $2
$CERT_DAEMON certonly --webroot -w /var/www/html -d $2
# chown -R root:letsencrypt /etc/letsencrypt
# chmod -R 6775 /etc/letsencrypt
"$0" service haproxy start
echo -e "${idsCL[LightGreen]}Waiting for Certificate Replication...${idsCL[Default]}"
sleep 20
"$0" service 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