-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcron-stop.sh
More file actions
executable file
·37 lines (31 loc) · 912 Bytes
/
cron-stop.sh
File metadata and controls
executable file
·37 lines (31 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# Force location
cd "$(dirname "$0")" || exit
# Source env
source .env
source detect.sh
# Cron doesn't have this in PATH
export PATH="$PATH:/snap/bin"
# Log current state
LOGFILE="/vmtree/log/state-$(date +%Y%m%d).txt"
$TOOL list --format csv -c nstcl46SN >"$LOGFILE"
free -m >>"$LOGFILE"
df -m | grep -v 'snap\|tmpfs\|udev' >>"$LOGFILE"
# Stop/kill personal VMs
for VM in $($TOOL list --format csv --columns n | grep -- -); do
if ! $TOOL file pull "$VM/nokill" - 2>/dev/null ; then
# Every VM (without protection) is considered ephemeral, destroy them.
echo "Deleting $VM" >>"$LOGFILE"
$TOOL delete -f "$VM"
else
# If it is a "nokill" VM but personal, still stop it. But leave demo-VMs running.
if [[ "${VM%-*}" == "demo" ]]; then
echo "No-kill: $VM" >>"$LOGFILE"
else
echo "Stopping $VM" >>"$LOGFILE"
$TOOL stop "$VM"
fi
fi
done
# Log once more
free -m >>"$LOGFILE"