diff --git a/build/docs/content/03-environment-variables.md b/build/docs/content/03-environment-variables.md index 1a915e04..3f081d56 100644 --- a/build/docs/content/03-environment-variables.md +++ b/build/docs/content/03-environment-variables.md @@ -13,7 +13,6 @@ It takes the strings `"0"` or `"1"` as value. > If Google Chrome is disabled, the following conversions will **not** be available anymore: > [HTML](#html), [URL](#url) and [Markdown](#markdown) - ## Disable LibreOffice (unoconv) You may also disable LibreOffice (unoconv) with `DISABLE_UNOCONV`. @@ -30,4 +29,20 @@ You may customize this timeout thanks to the environment variable `DEFAULT_WAIT_ It takes a string representation of a float as value (e.g `"2.5"` for 2.5 seconds). > The default timeout may also be overridden per request thanks to the form field `waitTimeout`. -> See the [timeout section](#timeout). \ No newline at end of file +> See the [timeout section](#timeout). + +## Disable logging on healthcheck + +By default, the API will add a log entry when the [healthcheck endpoint](#ping) is called. + +You may turn off this logging so as to avoid unnecessary entries in your logs with the environment variable `DISABLE_HEALTHCHECK_LOGGING`. + +This environment variable operates in the same manner as the `DISABLE_GOOGLE_CHROME` and `DISABLE_UNOCONV` variables operate in that it accepts the strings `"0"` or `"1"` as values. + +## Default listen port + +By default, the API will listen on port `3000`. For most use cases this is perfectly fine, but at times there may be cases where you need to change this due to port conflicts. + +You may customize this port location with the environment variable `DEFAULT_LISTEN_PORT`. + +This environment variable accepts any string that can be turned into a port number (e.g., the string `"0"` up to the string `"65535"`). \ No newline at end of file diff --git a/cmd/gotenberg/main.go b/cmd/gotenberg/main.go index e5e19324..0d7d7cea 100644 --- a/cmd/gotenberg/main.go +++ b/cmd/gotenberg/main.go @@ -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) diff --git a/docs/index.html b/docs/index.html index 114bbd93..bcf2fd81 100755 --- a/docs/index.html +++ b/docs/index.html @@ -255,6 +255,26 @@ Gotenberg API is available at http://localhost:3 See the timeout section.
+By default, the API will add a log entry when the healthcheck endpoint is called.
+ +You may turn off this logging so as to avoid unnecessary entries in your logs with the environment variable DISABLE_HEALTHCHECK_LOGGING.
This environment variable operates in the same manner as the DISABLE_GOOGLE_CHROME and DISABLE_UNOCONV variables operate in that it accepts the strings "0" or "1" as values.
By default, the API will listen on port 3000. For most use cases this is perfectly fine, but at times there may be cases where you need to change this due to port conflicts.
You may customize this port location with the environment variable DEFAULT_LISTEN_PORT.
This environment variable accepts any string that can be turned into a port number (e.g., the string "0" up to the string "65535").