Skip to content
Snippets Groups Projects
Commit ab783c82 authored by Eric Zillmann's avatar Eric Zillmann
Browse files

#2783 use lockfile instead of checking active processes as the lockfile is...

#2783 use lockfile instead of checking active processes as the lockfile is site specific; check to detect stale lock files
parent 5d631280
No related branches found
No related tags found
1 merge request!2update-loop: use lockfile with check for stale lockfile instead of checking active processes
#!/usr/bin/env bash
LOCKFILE={{ webRoot }}/.update-loop.lock;
# Check if there is a lockfile.
if [ -f "$LOCKFILE" ]; then
# Get the pid from the lockfile.
lockpid="$(head -n1 "$LOCKFILE")";
if ! echo "$lockpid" | grep "^[0-9][0-9]*$" >/dev/null; then
echo "> error reading lockfile";
exit 1;
fi;
# Check if the pid in the lockfile is still active.
if ps -eo pid,cmd | grep "^\s*$lockpid .*\/var\/www\/\.update-loop$" >/dev/null; then
echo '> locked';
exit;
fi;
fi
# Get our own process ID.
mypid="$$";
if [ "$mypid" = "" ] || ! echo "$mypid" | grep "^[0-9][0-9]*$" >/dev/null; then
echo "Error getting current PID.";
if ! echo "$mypid" | grep "^[0-9][0-9]*$" >/dev/null; then
echo "> error getting current PID";
exit 1;
fi;
# Check if there are other .update-loop processes.
if ps -eo pid,cmd | grep "\/\.update-loop$" | grep -v "grep\|sudo\|^\s*$mypid\s" >/dev/null; then
echo "Skip: .update-loop is already running.";
exit 0;
fi;
# Store our pid as lockfile.
echo "$mypid" >"$LOCKFILE"
# Get path to the actual update script.
scriptfile="$0";
......@@ -28,3 +43,5 @@ while true; do
sleep 5;
done;
rm "$LOCKFILE";
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment