forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
79 lines (64 loc) · 1.9 KB
/
main.go
File metadata and controls
79 lines (64 loc) · 1.9 KB
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
73
74
75
76
77
78
79
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/sourcegraph/sourcegraph/cmd/precise-code-intel-api-server/internal/janitor"
"github.com/sourcegraph/sourcegraph/cmd/precise-code-intel-api-server/internal/server"
bundles "github.com/sourcegraph/sourcegraph/internal/codeintel/bundles/client"
"github.com/sourcegraph/sourcegraph/internal/codeintel/db"
"github.com/sourcegraph/sourcegraph/internal/conf"
"github.com/sourcegraph/sourcegraph/internal/debugserver"
"github.com/sourcegraph/sourcegraph/internal/env"
"github.com/sourcegraph/sourcegraph/internal/tracer"
)
func main() {
env.Lock()
env.HandleHelpFlag()
tracer.Init()
var (
janitorInterval = mustParseInterval(rawJanitorInterval, "PRECISE_CODE_INTEL_JANITOR_INTERVAL")
bundleManagerURL = mustGet(rawBundleManagerURL, "PRECISE_CODE_INTEL_BUNDLE_MANAGER_URL")
)
db := mustInitializeDatabase()
host := ""
if env.InsecureDev {
host = "127.0.0.1"
}
serverInst := server.New(server.ServerOpts{
Host: host,
Port: 3186,
DB: db,
BundleManagerClient: bundles.New(bundleManagerURL),
})
janitorInst := janitor.NewJanitor(janitor.JanitorOpts{
DB: db,
JanitorInterval: janitorInterval,
})
go serverInst.Start()
go janitorInst.Start()
go debugserver.Start()
waitForSignal()
}
func mustInitializeDatabase() db.DB {
postgresDSN := conf.Get().ServiceConnections.PostgresDSN
conf.Watch(func() {
if newDSN := conf.Get().ServiceConnections.PostgresDSN; postgresDSN != newDSN {
log.Fatalf("Detected repository DSN change, restarting to take effect: %s", newDSN)
}
})
db, err := db.New(postgresDSN)
if err != nil {
log.Fatalf("failed to initialize db store: %s", err)
}
return db
}
func waitForSignal() {
signals := make(chan os.Signal, 2)
signal.Notify(signals, syscall.SIGINT, syscall.SIGHUP)
for i := 0; i < 2; i++ {
<-signals
}
os.Exit(0)
}