package main import ( "context" "errors" "log" "os" "os/signal" "syscall" "time" ) func main() { s := NewServer() serverCtx, serverStopCtx := context.WithCancel(context.Background()) sig := make(chan os.Signal, 1) signal.Notify(sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) go func() { <-sig shutdownCtx, cancel := context.WithTimeout(serverCtx, 30*time.Second) go func() { <-shutdownCtx.Done() if errors.Is(shutdownCtx.Err(), context.DeadlineExceeded) { log.Println("Shutdown timeout, force exit") cancel() } }() err := s.Shutdown(shutdownCtx) if err != nil { log.Fatal(err) } serverStopCtx() }() // Spawn a goroutine to run git pull every 10 minutes //go RunGitRecipeWorker() // ** Use crontab instead ** err := s.Run() if err != nil { log.Fatal(err) } <-serverCtx.Done() }