bain
b0eb822628
The script should take guest_accounts.jsonl file from shared storage and lock it. The file is unlocked again on exit. This is useful when the same service is spun up multiple times in a docker swarm environment.
42 lines
903 B
Bash
Executable file
42 lines
903 B
Bash
Executable file
#!/bin/sh
|
|
# Startup nitter with guest accounts
|
|
|
|
GUEST_ACC_FOLDER=/guest_accs
|
|
|
|
__cleanup() {
|
|
kill -s TERM "$NITTER_PID"
|
|
[ -n "$LOCKFILE_PID" ] && kill "$LOCKFILE_PID"
|
|
lockfile-remove "$GUEST_ACC_FILE"
|
|
echo "unlocked \"$GUEST_ACC_FILE\""
|
|
|
|
# Cleanup done, we can now wait for nitter. We might get killed in the
|
|
# process :)
|
|
wait "$NITTER_PID"
|
|
}
|
|
|
|
for accounts in $GUEST_ACC_FOLDER/*.jsonl; do
|
|
if lockfile-create -r 0 "$accounts"; then
|
|
GUEST_ACC_FILE="$accounts"
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ -z "$GUEST_ACC_FILE" ]; then
|
|
echo "No guest accounts available! Exiting..."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Taking \"$GUEST_ACC_FILE\""
|
|
|
|
trap __cleanup EXIT TERM INT
|
|
|
|
lockfile-touch "$GUEST_ACC_FILE" &
|
|
LOCKFILE_PID="$!"
|
|
|
|
cp "$GUEST_ACC_FILE" ./guest_accounts.jsonl
|
|
|
|
./nitter &
|
|
NITTER_PID="$!"
|
|
|
|
# this will always terminate in the docker grace period on SIGTERM
|
|
wait "$NITTER_PID"
|