blob: a27e94a76a78de7212f7571c3c65565b57c99ca9 (
plain) (
blame)
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
80
81
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: arnej
package main
import (
"fmt"
"os"
"runtime"
"strings"
"github.com/vespa-engine/vespa/client/go/cmd/clusterstate"
"github.com/vespa-engine/vespa/client/go/cmd/deploy"
"github.com/vespa-engine/vespa/client/go/cmd/logfmt"
"github.com/vespa-engine/vespa/client/go/script-utils/startcbinary"
"github.com/vespa-engine/vespa/client/go/vespa"
)
func basename(s string) string {
parts := strings.Split(s, "/")
return parts[len(parts)-1]
}
func main() {
defer handleSimplePanic()
action := basename(os.Args[0])
if action == "script-utils" && len(os.Args) > 1 {
action = os.Args[1]
os.Args = os.Args[1:]
}
_ = vespa.FindHome()
switch action {
case "start-c-binary":
os.Exit(startcbinary.Run(os.Args[1:]))
case "export-env":
vespa.ExportDefaultEnvToSh()
case "security-env":
vespa.ExportSecurityEnvToSh()
case "ipv6-only":
if vespa.HasOnlyIpV6() {
os.Exit(0)
} else {
os.Exit(1)
}
case "vespa-deploy":
cobra := deploy.NewDeployCmd()
cobra.Execute()
case "vespa-logfmt":
cobra := logfmt.NewLogfmtCmd()
cobra.Execute()
case "vespa-get-cluster-state":
cobra := clusterstate.NewGetClusterStateCmd()
cobra.Execute()
case "vespa-get-node-state":
cobra := clusterstate.NewGetNodeStateCmd()
cobra.Execute()
case "vespa-set-node-state":
cobra := clusterstate.NewSetNodeStateCmd()
cobra.Execute()
default:
if startcbinary.IsCandidate(os.Args[0]) {
os.Exit(startcbinary.Run(os.Args))
}
fmt.Fprintf(os.Stderr, "unknown action '%s'\n", action)
fmt.Fprintln(os.Stderr, "actions: export-env, ipv6-only, security-env")
fmt.Fprintln(os.Stderr, "(also: vespa-deploy, vespa-logfmt)")
}
}
func handleSimplePanic() {
if r := recover(); r != nil {
if rte, ok := r.(runtime.Error); ok {
panic(rte)
} else if je, ok := r.(error); ok {
fmt.Fprintln(os.Stderr, je)
os.Exit(1)
} else {
panic(r)
}
}
}
|