diff options
author | Samuel Fadel <samuel@nihil.ws> | 2023-06-20 14:18:54 +0200 |
---|---|---|
committer | Samuel Fadel <samuel@nihil.ws> | 2023-06-20 14:18:54 +0200 |
commit | 2d8a89d6be28c995478794531748e4c7b0a3b9d4 (patch) | |
tree | eec10b7e639ea1f259a1977dfb595a6d6d9c6aad /bin | |
parent | 5ec461479aac4433066292c668d316ad64a0efa9 (diff) |
Added naive wrapper to run scripts as singletons.0.6
* bin/singleton: Added.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/singleton | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/bin/singleton b/bin/singleton new file mode 100755 index 0000000..e11ed71 --- /dev/null +++ b/bin/singleton @@ -0,0 +1,17 @@ +#!/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 $@ |