summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2020-10-19 13:31:47 +0200
committerErich Eckner <git@eckner.net>2020-10-19 13:31:47 +0200
commit932ff6ef88e644634314135b15bfb905f121c5c5 (patch)
tree320aca012de2fd59cfa7e50b9fb2d08b6410ad68
parentb316b5d643cab62f35742ab9868e738561556f24 (diff)
downloadbuff-di-wuff-master.tar.xz
buff-di-wuff: add pid file and startup-delay for non-interactive runsHEADmaster
-rwxr-xr-xbuff-di-wuff15
1 files changed, 15 insertions, 0 deletions
diff --git a/buff-di-wuff b/buff-di-wuff
index 2be2f21..7a07d9d 100755
--- a/buff-di-wuff
+++ b/buff-di-wuff
@@ -2,6 +2,21 @@
set -e
+pid_file="/tmp/${0##*/}.pid"
+if [ -f "${pid_file}" ] \
+&& kill -0 "$(cat "${pid_file}")" >/dev/null 2>&1; then
+ >&2 printf 'another %s is running as %s\n' "${0##*/}" "$(cat "${pid_file}")"
+ exit
+fi
+
+echo $$ \
+> "${pid_file}"
+trap 'rm "${pid_file}"' EXIT
+
+if ! tty -s; then
+ sleep $((${RANDOM} % 3600))
+fi
+
cache_dir=$(readlink -e "$(dirname "$0")/../httpdocs")
mkdir -p \