nitter/startup.sh

43 lines
903 B
Bash
Raw Normal View History

#!/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"