-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add startup script to start the postgres instance on a selected port (#…
…1901) Just easier to manage multiple postgres instances this way. This script will: 1. set the port number you passed to it in the passport server .env 2. start the postgres instance with the selected port. 3. verify that you didnt try to use a already taken post, so you dont have to guess. Works only on unix based machines tho (and, i think, WSL. didnt check tho) --------- Co-authored-by: Richard Liu <[email protected]>
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
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
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
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,42 @@ | ||
#!/bin/bash | ||
PORT=${1:-5432} | ||
if ! [[ $PORT =~ ^[0-9]+$ && $PORT -gt 0 ]]; then | ||
echo "Error: $PORT is not a port number." >&2 | ||
exit 1 | ||
fi | ||
|
||
|
||
# Get a list of all listening port numbers | ||
ports=$(sudo lsof -i -P -n | grep LISTEN | awk '{print $(NF - 1)}' | awk -F':' '{print $NF}') | ||
|
||
# Convert the list into an array | ||
port_array=($ports) | ||
|
||
# Print the list of ports | ||
for port in "${port_array[@]}"; do | ||
if [[ $PORT -eq $port ]]; then | ||
echo "Error: $PORT is taken." >&2 | ||
exit 1 | ||
fi | ||
done | ||
|
||
ENV_FILE="./apps/passport-server/.env" | ||
|
||
# Check if .env file exists | ||
if [[ ! -f $ENV_FILE ]]; then | ||
echo "Error: $ENV_FILE does not exist." >&2 | ||
exit 1 | ||
fi | ||
|
||
# Update DATABASE_PORT in the .env file or add it if it doesn't exist | ||
if grep -q "^DATABASE_PORT=" "$ENV_FILE"; then | ||
# Update the existing DATABASE_PORT line | ||
sed -i '' "s/^DATABASE_PORT=.*/DATABASE_PORT=$PORT/" "$ENV_FILE" | ||
echo "Updated DATABASE_PORT to $PORT in $ENV_FILE." | ||
else | ||
# Add DATABASE_PORT to the .env file | ||
echo "DATABASE_PORT=$PORT" >> "$ENV_FILE" | ||
echo "Added DATABASE_PORT=$PORT to $ENV_FILE." | ||
fi | ||
|
||
pg_ctl -D apps/passport-server/local-db-data -l apps/passport-server/local-db-log -o "-p $PORT" start |
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