feat: add ability to delay startup (#631)

* Feat: add ability to delay startup

* Enable ability to set delay seconds before start up gatus

* Update README.md

* Delete .examples/delay-startup/Makefile

---------

Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
I-HSIN Cheng 2023-12-25 09:48:43 +08:00 committed by GitHub
parent 3c246f0c69
commit 1e82d2f07d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -101,6 +101,7 @@ Have any feedback or questions? [Create a discussion](https://github.com/TwiN/ga
- [Endpoint groups](#endpoint-groups) - [Endpoint groups](#endpoint-groups)
- [Exposing Gatus on a custom path](#exposing-gatus-on-a-custom-path) - [Exposing Gatus on a custom path](#exposing-gatus-on-a-custom-path)
- [Exposing Gatus on a custom port](#exposing-gatus-on-a-custom-port) - [Exposing Gatus on a custom port](#exposing-gatus-on-a-custom-port)
- [Configuring a startup delay](#configuring-a-startup-delay)
- [Keeping your configuration small](#keeping-your-configuration-small) - [Keeping your configuration small](#keeping-your-configuration-small)
- [Badges](#badges) - [Badges](#badges)
- [Uptime](#uptime) - [Uptime](#uptime)
@ -1864,6 +1865,10 @@ web:
``` ```
### Configuring a startup delay
If, for any reason, you need Gatus to wait for a given amount of time before monitoring the endpoints on application start, you can use the `GATUS_DELAY_START_SECONDS` environment variable to make Gatus sleep on startup.
### Keeping your configuration small ### Keeping your configuration small
While not specific to Gatus, you can leverage YAML anchors to create a default configuration. While not specific to Gatus, you can leverage YAML anchors to create a default configuration.
If you have a large configuration file, this should help you keep things clean. If you have a large configuration file, this should help you keep things clean.

View File

@ -4,6 +4,7 @@ import (
"log" "log"
"os" "os"
"os/signal" "os/signal"
"strconv"
"syscall" "syscall"
"time" "time"
@ -14,6 +15,10 @@ import (
) )
func main() { func main() {
if delayInSeconds, _ := strconv.Atoi(os.Getenv("GATUS_DELAY_START_SECONDS")); delayInSeconds > 0 {
log.Printf("Delaying start by %d seconds", delayInSeconds)
time.Sleep(time.Duration(delayInSeconds) * time.Second)
}
cfg, err := loadConfiguration() cfg, err := loadConfiguration()
if err != nil { if err != nil {
panic(err) panic(err)