67 lines
2.5 KiB
Shell
67 lines
2.5 KiB
Shell
|
|
#!/bin/bash
|
||
|
|
# The CI runner's window by hand, outside the night's (ADR 0039, D6): the heavy sidecars
|
||
|
|
# rested (halkyon-night), the runner started, every queued job run, then the runner
|
||
|
|
# stopped and the sidecars started again (halkyon-morning), however it ends. Jellyfin,
|
||
|
|
# the map, routes, place search, LanguageTool and the dictionaries are down meanwhile;
|
||
|
|
# --keep-sidecars keeps them, and the job runs slower beside them, in swap.
|
||
|
|
#
|
||
|
|
# Installed root's own by host step 7, never run from deploy's checkout (deploy could
|
||
|
|
# change it, and root runs it):
|
||
|
|
# sudo install -m 755 deploy/runner/ci-now.sh /usr/local/sbin/halkyon-ci-now
|
||
|
|
# At the iMac: sudo halkyon-ci-now [--keep-sidecars]
|
||
|
|
# From melchior, on its own on balthasar, so a closed laptop doesn't end it:
|
||
|
|
# ssh -t balthasar sudo systemd-run --unit halkyon-ci-now /usr/local/sbin/halkyon-ci-now
|
||
|
|
# ssh balthasar journalctl -fu halkyon-ci-now
|
||
|
|
# ssh -t balthasar sudo systemctl stop halkyon-ci-now # to end it early
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
keep=false
|
||
|
|
case ${1:-} in
|
||
|
|
'') ;;
|
||
|
|
--keep-sidecars) keep=true ;;
|
||
|
|
*)
|
||
|
|
echo "usage: $0 [--keep-sidecars]" >&2
|
||
|
|
exit 2
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
[ "$(id -u)" = 0 ] || { echo "Error: run it as root (sudo)" >&2; exit 1; }
|
||
|
|
if systemctl is-active --quiet forgejo-runner; then
|
||
|
|
echo "The runner runs already (the night's window, or another start); nothing done." >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
restore() {
|
||
|
|
trap - EXIT INT TERM HUP
|
||
|
|
echo "== The runner stopped$($keep || echo ', the sidecars started again')"
|
||
|
|
systemctl stop forgejo-runner || true
|
||
|
|
$keep || systemctl start halkyon-morning
|
||
|
|
}
|
||
|
|
trap restore EXIT INT TERM HUP
|
||
|
|
|
||
|
|
if ! $keep; then
|
||
|
|
echo "== The heavy sidecars rested"
|
||
|
|
systemctl start halkyon-night
|
||
|
|
fi
|
||
|
|
echo "== The runner started; it stops itself after three hours at the latest"
|
||
|
|
systemctl start forgejo-runner
|
||
|
|
|
||
|
|
# The runner alone in its control group while idle; a job's processes beside it while
|
||
|
|
# one runs. Done once it has been idle for 90 s, several of its 10 s polls of the queue.
|
||
|
|
procs=/sys/fs/cgroup/system.slice/forgejo-runner.service/cgroup.procs
|
||
|
|
idle=0
|
||
|
|
jobs=0
|
||
|
|
running=false
|
||
|
|
while systemctl is-active --quiet forgejo-runner; do
|
||
|
|
if [ "$(wc -l <"$procs")" -gt 1 ]; then
|
||
|
|
$running || { jobs=$((jobs + 1)); echo "$(date +%H:%M) job $jobs running"; }
|
||
|
|
running=true
|
||
|
|
idle=0
|
||
|
|
else
|
||
|
|
$running && echo "$(date +%H:%M) job $jobs ended"
|
||
|
|
running=false
|
||
|
|
idle=$((idle + 10))
|
||
|
|
[ "$idle" -ge 90 ] && break
|
||
|
|
fi
|
||
|
|
sleep 10
|
||
|
|
done
|
||
|
|
echo "== $jobs job(s) run; their results are in Forgejo, the repository's Actions"
|