pkg-cache: CT130 self-check timer (fail fast when the cache is broken) #67
No files matched your search
@@ -93,6 +93,13 @@ stop_services() {
|
||||
}
|
||||
|
||||
# ---- main ---------------------------------------------------------------------
|
||||
# Something else (an admin, a package script) started nginx while our stop marker exists:
|
||||
# do not "recover" on our own schedule or leave it running unchecked. Drop the marker and
|
||||
# judge it like normal operation below, which stops it again if the cache is unhealthy.
|
||||
if [ -e "$MARKER" ] && $SYSTEMCTL is-active --quiet nginx; then
|
||||
log warning "nginx was started by something else while stopped by this script; re-checking it now"
|
||||
rm -f "$MARKER" "$OKFILE"
|
||||
fi
|
||||
if [ -e "$MARKER" ]; then
|
||||
# we stopped the services earlier: look for recovery
|
||||
if why=$(check_disks); then
|
||||
|
||||
@@ -32,13 +32,14 @@ EOS
|
||||
cat >"$T/bin/systemctl" <<'EOS'
|
||||
#!/bin/sh
|
||||
echo "$*" >>"$CALLS"
|
||||
case "$1" in is-active) [ -e "$ACTIVE" ];; start) touch "$ACTIVE";; stop) rm -f "$ACTIVE";; esac
|
||||
case "$1" in is-active) [ -e "$ACTIVE" ]; exit $?;; start) touch "$ACTIVE";; stop) rm -f "$ACTIVE";; esac
|
||||
exit 0
|
||||
EOS
|
||||
printf '#!/bin/sh\nexit 0\n' >"$T/bin/logger"; chmod +x "$T/bin/"*
|
||||
export PATH="$T/bin:$PATH" CALLS="$T/calls" ACTIVE="$T/active"
|
||||
export PKGCACHE_STATE_DIR="$T/state" PKGCACHE_CHECK_PATHS="$T/disk1 $T/disk2"
|
||||
export PKGCACHE_PROBE_URL=http://probe PKGCACHE_ORIGIN_URL=http://origin
|
||||
export PKGCACHE_SERVICES="nginx docker-registry" # explicit: never rely on the script default in a test
|
||||
export PKGCACHE_NGINX_TEST=true FAKE_RO=none FAKE_PROBE=ok FAKE_ORIGIN=ok
|
||||
run() { "$S" >"$T/out" 2>&1; }
|
||||
reset() { rm -rf "$T/state" "$T/calls"; touch "$T/calls" "$ACTIVE"; }
|
||||
@@ -67,6 +68,15 @@ run; run; PKGCACHE_NGINX_TEST=false run && bad "nginx -t fail exit" || { [ ! -e
|
||||
reset; FAKE_PROBE=empty run || true; run; run; FAKE_PROBE=empty run && bad "restart-fail exit" || { [ ! -e "$ACTIVE" ] && [ -e "$T/state/stopped" ] && ok "restart with failing fetch: stopped again" || bad "restart-fail"; }
|
||||
# never start something an admin stopped
|
||||
reset; rm -f "$ACTIVE"; run && ! grep -q '^start' "$CALLS" && ok "admin-stopped nginx is left alone" || bad "admin stop"
|
||||
# empty services list must mean "manage nothing", never the real defaults
|
||||
reset; PKGCACHE_SERVICES="" FAKE_PROBE=empty run || true
|
||||
! grep -q '^stop' "$CALLS" && ok "empty PKGCACHE_SERVICES: nothing stopped" || bad "empty services list stopped something"
|
||||
# something else restarts nginx while our marker exists: re-checked, stopped again if still bad
|
||||
reset; FAKE_PROBE=empty run || true; touch "$ACTIVE"
|
||||
FAKE_RO="$T/disk1" run || true
|
||||
[ ! -e "$ACTIVE" ] && ok "nginx restarted by someone else while unhealthy: stopped again" || bad "fight: left running"
|
||||
reset; FAKE_PROBE=empty run || true; touch "$ACTIVE"
|
||||
run && [ -e "$ACTIVE" ] && [ ! -e "$T/state/stopped" ] && ok "nginx restarted by someone else and healthy: left running, marker cleared" || bad "fight: healthy case"
|
||||
# REAL read-only bind mount
|
||||
mkdir -p "$T/real" "$T/robind"
|
||||
if sudo -n mount --bind "$T/real" "$T/robind" 2>/dev/null && sudo -n mount -o remount,bind,ro "$T/robind"; then
|
||||
|
||||
Reference in new issue
Block a user