Skip to content

Commit 7f86c8c

Browse files
Implement --import mode and re-order startup
This commit modifies the startup sequence somewhat, so that OS signals are only listened for if NodeAtlas is starting up normally. Ref #62
1 parent cb21de2 commit 7f86c8c

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

nodeatlas.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var (
4848

4949
fReadOnly = flag.Bool("readonly", false, "disallow database changes")
5050

51+
fImport = flag.String("import", "", "import a JSON array of nodes")
5152
fTestDB = flag.Bool("testdb", false, "test the database")
5253
)
5354

@@ -90,9 +91,6 @@ func main() {
9091
os.Exit(1)
9192
}
9293

93-
// Listen for OS signals.
94-
go ListenSignal()
95-
9694
l.Infof("Starting NodeAtlas %s\n", Version)
9795

9896
// Compile and template the static directory.
@@ -159,6 +157,21 @@ func main() {
159157
l.Debug("Initialized database\n")
160158
l.Infof("Nodes: %d (%d local)\n", Db.LenNodes(true), Db.LenNodes(false))
161159

160+
// Check action flags and abandon normal startup if any are set.
161+
if len(*fImport) != 0 {
162+
err := ImportFile(*fImport)
163+
if err != nil {
164+
l.Fatalf("Import failed: %s", err)
165+
} else {
166+
l.Printf("Import successful!")
167+
}
168+
return
169+
}
170+
171+
// Listen for OS signals.
172+
go ListenSignal()
173+
174+
// Start the Heartbeat.
162175
Heartbeat()
163176
l.Debug("Heartbeat started\n")
164177

0 commit comments

Comments
 (0)