2026-03-26 15:20:29 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
# Bail if other agents are alive in the state dir.
|
2026-04-08 10:39:07 -04:00
|
|
|
# $1 = this agent's pid file name (e.g. pid-12345)
|
2026-03-26 15:20:29 -04:00
|
|
|
# cwd = state dir
|
|
|
|
|
#
|
|
|
|
|
# Exit 0 = continue, exit 1 = bail
|
|
|
|
|
|
2026-04-08 10:39:07 -04:00
|
|
|
shopt -s nullglob
|
|
|
|
|
|
|
|
|
|
my_pid_file="$1"
|
2026-03-26 15:20:29 -04:00
|
|
|
|
|
|
|
|
for f in pid-*; do
|
2026-04-11 18:41:44 -04:00
|
|
|
[[ $f == $my_pid_file ]] && continue
|
|
|
|
|
pid="${f#pid-}"
|
|
|
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
|
|
|
exit 1 # competing agent is alive
|
|
|
|
|
else
|
|
|
|
|
rm -f "$f" # stale pid file, clean up
|
|
|
|
|
fi
|
2026-03-26 15:20:29 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
|
|
exit 0
|