-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
65 lines (50 loc) · 1.66 KB
/
start.sh
File metadata and controls
65 lines (50 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
export POSTGRES_HOST_AUTH_METHOD=trust
pg_ctlcluster 17 main restart
# Wait for PostgreSQL to be ready
until pg_isready -U postgres; do
echo "Waiting for PostgreSQL to start..."
sleep 2
done
# Activate venv
source /app/.venv/bin/activate
# Generate the init.sql script
echo "Generating init.sql..."
cd /app
generate-init-sql
# Run the init.sql script as the postgres superuser
echo "Running init.sql..."
until pg_isready -U postgres; do sleep 1; done
su postgres -c "psql -d postgres -f /app/init.sql"
# Set listen_addresses = '*'
echo "Configuring PostgreSQL to listen on all addresses..."
su postgres -c "psql -d postgres -c \"ALTER SYSTEM SET listen_addresses = '*';\""
pg_ctlcluster 17 main restart
# Check if the psql command was successful
if [ $? -eq 0 ]; then
echo "init.sql executed successfully."
else
echo "Error executing init.sql."
exit 1 # Exit if there was an error
fi
# Wait for the new user and database to be ready
until pg_isready -U lablink -d lablink_db; do
echo "Waiting for lablink_db to be ready..."
sleep 2
done
CONFIG_DIR="${CONFIG_DIR:-/config}"
CONFIG_NAME="${CONFIG_NAME:-config.yaml}"
mkdir -p "$CONFIG_DIR"
# Seed only if needed
if [ ! -f "$CONFIG_DIR/$CONFIG_NAME" ]; then
if [ -z "$(ls -A "$CONFIG_DIR" 2>/dev/null || true)" ]; then
echo "[allocator] Seeding defaults into $CONFIG_DIR ..."
rsync -a /app/config.defaults/ "$CONFIG_DIR"/
else
echo "[allocator] Warning: $CONFIG_DIR/$CONFIG_NAME not found; using whatever exists in \"$CONFIG_DIR\""
fi
fi
echo "[allocator] Using config: $CONFIG_DIR/$CONFIG_NAME"
# Start the Flask application
echo "Starting Flask app..."
exec lablink-allocator