23 lines
450 B
Bash
23 lines
450 B
Bash
|
|
#!/bin/bash
|
||
|
|
# Bail if other agents are alive in the state dir.
|
||
|
|
# $1 = path to this agent's pid file
|
||
|
|
# cwd = state dir
|
||
|
|
#
|
||
|
|
# Exit 0 = continue, exit 1 = bail
|
||
|
|
|
||
|
|
my_pid_file=$(basename "$1")
|
||
|
|
|
||
|
|
for f in pid-*; do
|
||
|
|
[ "$f" = "$my_pid_file" ] && continue
|
||
|
|
[ ! -f "$f" ] && continue
|
||
|
|
|
||
|
|
pid=${f#pid-}
|
||
|
|
if kill -0 "$pid" 2>/dev/null; then
|
||
|
|
exit 1 # another agent is alive, bail
|
||
|
|
else
|
||
|
|
rm -f "$f" # stale, clean up
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
|
||
|
|
exit 0
|