-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from balena-os/kyle/lock-manager
Create update locks for logged in sessions
- Loading branch information
Showing
6 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
rm -f /tmp/balena/updates.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
[[ ${VERBOSE:-,,} =~ true|yes|on|1 ]] && set -x | ||
|
||
LOCKFILE=/tmp/balena/updates.lock | ||
|
||
while true; do | ||
( | ||
# check for active sessions | ||
while last | grep -q "still logged in"; do | ||
|
||
# create the lockfile | ||
touch $LOCKFILE | ||
|
||
# create a file descriptor over the given lockfile | ||
exec {fd}<>${LOCKFILE} | ||
|
||
# request an exclusive lock in non-blocking mode | ||
flock -n $fd || exit 0 | ||
|
||
echo "Updates are locked while sessions are active..." | ||
last | grep "still logged in" | ||
|
||
# wait 30 seconds before checking again | ||
# updates are locked during this time | ||
sleep 30 | ||
|
||
done | ||
) | ||
|
||
# remove the lockfile (this should be unecessary?) | ||
rm -f $LOCKFILE | ||
|
||
# wait 5 seconds before checking again | ||
# updates are unlocked during this time | ||
sleep 5 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
longrun |
Empty file.