mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 00:22:14 +01:00
New environment variables : DISABLE_HEALTHCHECK_LOGGING and DEFAULT_LISTEN_PORT (#78)
* skip logging when healthcheck url is called; closes #74 (#75) Signed-off-by: Casey Kuhlman <casey@monax.io> * Configure listen port via environment variable (#77) * skip logging when healthcheck url is called; closes #74 Signed-off-by: Casey Kuhlman <casey@monax.io> * skip logging when healthcheck url is called; closes #74 Signed-off-by: Casey Kuhlman <casey@monax.io> * adds the ability to establish the listen port via env var Signed-off-by: Casey Kuhlman <casey@monax.io> * minor refactoring of @compleatang work * fixing typo
This commit is contained in:
@@ -20,9 +20,11 @@ import (
|
||||
var version = "snapshot"
|
||||
|
||||
const (
|
||||
defaultWaitTimeoutEnvVar = "DEFAULT_WAIT_TIMEOUT"
|
||||
disableGoogleChromeEnvVar = "DISABLE_GOOGLE_CHROME"
|
||||
disableUnoconvEnvVar = "DISABLE_UNOCONV"
|
||||
defaultWaitTimeoutEnvVar = "DEFAULT_WAIT_TIMEOUT"
|
||||
defaultListenPortEnvVar = "DEFAULT_LISTEN_PORT"
|
||||
disableGoogleChromeEnvVar = "DISABLE_GOOGLE_CHROME"
|
||||
disableUnoconvEnvVar = "DISABLE_UNOCONV"
|
||||
disableHealthcheckLoggingEnvVar = "DISABLE_HEALTHCHECK_LOGGING"
|
||||
)
|
||||
|
||||
func mustParseEnvVar() *api.Options {
|
||||
@@ -35,6 +37,18 @@ func mustParseEnvVar() *api.Options {
|
||||
}
|
||||
opts.DefaultWaitTimeout = defaultWaitTimeout
|
||||
}
|
||||
if v, ok := os.LookupEnv(defaultListenPortEnvVar); ok {
|
||||
defaultListener, err := strconv.ParseUint(os.Getenv(defaultListenPortEnvVar), 10, 64)
|
||||
if err != nil {
|
||||
notify.ErrPrint(fmt.Errorf("%s: wrong value: want uint got %v", defaultListenPortEnvVar, err))
|
||||
os.Exit(1)
|
||||
}
|
||||
if defaultListener > 65535 {
|
||||
notify.ErrPrint(fmt.Errorf("%s: wrong value: want uint < 65535 got %v", defaultListenPortEnvVar, defaultListener))
|
||||
os.Exit(1)
|
||||
}
|
||||
opts.DefaultListenPort = v
|
||||
}
|
||||
if v, ok := os.LookupEnv(disableGoogleChromeEnvVar); ok {
|
||||
if v != "1" && v != "0" {
|
||||
notify.ErrPrint(fmt.Errorf("%s: wrong value: want \"0\" or \"1\" got %v", disableGoogleChromeEnvVar, v))
|
||||
@@ -49,6 +63,13 @@ func mustParseEnvVar() *api.Options {
|
||||
}
|
||||
opts.EnableUnoconvEndpoints = v != "1"
|
||||
}
|
||||
if v, ok := os.LookupEnv(disableHealthcheckLoggingEnvVar); ok {
|
||||
if v != "1" && v != "0" {
|
||||
notify.ErrPrint(fmt.Errorf("%s: wrong value: want \"0\" or \"1\" got %v", disableHealthcheckLoggingEnvVar, v))
|
||||
os.Exit(1)
|
||||
}
|
||||
opts.EnableHealthcheckLogging = v != "1"
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
@@ -70,9 +91,9 @@ func mustStartProcesses(opts *api.Options) []pm2.Process {
|
||||
return processes
|
||||
}
|
||||
|
||||
func mustStartAPI(srv *echo.Echo) {
|
||||
notify.Print("http server started on port 3000")
|
||||
if err := srv.Start(":3000"); err != nil {
|
||||
func mustStartAPI(srv *echo.Echo, port string) {
|
||||
notify.Printf("http server started on port %v", port)
|
||||
if err := srv.Start(fmt.Sprintf(":%v", port)); err != nil {
|
||||
if err != http.ErrServerClosed {
|
||||
notify.ErrPrint(err)
|
||||
os.Exit(1)
|
||||
@@ -110,7 +131,7 @@ func main() {
|
||||
processes := mustStartProcesses(opts)
|
||||
// run our API in a goroutine so that it doesn't block.s
|
||||
go func() {
|
||||
mustStartAPI(srv)
|
||||
mustStartAPI(srv, opts.DefaultListenPort)
|
||||
}()
|
||||
quit := make(chan os.Signal, 1)
|
||||
// we'll accept graceful shutdowns when quit via SIGINT (Ctrl+C)
|
||||
|
||||
Reference in New Issue
Block a user