Pepguy commited on
Commit
24634dc
·
verified ·
1 Parent(s): 40881e7

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +10 -36
start.sh CHANGED
@@ -1,47 +1,21 @@
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
 
1
  #!/bin/bash
2
 
3
+ echo "===== Application Startup at $(date) ====="
4
 
5
+ # --- Step 1: Start Valkey (Redis fork) ---
6
+ echo "[INFO] Starting Valkey server..."
7
+ valkey-server /etc/valkey/valkey.conf --daemonize yes
8
+ echo "[INFO] Valkey server started."
9
 
10
+ # --- Step 2: Wait for Valkey to be ready ---
11
+ echo "[INFO] Waiting for Valkey to be ready..."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  until valkey-cli -h 127.0.0.1 -p 6379 ping | grep -q "PONG"
13
  do
14
+ echo "[INFO] Waiting for Valkey to respond..."
15
  sleep 2
16
  done
17
  echo "[SUCCESS] Valkey is ready."
18
 
19
+ # --- Step 3: Start Bun app ---
20
+ echo "[INFO] Starting Bun app..."
 
 
 
21
  exec bun run app.js