aboutsummaryrefslogtreecommitdiff
#!/bin/sh
#
# Simple script wrapper to force another script to run as a singleton:
# prevents multiple instances of it (the same command name; naive)
# from running.

LOCKFILE="/tmp/singleton-$1"
LOCKFD=9

lock()      { flock -$1 $LOCKFD; }
stop_lock() { lock u; lock xn && rm -f $LOCKFILE; }
prep_lock() { eval "exec $LOCKFD>\"$LOCKFILE\""; trap stop_lock EXIT; }

prep_lock
lock xn || exit 1

exec $@