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
Branches
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 #!/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. # Get our own process ID.
mypid="$$"; mypid="$$";
if [ "$mypid" = "" ] || ! echo "$mypid" | grep "^[0-9][0-9]*$" >/dev/null; then if ! echo "$mypid" | grep "^[0-9][0-9]*$" >/dev/null; then
echo "Error getting current PID."; echo "> error getting current PID";
exit 1; exit 1;
fi; fi;
# Check if there are other .update-loop processes. # Store our pid as lockfile.
if ps -eo pid,cmd | grep "\/\.update-loop$" | grep -v "grep\|sudo\|^\s*$mypid\s" >/dev/null; then echo "$mypid" >"$LOCKFILE"
echo "Skip: .update-loop is already running.";
exit 0;
fi;
# Get path to the actual update script. # Get path to the actual update script.
scriptfile="$0"; scriptfile="$0";
...@@ -28,3 +43,5 @@ while true; do ...@@ -28,3 +43,5 @@ while true; do
sleep 5; sleep 5;
done; done;
rm "$LOCKFILE";
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment