-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (33 loc) · 842 Bytes
/
main.go
File metadata and controls
38 lines (33 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/AlexanderGrooff/spage/cmd"
"github.com/AlexanderGrooff/spage/pkg"
)
func main() {
// Set up signal handling for graceful shutdown
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
// Start command execution in a goroutine
errChan := make(chan error, 1)
go func() {
errChan <- cmd.RootCmd.Execute()
}()
// Wait for either command completion or signal
select {
case err := <-errChan:
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
case sig := <-sigChan:
fmt.Fprintf(os.Stderr, "Received signal %v, shutting down gracefully...\n", sig)
// Wait for any pending daemon reports to complete
_ = pkg.WaitForPendingReportsWithTimeout(10 * time.Second)
os.Exit(0)
}
}