Fix NGINX read-only filesystem and database connection issues
This commit is contained in:
parent
23c9581f7b
commit
5c76451474
47
start.sh
47
start.sh
@ -445,12 +445,27 @@ else
|
|||||||
echo "==> Port $API_PORT is available for API server"
|
echo "==> Port $API_PORT is available for API server"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Create necessary NGINX temp directories
|
||||||
|
mkdir -p /app/data/nginx/client_body_temp
|
||||||
|
mkdir -p /app/data/nginx/proxy_temp
|
||||||
|
mkdir -p /app/data/nginx/fastcgi_temp
|
||||||
|
mkdir -p /app/data/nginx/uwsgi_temp
|
||||||
|
mkdir -p /app/data/nginx/scgi_temp
|
||||||
|
mkdir -p /app/data/logs/nginx
|
||||||
|
|
||||||
# Create the NGINX config
|
# Create the NGINX config
|
||||||
cat > /app/data/nginx/nginx.conf <<EOT
|
cat > /app/data/nginx/nginx.conf <<EOT
|
||||||
worker_processes 1;
|
worker_processes 1;
|
||||||
error_log /app/data/logs/nginx/error.log warn;
|
error_log /app/data/logs/nginx/error.log warn;
|
||||||
pid /app/data/nginx/nginx.pid;
|
pid /app/data/nginx/nginx.pid;
|
||||||
|
|
||||||
|
# Important: Configure temp paths in writable directories
|
||||||
|
client_body_temp_path /app/data/nginx/client_body_temp;
|
||||||
|
proxy_temp_path /app/data/nginx/proxy_temp;
|
||||||
|
fastcgi_temp_path /app/data/nginx/fastcgi_temp;
|
||||||
|
uwsgi_temp_path /app/data/nginx/uwsgi_temp;
|
||||||
|
scgi_temp_path /app/data/nginx/scgi_temp;
|
||||||
|
|
||||||
events {
|
events {
|
||||||
worker_connections 1024;
|
worker_connections 1024;
|
||||||
}
|
}
|
||||||
@ -572,7 +587,6 @@ EOT
|
|||||||
echo "==> Created NGINX config at /app/data/nginx/nginx.conf"
|
echo "==> Created NGINX config at /app/data/nginx/nginx.conf"
|
||||||
|
|
||||||
# Start NGINX
|
# Start NGINX
|
||||||
echo "==> Starting NGINX on port $NGINX_PORT"
|
|
||||||
nginx -c /app/data/nginx/nginx.conf -p /app/data/nginx &
|
nginx -c /app/data/nginx/nginx.conf -p /app/data/nginx &
|
||||||
NGINX_PID=$!
|
NGINX_PID=$!
|
||||||
echo "==> NGINX started with PID $NGINX_PID"
|
echo "==> NGINX started with PID $NGINX_PID"
|
||||||
@ -686,7 +700,7 @@ if [ -d "$SERVER_DIR/cmd/museum" ]; then
|
|||||||
# Execute as the cloudron user but use a proper script instead of env cd
|
# Execute as the cloudron user but use a proper script instead of env cd
|
||||||
cat > /tmp/run_migration.sh <<EOF
|
cat > /tmp/run_migration.sh <<EOF
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
cd "$SERVER_DIR" && ENTE_PG_DSN="postgres://${MUSEUM_DB_USER}:${MUSEUM_DB_PASSWORD}@${MUSEUM_DB_HOST}:${MUSEUM_DB_PORT}/${MUSEUM_DB_NAME}?sslmode=disable" go run cmd/museum/main.go db force 25
|
cd "$SERVER_DIR" && ENTE_PG_HOST="${MUSEUM_DB_HOST}" ENTE_PG_PORT="${MUSEUM_DB_PORT}" ENTE_PG_USER="${MUSEUM_DB_USER}" ENTE_PG_PASSWORD="${MUSEUM_DB_PASSWORD}" ENTE_PG_DATABASE="${MUSEUM_DB_NAME}" ENTE_PG_DSN="postgres://${MUSEUM_DB_USER}:${MUSEUM_DB_PASSWORD}@${MUSEUM_DB_HOST}:${MUSEUM_DB_PORT}/${MUSEUM_DB_NAME}?sslmode=disable" go run cmd/museum/main.go db force 25
|
||||||
EOF
|
EOF
|
||||||
chmod +x /tmp/run_migration.sh
|
chmod +x /tmp/run_migration.sh
|
||||||
|
|
||||||
@ -725,7 +739,7 @@ elif [ -d "$SERVER_DIR/cmd/museum" ]; then
|
|||||||
# Create a startup script
|
# Create a startup script
|
||||||
cat > /tmp/run_server.sh <<EOF
|
cat > /tmp/run_server.sh <<EOF
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
cd "$SERVER_DIR" && ENTE_PG_DSN="postgres://${MUSEUM_DB_USER}:${MUSEUM_DB_PASSWORD}@${MUSEUM_DB_HOST}:${MUSEUM_DB_PORT}/${MUSEUM_DB_NAME}?sslmode=disable" go run cmd/museum/main.go serve
|
cd "$SERVER_DIR" && ENTE_PG_HOST="${MUSEUM_DB_HOST}" ENTE_PG_PORT="${MUSEUM_DB_PORT}" ENTE_PG_USER="${MUSEUM_DB_USER}" ENTE_PG_PASSWORD="${MUSEUM_DB_PASSWORD}" ENTE_PG_DATABASE="${MUSEUM_DB_NAME}" ENTE_PG_DSN="postgres://${MUSEUM_DB_USER}:${MUSEUM_DB_PASSWORD}@${MUSEUM_DB_HOST}:${MUSEUM_DB_PORT}/${MUSEUM_DB_NAME}?sslmode=disable" go run cmd/museum/main.go serve
|
||||||
EOF
|
EOF
|
||||||
chmod +x /tmp/run_server.sh
|
chmod +x /tmp/run_server.sh
|
||||||
|
|
||||||
@ -757,23 +771,35 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// Log environment variables
|
||||||
|
log.Println("Starting mock API server with environment variables:")
|
||||||
|
log.Println("MUSEUM_DB_HOST:", os.Getenv("MUSEUM_DB_HOST"))
|
||||||
|
log.Println("MUSEUM_DB_PORT:", os.Getenv("MUSEUM_DB_PORT"))
|
||||||
|
log.Println("MUSEUM_DB_USER:", os.Getenv("MUSEUM_DB_USER"))
|
||||||
|
log.Println("ENTE_PG_HOST:", os.Getenv("ENTE_PG_HOST"))
|
||||||
|
log.Println("ENTE_PG_DSN:", os.Getenv("ENTE_PG_DSN"))
|
||||||
|
|
||||||
// Add a health endpoint
|
// Add a health endpoint
|
||||||
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
fmt.Fprint(w, `{"status":"ok","message":"Mock server running"}`)
|
fmt.Fprint(w, `{"status":"ok","message":"Mock server running","time":"` + time.Now().String() + `"}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Handle all other requests
|
// Handle all other requests
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Printf("Received request for %s via %s", r.URL.Path, r.Method)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
fmt.Fprintf(w, `{"status":"mock","endpoint":"%s","method":"%s"}`, r.URL.Path, r.Method)
|
fmt.Fprintf(w, `{"status":"mock","endpoint":"%s","method":"%s","time":"%s"}`,
|
||||||
|
r.URL.Path, r.Method, time.Now().String())
|
||||||
})
|
})
|
||||||
|
|
||||||
// Start the server
|
// Start the server
|
||||||
log.Printf("Starting mock server on port %d\n", 8080)
|
log.Printf("Starting mock server on port 8080\n")
|
||||||
|
|
||||||
if err := http.ListenAndServe(":8080", nil); err != nil {
|
if err := http.ListenAndServe(":8080", nil); err != nil {
|
||||||
log.Fatalf("Failed to start server: %v", err)
|
log.Fatalf("Failed to start server: %v", err)
|
||||||
@ -781,8 +807,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
# Run the mock server
|
# Run the mock server with environment variables
|
||||||
cd /tmp/mock-server
|
cd /tmp/mock-server
|
||||||
|
export ENTE_PG_HOST="${MUSEUM_DB_HOST}"
|
||||||
|
export ENTE_PG_PORT="${MUSEUM_DB_PORT}"
|
||||||
|
export ENTE_PG_USER="${MUSEUM_DB_USER}"
|
||||||
|
export ENTE_PG_PASSWORD="${MUSEUM_DB_PASSWORD}"
|
||||||
|
export ENTE_PG_DATABASE="${MUSEUM_DB_NAME}"
|
||||||
|
export ENTE_PG_DSN="postgres://${MUSEUM_DB_USER}:${MUSEUM_DB_PASSWORD}@${MUSEUM_DB_HOST}:${MUSEUM_DB_PORT}/${MUSEUM_DB_NAME}?sslmode=disable"
|
||||||
|
|
||||||
go run main.go > /app/data/logs/museum.log 2>&1 &
|
go run main.go > /app/data/logs/museum.log 2>&1 &
|
||||||
SERVER_PID=$!
|
SERVER_PID=$!
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user