This repository has been archived by the owner on Apr 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
72 lines (60 loc) · 1.63 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"flag"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/leapp-to/leapp-go/pkg/actors"
"github.com/leapp-to/leapp-go/pkg/web"
_ "github.com/mattn/go-sqlite3"
)
var (
defaultReadTimeout = 5 // seconds
flagHelp = flag.Bool("help", false, "show usage")
flagListen = flag.String("listen", "127.0.0.1:8000", "host:port to listen on.")
flagTimeout = flag.Int64("timeout", 10, "time range in which daemon has to send a response to the client.")
flagVerbose = flag.Bool("verbose", false, "enable verbose mode")
)
func main() {
os.Exit(Main(nil))
}
// Main controls the startup and shutdown of the daemon lifecycle
func Main(up chan<- struct{}) int {
flag.Parse()
if *flagHelp {
flag.Usage()
return 0
}
// Parse options
options := web.Options{
ListenAddress: *flagListen,
ReadTimeout: time.Duration(defaultReadTimeout),
WriteTimeout: time.Duration(*flagTimeout),
Verbose: *flagVerbose,
}
actorAPI, err := actors.NewActorAPIService(false)
if err != nil {
log.Printf("Failed to start actor API service %s", err.Error())
return 1
}
defer actorAPI.Close()
// Start HTTP server
webHandler := web.New(&options)
log.Printf("Starting leapp-daemon at %s\n", options.ListenAddress)
go webHandler.Run()
// Handle shutdown under different conditions
term := make(chan os.Signal, 1)
signal.Notify(term, os.Interrupt, syscall.SIGTERM)
select {
case <-term:
log.Println("Received SIGTERM. Shutting down...")
case up <- struct{}{}:
log.Println("Up channel unblocked. Shutting down...")
case err := <-webHandler.ErrorCh():
log.Printf("Error starting service: %v\n", err)
return 1
}
return 0
}