-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.go
71 lines (62 loc) · 1.36 KB
/
start.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
package commands
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/ms900ft/movielite"
"github.com/ms900ft/movielite/pkg/token"
"github.com/urfave/cli"
"golang.org/x/sync/errgroup"
)
// StartCommand is used to register the start cli command
var StartCommand = cli.Command{
Name: "start",
Usage: "Starts web server",
//Flags: startFlags,
Action: startAction,
}
var (
g errgroup.Group
)
// startAction start the web server and initializes the daemon
func startAction(ctx *cli.Context) error {
conf := movielite.GetConfig(ctx.GlobalString("config"))
a := movielite.Service{Config: conf}
w := movielite.Walker{Config: conf}
a.Initialize()
token, err := token.AdminToken(conf.Secret)
if err != nil {
log.Fatal(err)
}
w.Token = token
var gracefulStop = make(chan os.Signal)
signal.Notify(gracefulStop, syscall.SIGTERM)
signal.Notify(gracefulStop, syscall.SIGINT)
go func() {
sig := <-gracefulStop
a.WorkerPool.Stop()
fmt.Printf("caught sig: %+v", sig)
fmt.Println("Wait for 2 second to finish processing")
time.Sleep(2 * time.Second)
os.Exit(0)
}()
//a.Run(":8080")
g.Go(func() error {
return a.Run()
})
g.Go(func() error {
return w.RunWatcher()
})
// if viper.GetBool("Rescan.Enable") {
// g.Go(func() error {
// return r.Run()
// })
// }
if err := g.Wait(); err != nil {
log.Fatal(err)
}
return nil
}