From 932ff6ef88e644634314135b15bfb905f121c5c5 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 19 Oct 2020 13:31:47 +0200 Subject: buff-di-wuff: add pid file and startup-delay for non-interactive runs --- buff-di-wuff | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 \ -- cgit v1.2.3-54-g00ecf