Datasets:
Download scripts/guard-userdata.sh from DrumsRL/drums-benchmarks: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/datasets/DrumsRL/drums-benchmarks/resolve/main/scripts/guard-userdata.sh
- Command line
-
hf download hf://datasets/DrumsRL/drums-benchmarks/scripts/guard-userdata.sh
-
curl -L -o guard-userdata.sh https://huggingface.co/datasets/DrumsRL/drums-benchmarks/resolve/main/scripts/guard-userdata.sh
1.46 kB
| # Auto-stop guard installed at launch (charter rule): hard ceiling + idle rule. Shutdown behavior of the instance is "stop". | |
| # HARD_H: hours after boot at which the host powers off no matter what. IDLE_MIN: power off after this many minutes with | |
| # load1 < 2, no sshd session and no file /run/t1-busy (the bench driver touches it while it runs). | |
| HARD_H=${HARD_H:-14}; IDLE_MIN=${IDLE_MIN:-40} | |
| cat > /usr/local/sbin/t1-guard <<G | |
| #!/bin/bash | |
| up=\$(cut -d. -f1 /proc/uptime) | |
| [ \$up -ge $((HARD_H*3600)) ] && { logger t1-guard hard ceiling; systemctl poweroff; } | |
| busy=0 | |
| [ -n "\$(find /run/t1-busy -mmin -15 2>/dev/null)" ] && busy=1 | |
| pgrep -f 'sshd(-session)?: [a-z]+@' >/dev/null && busy=1 | |
| awk '{exit !(\$1>=2)}' /proc/loadavg && busy=1 | |
| if [ \$busy = 1 ]; then date +%s > /run/t1-last-busy; exit 0; fi | |
| last=\$(cat /run/t1-last-busy 2>/dev/null || echo \$(date +%s)); [ -f /run/t1-last-busy ] || echo \$last > /run/t1-last-busy | |
| [ \$(( \$(date +%s) - last )) -ge $((IDLE_MIN*60)) ] && { logger t1-guard idle; systemctl poweroff; } | |
| exit 0 | |
| G | |
| chmod 755 /usr/local/sbin/t1-guard | |
| cat > /etc/systemd/system/t1-guard.service <<U | |
| [Unit] | |
| Description=T1 auto-stop guard | |
| [Service] | |
| Type=oneshot | |
| ExecStart=/usr/local/sbin/t1-guard | |
| U | |
| cat > /etc/systemd/system/t1-guard.timer <<U | |
| [Unit] | |
| Description=T1 auto-stop guard every minute | |
| [Timer] | |
| OnBootSec=2min | |
| OnUnitActiveSec=1min | |
| [Install] | |
| WantedBy=timers.target | |
| U | |
| systemctl daemon-reload; systemctl enable --now t1-guard.timer | |