Skip to content

Commit

Permalink
scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Jun 22, 2024
1 parent 946aafd commit 2eeed62
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
30 changes: 30 additions & 0 deletions scripts/await-service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -uo pipefail

await_service()
{
local start_ts=$(date +%s)
while [ $(date +%s) -lt $((start_ts + $3)) ];
do
(echo -n > /dev/tcp/$1/$2) > /dev/null
if [[ $? -eq 0 ]]; then
break
fi
sleep 1
done
local end_ts=$(date +%s)

if [ $(date +%s) -ge $((start_ts + $3)) ]; then
echo "Timeout occurred while waiting for $1:$2 to become available"
exit 1
fi

echo "$1:$2 is available after $((end_ts - start_ts)) seconds"
}

if [[ $# -ne 3 ]]; then
echo "Usage: $0 <host> <port> <timeout>"
exit 1
fi

await_service $1 $2 $3
29 changes: 29 additions & 0 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -eo pipefail

cd /srv/root

if [ -z "$APP_ENV" ]; then
echo "Please set APP_ENV"
exit 1
fi

if [ -z "$APP_COMPONENT" ]; then
echo "Please set APP_COMPONENT"
exit 1
fi

if [[ $PULL_SECRETS_FROM_VAULT -eq 1 ]]; then
echo "Fetching secrets from vault"
akatsuki vault get beatmaps-service $APP_ENV -o .env
echo "Fetched secrets from vault"
source .env
echo "Sourced secrets from vault"
fi

if [[ $APP_COMPONENT == "api" ]]; then
exec /scripts/run-api.sh
else
echo "Unknown APP_COMPONENT: $APP_COMPONENT"
exit 1
fi
4 changes: 4 additions & 0 deletions scripts/run-api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail

exec ./main.py

0 comments on commit 2eeed62

Please sign in to comment.