pve: rm old scripts
migrate_running, return_migrate replaced by HA maintenance mode stalk_updates was very hacky and broken now.. there's not a good way to get number of sec updates on debian systems tbh
This commit is contained in:
@@ -8,37 +8,31 @@ esac
|
|||||||
|
|
||||||
source /root/telegram.env
|
source /root/telegram.env
|
||||||
|
|
||||||
alias updl="apt update -q && apt full-upgrade --download-only -y -qq && apt autoremove -y -qq"
|
alias updl="rup && apt update -q && apt full-upgrade --download-only -y -qq && apt autoremove -y -qq"
|
||||||
|
#TODO: reinstate restic
|
||||||
alias rup="restic -q -r local:/root/jc/restic/"$HOSTNAME" -p /root/jc/restic/passwd backup /etc ~/.bash_history && restic -q -r local:/root/jc/restic/"$HOSTNAME" -p /root/jc/restic/passwd forget --prune --keep-last 14 --keep-within 3m --keep-weekly 520"
|
alias rup="restic -q -r local:/root/jc/restic/"$HOSTNAME" -p /root/jc/restic/passwd backup /etc ~/.bash_history && restic -q -r local:/root/jc/restic/"$HOSTNAME" -p /root/jc/restic/passwd forget --prune --keep-last 14 --keep-within 3m --keep-weekly 520"
|
||||||
#TODO: restic -p ~/jc/restic/passwd -r local:"??no more nas??/restic/$HOSTNAME" init
|
#TODO: restic -p ~/jc/restic/passwd -r local:"??no more nas??/restic/$HOSTNAME" init
|
||||||
|
|
||||||
function up {
|
function waitNoRunning {
|
||||||
read -p "where to? " whereto
|
echo '- - - - - - - - Waiting VMs to migrate or shutdown 200s - - - - - - - -'
|
||||||
if ! ~/jc/migrate_running.sh "$HOSTNAME" "$whereto"; then
|
while true; do
|
||||||
tgmsg tgmsg 'ERROR: up: migrate'
|
if "$(basedir "$0")"/confirm_norunning.sh "$@" >/dev/null; then
|
||||||
return 1
|
return
|
||||||
fi
|
|
||||||
echo restic…
|
|
||||||
if ! rup; then
|
|
||||||
tgmsg 'ERROR: up: restic'
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if ! updl; then
|
|
||||||
tgmsg 'ERROR: up: download'
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
function upg {
|
|
||||||
if ! ~/jc/confirm_norunning.sh; then
|
|
||||||
tgmsg 'ERROR: upg: migratables present'
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! ~/jc/shutdown_nomigrates.sh; then
|
sleep 3
|
||||||
|
printf .
|
||||||
|
done
|
||||||
|
}
|
||||||
|
export -f waitNoRunning
|
||||||
|
|
||||||
|
function upg {
|
||||||
|
if ! "$(basedir "$0")"/shutdown_nomigrates.sh; then
|
||||||
tgmsg 'ERROR: upg: signaling nomigrate shutdowns'
|
tgmsg 'ERROR: upg: signaling nomigrate shutdowns'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if ! timeout 200 bash -c waitNomigrateShutdown; then
|
|
||||||
|
if ! timeout 200 bash -c waitNomigrateShutdown 0; then
|
||||||
tgmsg 'ERROR: upg: running VMs before upgrade'
|
tgmsg 'ERROR: upg: running VMs before upgrade'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -49,25 +43,13 @@ function upg {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function waitNomigrateShutdown {
|
|
||||||
echo '- - - - - - - - Waiting nomigrate to shutdown 200s - - - - - - - -'
|
|
||||||
while true; do
|
|
||||||
if ~/jc/confirm_norunning.sh 1 >/dev/null; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep 3
|
|
||||||
printf .
|
|
||||||
done
|
|
||||||
}
|
|
||||||
export -f waitNomigrateShutdown
|
|
||||||
|
|
||||||
function upgr {
|
function upgr {
|
||||||
up || return $?
|
# shellcheck disable=SC2119
|
||||||
|
off || return $?
|
||||||
upg || return $?
|
upg || return $?
|
||||||
|
|
||||||
# double confirmation
|
# double confirmation
|
||||||
if ! timeout 200 bash -c waitNomigrateShutdown; then
|
if ! timeout 200 bash -c waitNomigrateShutdown 1; then
|
||||||
tgmsg 'ERROR: upgr: running VMs before reboot'
|
tgmsg 'ERROR: upgr: running VMs before reboot'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -75,13 +57,24 @@ function upgr {
|
|||||||
reboot
|
reboot
|
||||||
}
|
}
|
||||||
|
|
||||||
function toh {
|
function _off {
|
||||||
~/jc/return_migrate.sh ~/jc/desired.yaml "$@"
|
ha-manager crm-command node-maintenance enable "$1" && \
|
||||||
tgmsg "return_migrate finished: $?"
|
echo "$1": maintenance mode
|
||||||
}
|
}
|
||||||
|
|
||||||
alias des="vim ~/jc/desired.yaml"
|
# shellcheck disable=SC2120
|
||||||
alias h="echo 'avail cmds: up upg upgr | toh des | localprogress'"
|
function off {
|
||||||
|
if [[ "$#" -gt 0 ]]; then
|
||||||
|
_off "$@"
|
||||||
|
return "$?"
|
||||||
|
else
|
||||||
|
_off "$HOSTNAME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
updl
|
||||||
|
}
|
||||||
|
|
||||||
|
alias h="echo 'avail cmds: updl upg upgr | localprogress'"
|
||||||
|
|
||||||
function localprogress () {
|
function localprogress () {
|
||||||
watch ls -lh "/var/lib/vz/images/$1"
|
watch ls -lh "/var/lib/vz/images/$1"
|
||||||
|
@@ -1,9 +0,0 @@
|
|||||||
# If not running interactively, don't do anything
|
|
||||||
case $- in
|
|
||||||
*i*) ;;
|
|
||||||
*) return;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if timeout 5 cat "/root/jc/bashrc" >> /dev/null; then
|
|
||||||
source "/root/jc/bashrc"
|
|
||||||
fi
|
|
@@ -1,24 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if ! which jq >> /dev/null; then
|
|
||||||
echo "jq not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$#" -ne 2 ]; then
|
|
||||||
pvesh get /nodes
|
|
||||||
echo "usage: $0 <node_from> <node_to>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
from="$1"
|
|
||||||
target="$2"
|
|
||||||
|
|
||||||
migratable_ids="$(pvesh get "/nodes/${from}/qemu" --output-format json |\
|
|
||||||
jq -r 'map(select( .status == "running" and (.tags | split(";") | all(.!="nomigrate")) ) | .vmid) | @csv')"
|
|
||||||
|
|
||||||
if [[ "$migratable_ids" != "" ]]; then
|
|
||||||
echo "$from $target $migratable_ids"
|
|
||||||
pvesh create "/nodes/${from}/migrateall" -vms "$migratable_ids" -target "$target"
|
|
||||||
fi
|
|
@@ -1,37 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
source ~/jc/telegram.env
|
|
||||||
|
|
||||||
set -e
|
|
||||||
if [ "$#" -lt 1 ]; then
|
|
||||||
echo "usage: return_migrate.sh <file_desired_state> [single destination]"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if ! which jq >> /dev/null; then
|
|
||||||
echo "jq not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if ! which yq >> /dev/null; then
|
|
||||||
echo "yq not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
desired_file="$1"
|
|
||||||
single="$2"
|
|
||||||
|
|
||||||
#TODO: warn about nodes not in the file
|
|
||||||
#TODO: warn about VMs w/o nomigrate not in the file
|
|
||||||
yq -r 'keys[]' "$desired_file" | grep -v '^ *#' | while IFS= read -r desired_node; do
|
|
||||||
# validation of nodes and ids would be nice
|
|
||||||
desired_ids="$(yq -r --arg node "$desired_node" '.[$node][]' "$desired_file" | tr '\n' ',')"
|
|
||||||
pvesh get "/nodes" --output-format json | jq -r '.[] | select(.status == "online") | .node' | grep -v '^ *#' | while IFS= read -r node_from; do
|
|
||||||
if [[ "$node_from" != "$desired_node" ]]; then # not local / recursion
|
|
||||||
if [[ ! -z "$single" ]] && [[ "$desired_node" != "$single" ]]; then
|
|
||||||
echo skipping $node_from $desired_node $desired_ids
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo $node_from $desired_node $desired_ids
|
|
||||||
pvesh create "/nodes/${node_from}/migrateall" -vms "$desired_ids" -target "$desired_node"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
@@ -1,53 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
host="$(hostname)"
|
|
||||||
|
|
||||||
cleanup() {
|
|
||||||
printf "$(tput sgr0)\n"
|
|
||||||
}
|
|
||||||
trap cleanup EXIT
|
|
||||||
|
|
||||||
printf 'ID\tName\tup;sec\tver\t(notice)\n'
|
|
||||||
|
|
||||||
pvesh get "/nodes/$host/qemu" --output-format json | jq -r '.[] | select(.status == "running") | "\(.vmid),\(.name),\(.tags)"' |\
|
|
||||||
while IFS= read -r vmline; do
|
|
||||||
vmid="$(cut -d, -f1 <<< "$vmline")"
|
|
||||||
vmname="$(cut -d, -f2 <<< "$vmline")"
|
|
||||||
tags="$(cut -d, -f3 <<< "$vmline")"
|
|
||||||
|
|
||||||
printf "$vmid $vmname "
|
|
||||||
|
|
||||||
if grep -q custom <<< "$tags"; then echo "$(tput setaf 5)is custom$(tput sgr0)";
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf "$(tput setaf 5)"; qm guest exec "$vmid" -- /usr/bin/apt-get update > /dev/null; code="$?"; printf "$(tput sgr0)"
|
|
||||||
if [[ "$code" == 255 ]]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
apt="$(qm guest exec "$vmid" -- /usr/lib/update-notifier/apt-check | jq '."err-data"' | sed 's/\n$//'| xargs -I: printf " ":)"
|
|
||||||
printf "$(tput setaf 190)$apt$(tput sgr0) "
|
|
||||||
|
|
||||||
ver="$(qm guest exec "$vmid" -- /usr/bin/lsb_release -a 2>/dev/null | jq '."out-data"' | cut -d'\' -f4 | cut -c 2- )"
|
|
||||||
printf "$ver"
|
|
||||||
|
|
||||||
expectedTag="unknown"
|
|
||||||
case "$(cut -d' ' -f1 <<< "$ver")" in
|
|
||||||
Ubuntu)
|
|
||||||
expectedTag="ub$(cut -d' ' -f2 <<< "$ver" | cut -d. -f1)"
|
|
||||||
;;
|
|
||||||
Debian)
|
|
||||||
expectedTag="d$(cut -d' ' -f3 <<< "$ver")"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if ! grep -q "$expectedTag" <<< "$tags"; then
|
|
||||||
printf " $(tput setaf 6)TAG MISMATCH$(tput sgr0)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$(cut -d';' -f2 <<< "$apt")" != 0 ]]; then
|
|
||||||
printf " $(tput setaf 3)SECURITY UPDATES$(tput sgr0)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo
|
|
||||||
done
|
|
Reference in New Issue
Block a user