-
Notifications
You must be signed in to change notification settings - Fork 15
/
provider.go
72 lines (64 loc) 路 1.36 KB
/
provider.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 (
"context"
"fmt"
"os"
"os/signal"
"syscall"
provider "github.com/ipni/index-provider"
"github.com/urfave/cli/v2"
)
func main() {
os.Exit(run())
}
func run() int {
// 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 SIGING to kill the process
signal.Stop(interrupt)
}()
var rev string
if provider.Modified {
rev = "SNAPSHOT"
} else {
rev = provider.Revision
if len(rev) > 7 {
rev = rev[:7]
}
}
version := provider.Release + "-" + rev
app := &cli.App{
Name: "provider",
Usage: "Indexer Reference Provider Implementation",
Version: version,
Commands: []*cli.Command{
AnnounceCmd,
AnnounceHttpCmd,
ConnectCmd,
DaemonCmd,
ImportCmd,
IndexCmd,
InitCmd,
ListCmd,
RemoveCmd,
Mirror.Command,
},
}
if err := app.RunContext(ctx, os.Args); err != nil {
fmt.Fprintln(app.ErrWriter, err)
return 1
}
return 0
}