Update porygon-management.sh

This commit is contained in:
2026-10-11 11:34:41 +00:00
parent 470c57a6f4
commit 3a69e77cf5
+38
View File
@@ -133,6 +133,39 @@ echo "making directory for apache"
cp /root/templates/metrics_page.html /var/www/porygon/"$HOSTNAME"/index.html
}
remove_server() {
read -p "enter the hostname of the server you would like to remove from porygon management: " HOSTNAME
jq -e --arg host "$HOSTNAME" 'has($host)' "$SERVERS_JSON" >/dev/null || {
echo "$HOSTNAME not found in servers.json file"
exit 1
}
cp "$SERVERS_JSON" "$SERVERS_JSON".old
jq --arg host "$HOSTNAME" 'del(.[$host])' "$SERVERS_JSON" > /tmp/servers.json && mv /tmp/servers.json "$SERVERS_JSON"
ssh -i "$PORYGON_LXC_KEY" root@"$PORYGON_LXC_IP" 'cp /root/servers.json /root/servers.json.old'
ssh -i "$PORYGON_LXC_KEY" root@"$PORYGON_LXC_IP" \
"jq --arg host '$HOSTNAME' 'del(.[\$host])' /root/servers.json > /tmp/servers.json \
&& mv /tmp/servers.json /root/servers.json" || {
echo "failed to remove $HOSTNAME from porygon lxc"
exit 1
}
rm -rf /var/www/porygon/"$HOSTNAME"
echo -e "\n\nsuccessfully removed $HOSTNAME from porygon monitoring \\(^0^)/\n\n"
TO_ADD=$(sed 's/\$HOSTNAME/'"$HOSTNAME"'/g' /root/templates/main-page-paste.html)
echo -e "remove the following from /var/www/porygon/index.html\n\n$TO_ADD"
exit 0
}
######RUNNING INTRO###########
@@ -165,10 +198,15 @@ while getopts "udkph" flag; do
ANSIBLE_PORT=(-e ansible_port="$PORT")
;;
r)
remove_server
;;
h)
echo -e "Options:\n-d - DEBUG - runs ansible with verbose (-vvv) flags\n\
-h - HELP - displays this help page\n-k - KEY - specifies connecting over ssh with a private key\n\
-p - PORT - specifies which port to connect over ssh with\n\
-r - REMOVE - specifies which server to remove from porygon monitoring\n\
-u - USER - specifies a user to connect over ssh and run the ansible playbook with"
exit 0
;;