/
main.go
64 lines (53 loc) · 1.7 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
58
59
60
61
62
63
64
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// The following enables go generate to generate the doc.go file.
//go:generate gendoc . -help
package main
import (
"fmt"
"v.io/v23"
"v.io/v23/context"
"v.io/x/lib/cmdline"
"v.io/x/ref/lib/signals"
"v.io/x/ref/lib/v23cmd"
_ "v.io/x/ref/runtime/factories/roaming"
)
var name, store string
func main() {
cmdAppD.Flags.StringVar(&name, "name", "", "Name to mount the application repository as.")
cmdAppD.Flags.StringVar(&store, "store", "", "Local directory to store application envelopes in.")
cmdline.HideGlobalFlagsExcept()
cmdline.Main(cmdAppD)
}
var cmdAppD = &cmdline.Command{
Runner: v23cmd.RunnerFunc(runAppD),
Name: "applicationd",
Short: "Runs the application daemon.",
Long: `
Command applicationd runs the application daemon, which implements the
v.io/x/ref/services/repository.Application interface.
`,
}
func runAppD(ctx *context.T, env *cmdline.Env, args []string) error {
if store == "" {
return env.UsageErrorf("Specify a directory for storing application envelopes using --store=<name>")
}
dispatcher, err := NewDispatcher(store)
if err != nil {
return fmt.Errorf("NewDispatcher() failed: %v", err)
}
ctx, server, err := v23.WithNewDispatchingServer(ctx, name, dispatcher)
if err != nil {
return fmt.Errorf("NewServer() failed: %v", err)
}
epName := server.Status().Endpoints[0].Name()
if name != "" {
ctx.Infof("Application repository serving at %q (%q)", name, epName)
} else {
ctx.Infof("Application repository serving at %q", epName)
}
// Wait until shutdown.
<-signals.ShutdownOnSignals(ctx)
return nil
}