This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
/
apt_restore.go
60 lines (52 loc) · 1.66 KB
/
apt_restore.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
package main
import (
"flag"
"fmt"
"github.com/APTrust/exchange/context"
"github.com/APTrust/exchange/models"
"github.com/APTrust/exchange/workers"
"os"
)
// apt_restore reassembles IntellectualObjects into tarred bags
// and copies them to the depositor's receiving bucket for download.
func main() {
pathToConfigFile := parseCommandLine()
config, err := models.LoadConfigFile(pathToConfigFile)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
_context := context.NewContext(config)
_context.MessageLog.Info("Connecting to NSQLookupd at %s", _context.Config.NsqLookupd)
_context.MessageLog.Info("NSQDHttpAddress is %s", _context.Config.NsqdHttpAddress)
consumer, err := workers.CreateNsqConsumer(_context.Config, &_context.Config.RestoreWorker)
if err != nil {
_context.MessageLog.Fatalf(err.Error())
}
_context.MessageLog.Info("apt_restore started")
restorer := workers.NewAPTRestorer(_context)
consumer.AddHandler(restorer)
consumer.ConnectToNSQLookupd(_context.Config.NsqLookupd)
// This reader blocks until we get an interrupt, so our program does not exit.
<-consumer.StopChan
}
func parseCommandLine() (configFile string) {
var pathToConfigFile string
flag.StringVar(&pathToConfigFile, "config", "", "Path to APTrust config file")
flag.Parse()
if pathToConfigFile == "" {
printUsage()
os.Exit(1)
}
return pathToConfigFile
}
// Tell the user about the program.
func printUsage() {
message := `
apt_restore reassembles IntellectualObjects into tarred bags
and copies them to the depositor's receiving bucket for download.
Usage: apt_restore -config=<path to APTrust config file>
Param -config is required.
`
fmt.Println(message)
}