Spaces:
Running
Running
Create start.sh
Browse files
start.sh
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# This script starts the necessary services and then runs the main application.
|
| 4 |
+
|
| 5 |
+
# --- Step 1: Switch to root to manage services ---
|
| 6 |
+
# Use sudo to run service commands as root.
|
| 7 |
+
# This is necessary because the Docker container will start as the 'user'.
|
| 8 |
+
echo "--- Starting Services (requires root) ---"
|
| 9 |
+
|
| 10 |
+
# Start Valkey in the background (daemonize)
|
| 11 |
+
# The config file is at /etc/valkey/valkey.conf
|
| 12 |
+
sudo valkey-server /etc/valkey/valkey.conf --daemonize yes
|
| 13 |
+
echo "[INFO] Valkey server process initiated."
|
| 14 |
+
|
| 15 |
+
# Start the PostgreSQL database service
|
| 16 |
+
# The 'service' command handles running it as the correct 'postgres' user
|
| 17 |
+
sudo service postgresql start
|
| 18 |
+
echo "[INFO] PostgreSQL service initiated."
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
# --- Step 2: Wait for services to be fully ready ---
|
| 22 |
+
echo "--- Waiting for services to initialize ---"
|
| 23 |
+
|
| 24 |
+
# Wait for PostgreSQL to be ready to accept connections
|
| 25 |
+
# The -q flag makes it quiet; it will exit with status 0 when ready.
|
| 26 |
+
until sudo -u postgres pg_isready -q
|
| 27 |
+
do
|
| 28 |
+
echo "[INFO] Waiting for PostgreSQL to be ready..."
|
| 29 |
+
sleep 2
|
| 30 |
+
done
|
| 31 |
+
echo "[SUCCESS] PostgreSQL is ready."
|
| 32 |
+
|
| 33 |
+
# Wait for Valkey to be ready
|
| 34 |
+
# The PING command will return PONG if the server is up.
|
| 35 |
+
until valkey-cli -h 127.0.0.1 -p 6379 ping | grep -q "PONG"
|
| 36 |
+
do
|
| 37 |
+
echo "[INFO] Waiting for Valkey to be ready..."
|
| 38 |
+
sleep 2
|
| 39 |
+
done
|
| 40 |
+
echo "[SUCCESS] Valkey is ready."
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# --- Step 3: Run the application ---
|
| 44 |
+
echo "--- Starting Bun Application ---"
|
| 45 |
+
# Use 'exec' to replace the shell process with your application.
|
| 46 |
+
# This ensures that your app is the main process and receives signals correctly.
|
| 47 |
+
exec bun run app.js
|