forked from ipni/storetheindex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (51 loc) · 1.24 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
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/ipni/storetheindex/command"
"github.com/ipni/storetheindex/version"
"github.com/urfave/cli/v2"
)
func main() {
// Set up a context that is canceled when the command is interrupted
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Set up a signal handler to cancel the context
go func() {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, syscall.SIGTERM, syscall.SIGINT)
select {
case <-interrupt:
cancel()
fmt.Println("Received interrupt signal, shutting down...")
fmt.Println("(Hit ctrl-c again to force-shutdown the daemon.)")
case <-ctx.Done():
}
// Allow any further SIGTERM or SIGINT to kill process
signal.Stop(interrupt)
}()
app := &cli.App{
Name: "indexer",
Usage: "Indexer Node: Filecoin's data indexer",
Version: version.String(),
Commands: []*cli.Command{
command.AdminCmd,
command.AssignerCmd,
command.DaemonCmd,
command.FindCmd,
command.ImportCmd,
command.InitCmd,
command.LoadtestCmd,
command.LogCmd,
command.ProvidersCmd,
command.SPAddrCmd,
},
}
if err := app.RunContext(ctx, os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}