-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
40 lines (32 loc) · 771 Bytes
/
main.go
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
39
40
package main
import (
"context"
"github.com/renorris/openfsd/bootstrap"
"log"
"os"
"os/signal"
"syscall"
)
func main() {
b := bootstrap.NewDefaultBootstrap()
log.Println("Starting services...")
ctx, cancel := context.WithCancel(context.Background())
if err := b.Start(ctx); err != nil {
log.Fatalln(err)
}
log.Println("All services started.")
// Listen for OS signals
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
// Wait for either an error or a shutdown signal
select {
case sig := <-sigCh:
log.Printf("received %s", sig)
cancel()
case <-b.Done:
log.Println("FATAL: a service exited early.")
}
log.Println("Waiting for services to stop...")
<-b.Done
log.Println("All services stopped.")
}