100 lines
3.2 KiB
Bash
Executable File
100 lines
3.2 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
|
|
|
|
if [[ "$1" = "service" ]]; then
|
|
NODE_HOSTS=`${ids_mysql_conn} -s -N -e "SELECT value FROM idssys.nodemgmt WHERE var = 'NODE_HOSTS'"`
|
|
fi
|
|
|
|
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'; else TACT="${3}"; fi
|
|
|
|
echo -e "${idsCL[LightGreen]}[[${SER} ${ADISP}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]}"
|
|
elif [ "$3" = "Stop" ]; then echo -e "${idsCL[Red]}STOPPED${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)
|
|
echo -e "${idsCL[LightGreen]}Requesting Certificate for '${idsCL[Yellow]}${2}${idsCL[LightGreen]}'...${idsCL[Default]}"
|
|
do_with_root $CERT_DAEMON certonly --webroot -w /var/www/html -d $2
|
|
do_with_root chown -R root:letsencrypt /etc/letsencrypt
|
|
do_with_root chmod -R 6775 /etc/letsencrypt
|
|
echo -e "${idsCL[LightGreen]}Waiting for Certificate Replication...${idsCL[Default]}"
|
|
sleep 20
|
|
"$0" service nginx reload
|
|
exit 0
|
|
;;
|
|
|
|
certrenew)
|
|
echo -e "${idsCL[LightGreen]}Renewing Certificates...${idsCL[Default]}"
|
|
do_with_root $DAEMON renew --webroot -w /var/www/html
|
|
do_with_root chown -R root:letsencrypt /etc/letsencrypt
|
|
do_with_root chmod -R 6775 /etc/letsencrypt
|
|
echo -e "${idsCL[LightGreen]}Waiting for Certificate Replication...${idsCL[Default]}"
|
|
sleep 20
|
|
"$0" service nginx reload
|
|
exit 0
|
|
;;
|
|
|
|
nightlyrenew)
|
|
rm -f /opt/idssys/nodemgmt/cert-renewal-run-$(hostname)
|
|
do_with_root $DAEMON renew --webroot -w /var/www/html >> /opt/idssys/nodemgmt/cert-renewal-run-$(hostname)
|
|
do_with_root chown -R root:letsencrypt /etc/letsencrypt >> /opt/idssys/nodemgmt/cert-renewal-run-$(hostname)
|
|
do_with_root chmod -R 6775 /etc/letsencrypt >> /opt/idssys/nodemgmt/cert-renewal-run-$(hostname)
|
|
sleep 20
|
|
"$0" service nginx reload >> /opt/idssys/nodemgmt/cert-renewal-run-$(hostname)
|
|
exit 0
|
|
;;
|
|
|
|
update)
|
|
echo -en "\e[1A";
|
|
echo -e "\e[0K\r ${idsCL[Green]}Updates Completed${idsCL[Default]}"
|
|
echo ""
|
|
exit 0;;
|
|
|
|
*)
|
|
echo ""
|
|
echo -e "Usage: ${idsCL[Yellow]}nodemgmt${idsCL[Default]} { ${idsCL[Yellow]}service${idsCL[Default]} [service] [action] | ${idsCL[Yellow]}newcert${idsCL[Default]} [domain(,s)] | ${idsCL[Yellow]}certrenew${idsCL[Default]} }"
|
|
echo ""
|
|
exit 1
|
|
;;
|
|
|
|
esac
|
|
|
|
exit 0 |