1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
18 "git.arvados.org/arvados.git/lib/boot"
19 "git.arvados.org/arvados.git/lib/cloud/cloudtest"
20 "git.arvados.org/arvados.git/lib/cmd"
21 "git.arvados.org/arvados.git/lib/config"
22 "git.arvados.org/arvados.git/lib/controller"
23 "git.arvados.org/arvados.git/lib/crunchrun"
24 "git.arvados.org/arvados.git/lib/dispatchcloud"
25 "git.arvados.org/arvados.git/lib/install"
26 "git.arvados.org/arvados.git/lib/lsf"
27 "git.arvados.org/arvados.git/lib/recovercollection"
28 "git.arvados.org/arvados.git/lib/service"
29 "git.arvados.org/arvados.git/sdk/go/arvados"
30 "git.arvados.org/arvados.git/sdk/go/health"
31 dispatchslurm "git.arvados.org/arvados.git/services/crunch-dispatch-slurm"
32 "git.arvados.org/arvados.git/services/githttpd"
33 keepbalance "git.arvados.org/arvados.git/services/keep-balance"
34 keepweb "git.arvados.org/arvados.git/services/keep-web"
35 "git.arvados.org/arvados.git/services/keepproxy"
36 "git.arvados.org/arvados.git/services/keepstore"
37 "git.arvados.org/arvados.git/services/ws"
38 "github.com/prometheus/client_golang/prometheus"
42 handler = cmd.Multi(map[string]cmd.Handler{
43 "version": cmd.Version,
44 "-version": cmd.Version,
45 "--version": cmd.Version,
48 "check": health.CheckCommand,
49 "cloudtest": cloudtest.Command,
50 "config-check": config.CheckCommand,
51 "config-defaults": config.DumpDefaultsCommand,
52 "config-dump": config.DumpCommand,
53 "controller": controller.Command,
54 "crunch-run": crunchrun.Command,
55 "dispatch-cloud": dispatchcloud.Command,
56 "dispatch-lsf": lsf.DispatchCommand,
57 "dispatch-slurm": dispatchslurm.Command,
58 "git-httpd": githttpd.Command,
59 "health": healthCommand,
60 "install": install.Command,
61 "init": install.InitCommand,
62 "keep-balance": keepbalance.Command,
63 "keep-web": keepweb.Command,
64 "keepproxy": keepproxy.Command,
65 "keepstore": keepstore.Command,
66 "recover-collection": recovercollection.Command,
67 "workbench2": wb2command{},
73 os.Exit(handler.RunCommand(os.Args[0], os.Args[1:], os.Stdin, os.Stdout, os.Stderr))
76 type wb2command struct{}
78 func (wb2command) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
80 fmt.Fprintf(stderr, "usage: %s api-host listen-addr app-dir\n", prog)
83 configJSON, err := json.Marshal(map[string]string{"API_HOST": args[0]})
85 fmt.Fprintf(stderr, "json.Marshal: %s\n", err)
88 servefs := http.FileServer(http.Dir(args[2]))
89 mux := http.NewServeMux()
90 mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
91 for _, ent := range strings.Split(req.URL.Path, "/") {
93 http.Error(w, "invalid URL path", http.StatusBadRequest)
97 fnm := filepath.Join(args[2], filepath.FromSlash(path.Clean("/"+req.URL.Path)))
98 if _, err := os.Stat(fnm); os.IsNotExist(err) {
101 servefs.ServeHTTP(w, req)
103 mux.HandleFunc("/config.json", func(w http.ResponseWriter, _ *http.Request) {
106 mux.HandleFunc("/_health/ping", func(w http.ResponseWriter, _ *http.Request) {
107 io.WriteString(w, `{"health":"OK"}`)
109 err = http.ListenAndServe(args[1], mux)
111 fmt.Fprintln(stderr, err.Error())
117 var healthCommand cmd.Handler = service.Command(arvados.ServiceNameHealth, func(ctx context.Context, cluster *arvados.Cluster, _ string, reg *prometheus.Registry) service.Handler {
118 mClockSkew := prometheus.NewGauge(prometheus.GaugeOpts{
119 Namespace: "arvados",
121 Name: "clock_skew_seconds",
122 Help: "Clock skew observed in most recent health check",
124 reg.MustRegister(mClockSkew)
125 return &health.Aggregator{
127 MetricClockSkew: mClockSkew,