-
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.
- Loading branch information
1 parent
ccf9ad9
commit 1969b72
Showing
5 changed files
with
111 additions
and
37 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
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 |
---|---|---|
@@ -1,42 +1,45 @@ | ||
#!/bin/bash | ||
# init.sh | ||
set -e | ||
|
||
# Define PostgreSQL version | ||
PG_VERSION=11 | ||
|
||
# Paths | ||
POSTGRES_BIN_DIR="/usr/lib/postgresql/${PG_VERSION}/bin" | ||
|
||
# Initialize PostgreSQL data directory if it doesn't exist | ||
if [ ! -d "/var/lib/postgresql/data" ]; then | ||
echo "Initializing PostgreSQL data directory..." | ||
mkdir -p /var/lib/postgresql/data | ||
chown -R postgres:postgres /var/lib/postgresql | ||
su postgres -c "${POSTGRES_BIN_DIR}/initdb -D /var/lib/postgresql/data" | ||
su-exec postgres initdb -D /var/lib/postgresql/data | ||
fi | ||
|
||
# Update pg_hba.conf to allow password authentication | ||
PG_HBA=/var/lib/postgresql/data/pg_hba.conf | ||
if [ -f "$PG_HBA" ]; then | ||
echo "Configuring PostgreSQL to use md5 authentication..." | ||
sed -i "s/^\(local\s\+all\s\+all\s\+\)peer/\1md5/" $PG_HBA | ||
sed -i "s/^#\?\(local\s\+all\s\+all\s\+\)peer/\1md5/" $PG_HBA | ||
sed -i "s/^#\?\(host\s\+all\s\+all\s\+127\.0\.0\.1\/32\s\+\)md5/\1md5/" $PG_HBA | ||
sed -i "s/^#\?\(host\s\+all\s\+all\s\+::1\/128\s\+\)md5/\1md5/" $PG_HBA | ||
fi | ||
|
||
# Ensure /run/postgresql exists and is owned by postgres | ||
echo "Ensuring /run/postgresql exists and is owned by postgres..." | ||
mkdir -p /run/postgresql | ||
chown postgres:postgres /run/postgresql | ||
|
||
# Start PostgreSQL to perform setup | ||
echo "Starting PostgreSQL..." | ||
su postgres -c "${POSTGRES_BIN_DIR}/pg_ctl -D /var/lib/postgresql/data -w start" | ||
su-exec postgres postgres -D /var/lib/postgresql/data & | ||
sleep 5 | ||
|
||
# Create PostgreSQL user with SUPERUSER privilege if it doesn't exist | ||
echo "Creating PostgreSQL user with SUPERUSER privilege if it doesn't exist..." | ||
su postgres -c "psql -tc \"SELECT 1 FROM pg_roles WHERE rolname = '$db_username'\" | grep -q 1 || psql -c \"CREATE USER $db_username WITH PASSWORD '$db_password' SUPERUSER;\"" | ||
su-exec postgres psql -tc "SELECT 1 FROM pg_roles WHERE rolname = '$db_username'" | grep -q 1 || su-exec postgres psql -c "CREATE USER $db_username WITH PASSWORD '$db_password' SUPERUSER;" | ||
|
||
# Create database if it doesn't exist | ||
echo "Creating PostgreSQL database if it doesn't exist..." | ||
su postgres -c "psql -tc \"SELECT 1 FROM pg_database WHERE datname = '$OAUTHDB'\" | grep -q 1 || psql -c \"CREATE DATABASE $OAUTHDB OWNER $db_username;\"" | ||
su-exec postgres psql -tc "SELECT 1 FROM pg_database WHERE datname = '$OAUTHDB'" | grep -q 1 || su-exec postgres psql -c "CREATE DATABASE $OAUTHDB OWNER $db_username;" | ||
|
||
# Grant all privileges on the database to the user (redundant but ensures full access) | ||
su postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE $OAUTHDB TO $db_username;\"" | ||
# Grant all privileges on the database to the user | ||
su-exec postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $OAUTHDB TO $db_username;" | ||
|
||
# Stop PostgreSQL (Supervisor will manage it) | ||
echo "Stopping PostgreSQL..." | ||
su postgres -c "${POSTGRES_BIN_DIR}/pg_ctl -D /var/lib/postgresql/data -m fast -w stop" | ||
su-exec postgres pg_ctl -D /var/lib/postgresql/data -m fast -w stop |
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,34 @@ | ||
user nginx; | ||
worker_processes auto; | ||
error_log /var/log/nginx/error.log notice; | ||
pid /var/run/nginx.pid; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
sendfile on; | ||
keepalive_timeout 65; | ||
|
||
server { | ||
listen 443 ssl; | ||
server_name localhost; | ||
|
||
ssl_certificate /etc/ssl/certs/server.crt; | ||
ssl_certificate_key /etc/ssl/private/server.key; | ||
|
||
ssl_protocols TLSv1.2 TLSv1.3; | ||
ssl_ciphers HIGH:!aNULL:!MD5; | ||
|
||
location / { | ||
proxy_pass http://127.0.0.1:3100; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
} | ||
} | ||
} |
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