Fixed Caddy header syntax and moved db_override.go creation before server startup
This commit is contained in:
parent
783ad628b3
commit
4819bda8ad
115
start.sh
115
start.sh
@ -344,6 +344,60 @@ else
|
|||||||
echo "==> Cannot modify /etc/hosts (read-only filesystem)"
|
echo "==> Cannot modify /etc/hosts (read-only filesystem)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Create the overrides directory and db_override.go file
|
||||||
|
mkdir -p "$SERVER_DIR/overrides"
|
||||||
|
echo "==> Creating db_override.go in overrides directory"
|
||||||
|
cat > "$SERVER_DIR/overrides/db_override.go" <<EOT
|
||||||
|
// Override database functions - will be added to museum build
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
_ "github.com/lib/pq" // Import the postgres driver
|
||||||
|
)
|
||||||
|
|
||||||
|
// This will run before main() and override the database functions
|
||||||
|
func init() {
|
||||||
|
log.Println("Database override patch is active")
|
||||||
|
|
||||||
|
host := os.Getenv("CLOUDRON_POSTGRESQL_HOST")
|
||||||
|
if host == "" {
|
||||||
|
host = os.Getenv("PGHOST")
|
||||||
|
}
|
||||||
|
|
||||||
|
if host == "" {
|
||||||
|
log.Println("WARNING: No PostgreSQL host found in environment, using default")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force the PGHOST environment variable
|
||||||
|
os.Setenv("PGHOST", host)
|
||||||
|
|
||||||
|
log.Printf("Forcing database connections to use host: %s", host)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force correct database setup - this will be called instead of the original setupDatabase
|
||||||
|
func forceCorrectDatabase() (*sql.DB, error) {
|
||||||
|
host := os.Getenv("CLOUDRON_POSTGRESQL_HOST")
|
||||||
|
port := os.Getenv("CLOUDRON_POSTGRESQL_PORT")
|
||||||
|
user := os.Getenv("CLOUDRON_POSTGRESQL_USERNAME")
|
||||||
|
password := os.Getenv("CLOUDRON_POSTGRESQL_PASSWORD")
|
||||||
|
dbname := os.Getenv("CLOUDRON_POSTGRESQL_DATABASE")
|
||||||
|
|
||||||
|
connStr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
|
||||||
|
host, port, user, password, dbname)
|
||||||
|
|
||||||
|
log.Printf("Opening database connection with: %s", connStr)
|
||||||
|
return sql.Open("postgres", connStr)
|
||||||
|
}
|
||||||
|
EOT
|
||||||
|
echo "==> Created overrides/db_override.go"
|
||||||
|
|
||||||
# Patch source code directly for maximum effectiveness
|
# Patch source code directly for maximum effectiveness
|
||||||
if [ -d "$SERVER_DIR/cmd/museum" ]; then
|
if [ -d "$SERVER_DIR/cmd/museum" ]; then
|
||||||
MAIN_GO="$SERVER_DIR/cmd/museum/main.go"
|
MAIN_GO="$SERVER_DIR/cmd/museum/main.go"
|
||||||
@ -860,8 +914,8 @@ cat > /app/data/caddy/Caddyfile <<EOT
|
|||||||
|
|
||||||
console.log('Ente config loaded - API_URL:', window.ENTE_CONFIG.API_URL);
|
console.log('Ente config loaded - API_URL:', window.ENTE_CONFIG.API_URL);
|
||||||
console.log('Ente config loaded - PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL);
|
console.log('Ente config loaded - PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL);
|
||||||
" 200 {
|
" {
|
||||||
Content-Type "application/javascript"
|
header Content-Type "application/javascript"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -931,59 +985,4 @@ echo "==> Entering wait state - press Ctrl+C to stop"
|
|||||||
# Wait for all background processes to complete (or for user to interrupt)
|
# Wait for all background processes to complete (or for user to interrupt)
|
||||||
wait $SERVER_PID
|
wait $SERVER_PID
|
||||||
wait $PUBLIC_SERVER_PID
|
wait $PUBLIC_SERVER_PID
|
||||||
wait $CADDY_PID
|
wait $CADDY_PID
|
||||||
|
|
||||||
# Create the overrides directory and db_override.go file
|
|
||||||
mkdir -p "$SERVER_DIR/overrides"
|
|
||||||
echo "==> Creating db_override.go in overrides directory"
|
|
||||||
cat > "$SERVER_DIR/overrides/db_override.go" <<EOT
|
|
||||||
// Override database functions - will be added to museum build
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
_ "github.com/lib/pq" // Import the postgres driver
|
|
||||||
)
|
|
||||||
|
|
||||||
// This will run before main() and override the database functions
|
|
||||||
func init() {
|
|
||||||
log.Println("Database override patch is active")
|
|
||||||
|
|
||||||
host := os.Getenv("CLOUDRON_POSTGRESQL_HOST")
|
|
||||||
if host == "" {
|
|
||||||
host = os.Getenv("PGHOST")
|
|
||||||
}
|
|
||||||
|
|
||||||
if host == "" {
|
|
||||||
log.Println("WARNING: No PostgreSQL host found in environment, using default")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Force the PGHOST environment variable
|
|
||||||
os.Setenv("PGHOST", host)
|
|
||||||
|
|
||||||
log.Printf("Forcing database connections to use host: %s", host)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Force correct database setup - this will be called instead of the original setupDatabase
|
|
||||||
func forceCorrectDatabase() (*sql.DB, error) {
|
|
||||||
host := os.Getenv("CLOUDRON_POSTGRESQL_HOST")
|
|
||||||
port := os.Getenv("CLOUDRON_POSTGRESQL_PORT")
|
|
||||||
user := os.Getenv("CLOUDRON_POSTGRESQL_USERNAME")
|
|
||||||
password := os.Getenv("CLOUDRON_POSTGRESQL_PASSWORD")
|
|
||||||
dbname := os.Getenv("CLOUDRON_POSTGRESQL_DATABASE")
|
|
||||||
|
|
||||||
connStr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
|
|
||||||
host, port, user, password, dbname)
|
|
||||||
|
|
||||||
log.Printf("Opening database connection with: %s", connStr)
|
|
||||||
return sql.Open("postgres", connStr)
|
|
||||||
}
|
|
||||||
EOT
|
|
||||||
|
|
||||||
echo "==> Created overrides/db_override.go"
|
|
Loading…
x
Reference in New Issue
Block a user