-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Caddy and Pocketbase, together at last
- Loading branch information
Showing
5 changed files
with
109 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package pocketfhir | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
func StartPocketFHIR(dataDir string, hostname string, port string, getApiLogs bool, caddyPort string, caddyStoragePath string) { | ||
// Set environment variables for PocketBase configuration | ||
log.Println("[DEBUG] Setting environment variables...") | ||
if err := os.Setenv("POCKETBASE_DATA_DIR", dataDir); err != nil { | ||
log.Fatalf("Failed to set data directory: %v", err) | ||
} | ||
|
||
// Handle graceful shutdown signal | ||
log.Println("[DEBUG] Setting up channel for graceful shutdown...") | ||
stop := make(chan os.Signal, 1) | ||
signal.Notify(stop, os.Interrupt, syscall.SIGTERM) | ||
|
||
// Start the PocketFHIR server in a separate goroutine | ||
go func() { | ||
log.Println("[DEBUG] Starting PocketFHIR server...") | ||
RunServer(dataDir, hostname, port, getApiLogs) | ||
}() | ||
|
||
// Start the Caddy server in a separate goroutine | ||
go func() { | ||
log.Println("[DEBUG] Starting Caddy server...") | ||
StartCaddy(caddyPort, fmt.Sprintf("http://%s:%s", hostname, port), caddyStoragePath) | ||
}() | ||
|
||
// Wait for interrupt signal to gracefully shut down the server | ||
log.Println("[DEBUG] Waiting for interrupt signal to shut down the servers...") | ||
<-stop | ||
log.Println("Shutting down PocketFHIR and Caddy servers...") | ||
StopServer() // PocketFHIR shutdown | ||
log.Println("PocketFHIR and Caddy servers shut down gracefully.") | ||
} |