1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.arvados.org/arvados.git/lib/boot"
16 "git.arvados.org/arvados.git/lib/cloud/cloudtest"
17 "git.arvados.org/arvados.git/lib/cmd"
18 "git.arvados.org/arvados.git/lib/config"
19 "git.arvados.org/arvados.git/lib/controller"
20 "git.arvados.org/arvados.git/lib/crunchrun"
21 "git.arvados.org/arvados.git/lib/dispatchcloud"
22 "git.arvados.org/arvados.git/lib/install"
23 "git.arvados.org/arvados.git/lib/lsf"
24 "git.arvados.org/arvados.git/lib/recovercollection"
25 "git.arvados.org/arvados.git/lib/service"
26 "git.arvados.org/arvados.git/sdk/go/arvados"
27 "git.arvados.org/arvados.git/sdk/go/health"
28 "git.arvados.org/arvados.git/services/githttpd"
29 keepbalance "git.arvados.org/arvados.git/services/keep-balance"
30 keepweb "git.arvados.org/arvados.git/services/keep-web"
31 "git.arvados.org/arvados.git/services/keepproxy"
32 "git.arvados.org/arvados.git/services/keepstore"
33 "git.arvados.org/arvados.git/services/ws"
34 "github.com/prometheus/client_golang/prometheus"
38 handler = cmd.Multi(map[string]cmd.Handler{
39 "version": cmd.Version,
40 "-version": cmd.Version,
41 "--version": cmd.Version,
44 "check": health.CheckCommand,
45 "cloudtest": cloudtest.Command,
46 "config-check": config.CheckCommand,
47 "config-defaults": config.DumpDefaultsCommand,
48 "config-dump": config.DumpCommand,
49 "controller": controller.Command,
50 "crunch-run": crunchrun.Command,
51 "dispatch-cloud": dispatchcloud.Command,
52 "dispatch-lsf": lsf.DispatchCommand,
53 "git-httpd": githttpd.Command,
54 "health": healthCommand,
55 "install": install.Command,
56 "init": install.InitCommand,
57 "keep-balance": keepbalance.Command,
58 "keep-web": keepweb.Command,
59 "keepproxy": keepproxy.Command,
60 "keepstore": keepstore.Command,
61 "recover-collection": recovercollection.Command,
62 "workbench2": wb2command{},
68 os.Exit(handler.RunCommand(os.Args[0], os.Args[1:], os.Stdin, os.Stdout, os.Stderr))
71 type wb2command struct{}
73 func (wb2command) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
75 fmt.Fprintf(stderr, "usage: %s api-host listen-addr app-dir\n", prog)
78 configJSON, err := json.Marshal(map[string]string{"API_HOST": args[0]})
80 fmt.Fprintf(stderr, "json.Marshal: %s\n", err)
83 mux := http.NewServeMux()
84 mux.Handle("/", http.FileServer(http.Dir(args[2])))
85 mux.HandleFunc("/config.json", func(w http.ResponseWriter, _ *http.Request) {
88 mux.HandleFunc("/_health/ping", func(w http.ResponseWriter, _ *http.Request) {
89 io.WriteString(w, `{"health":"OK"}`)
91 err = http.ListenAndServe(args[1], mux)
93 fmt.Fprintln(stderr, err.Error())
99 var healthCommand cmd.Handler = service.Command(arvados.ServiceNameHealth, func(ctx context.Context, cluster *arvados.Cluster, _ string, reg *prometheus.Registry) service.Handler {
100 mClockSkew := prometheus.NewGauge(prometheus.GaugeOpts{
101 Namespace: "arvados",
103 Name: "clock_skew_seconds",
104 Help: "Clock skew observed in most recent health check",
106 reg.MustRegister(mClockSkew)
107 return &health.Aggregator{
109 MetricClockSkew: mClockSkew,