21189: On usage error, exit 64 and do not auto-restart.
authorTom Clegg <tom@curii.com>
Wed, 15 Nov 2023 14:49:04 +0000 (09:49 -0500)
committerTom Clegg <tom@curii.com>
Wed, 15 Nov 2023 15:48:40 +0000 (10:48 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

17 files changed:
cmd/arvados-client/cmd_test.go
cmd/arvados-server/arvados-controller.service
cmd/arvados-server/arvados-dispatch-cloud.service
cmd/arvados-server/arvados-dispatch-lsf.service
cmd/arvados-server/arvados-git-httpd.service
cmd/arvados-server/arvados-health.service
cmd/arvados-server/arvados-ws.service
cmd/arvados-server/crunch-dispatch-slurm.service
cmd/arvados-server/keep-balance.service
cmd/arvados-server/keep-web.service
cmd/arvados-server/keepproxy.service
cmd/arvados-server/keepstore.service
lib/cli/get.go
lib/cmd/cmd.go
lib/cmd/cmd_test.go
lib/cmd/parseflags.go
lib/config/cmd_test.go

index cbbc7b1f9505cf58515bfdade093298cb8a182da..5cbb1e5e4adab4600ccd00b4121862257bd5a241 100644 (file)
@@ -9,6 +9,7 @@ import (
        "io/ioutil"
        "testing"
 
+       "git.arvados.org/arvados.git/lib/cmd"
        check "gopkg.in/check.v1"
 )
 
@@ -23,12 +24,12 @@ type ClientSuite struct{}
 
 func (s *ClientSuite) TestBadCommand(c *check.C) {
        exited := handler.RunCommand("arvados-client", []string{"no such command"}, bytes.NewReader(nil), ioutil.Discard, ioutil.Discard)
-       c.Check(exited, check.Equals, 2)
+       c.Check(exited, check.Equals, cmd.EX_USAGE)
 }
 
 func (s *ClientSuite) TestBadSubcommandArgs(c *check.C) {
        exited := handler.RunCommand("arvados-client", []string{"get"}, bytes.NewReader(nil), ioutil.Discard, ioutil.Discard)
-       c.Check(exited, check.Equals, 2)
+       c.Check(exited, check.Equals, cmd.EX_USAGE)
 }
 
 func (s *ClientSuite) TestVersion(c *check.C) {
index 420cbb035a7e7177f84ef7a9ca07117d70e37e5f..cf680f959f394f98768e2dc0734f8b1ac6d30e0b 100644 (file)
@@ -19,6 +19,7 @@ ExecStart=/usr/bin/arvados-controller
 LimitNOFILE=65536
 Restart=always
 RestartSec=1
+RestartPreventExitStatus=64
 
 # systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
 StartLimitInterval=0
index 8d57e8a1612ca49ecc9d98b44a716eb1485e2640..61e2325d263637584f4e906aa8658aab64d71623 100644 (file)
@@ -19,6 +19,7 @@ ExecStart=/usr/bin/arvados-dispatch-cloud
 LimitNOFILE=65536
 Restart=always
 RestartSec=1
+RestartPreventExitStatus=64
 
 # systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
 StartLimitInterval=0
index 65d8786670af43a4e1a8ce610fdd3babf5af1270..931ef405628013f4d8f5cd544faf00eae2b3b22f 100644 (file)
@@ -19,6 +19,7 @@ ExecStart=/usr/bin/arvados-dispatch-lsf
 LimitNOFILE=65536
 Restart=always
 RestartSec=1
+RestartPreventExitStatus=64
 
 # systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
 StartLimitInterval=0
index b45587ffc06bd683467b8a5f3de086a08e5598b9..b86293d97798b1a628ca9182aea6ff4e8a34d5bb 100644 (file)
@@ -19,6 +19,7 @@ ExecStart=/usr/bin/arvados-git-httpd
 LimitNOFILE=65536
 Restart=always
 RestartSec=1
+RestartPreventExitStatus=64
 
 # systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
 StartLimitInterval=0
index cf246b0ee2a13a0fbd830a47314e1203067af822..4605681cb8f994d3576d50e82a122bb30ab6895f 100644 (file)
@@ -19,6 +19,7 @@ ExecStart=/usr/bin/arvados-health
 LimitNOFILE=65536
 Restart=always
 RestartSec=1
+RestartPreventExitStatus=64
 
 # systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
 StartLimitInterval=0
index f73db5d08032369c619e42429ddf7a68550b8551..5ba7b54c7d39c838c1f8ef70fdf5aa81846533a0 100644 (file)
@@ -18,6 +18,7 @@ ExecStart=/usr/bin/arvados-ws
 LimitNOFILE=65536
 Restart=always
 RestartSec=1
+RestartPreventExitStatus=64
 
 # systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
 StartLimitInterval=0
index 51b4e58c35b77ce1f391be6cea43f46d4961cd07..53b0157807dd062ea9a97497a5addf2ac506a568 100644 (file)
@@ -19,6 +19,7 @@ ExecStart=/usr/bin/crunch-dispatch-slurm
 LimitNOFILE=65536
 Restart=always
 RestartSec=1
+RestartPreventExitStatus=64
 
 # systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
 StartLimitInterval=0
index 1c5808288b38a4e0a1b5b4706cfa446f6a224841..6b16b2cfab709d93c028b0f3343a709057dd5b10 100644 (file)
@@ -20,6 +20,7 @@ LimitNOFILE=65536
 Restart=always
 RestartSec=10s
 Nice=19
+RestartPreventExitStatus=64
 
 # systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
 StartLimitInterval=0
index c0e193d6d812d1c367160aa5b25bd29dced9185e..d88dea231f408c460dc3aa23c8c8ea1e71570335 100644 (file)
@@ -19,6 +19,7 @@ ExecStart=/usr/bin/keep-web
 LimitNOFILE=65536
 Restart=always
 RestartSec=1
+RestartPreventExitStatus=64
 
 # systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
 StartLimitInterval=0
index 7d4d0926775286411b1176047913c452431f1cf6..952c7df6a1b49b00e790c1ace7b89dbe1ca908fa 100644 (file)
@@ -19,6 +19,7 @@ ExecStart=/usr/bin/keepproxy
 LimitNOFILE=65536
 Restart=always
 RestartSec=1
+RestartPreventExitStatus=64
 
 # systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
 StartLimitInterval=0
index bcfde3a7881f0c9d7a3217236d773e7845b2458c..14cad20436eb92c11eb8fef0ba2d120361bce30e 100644 (file)
@@ -23,6 +23,7 @@ ExecStart=/usr/bin/keepstore
 LimitNOFILE=65536
 Restart=always
 RestartSec=1
+RestartPreventExitStatus=64
 
 # systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
 StartLimitInterval=0
index 9625214e22ebd1c805fe0ae21b04c47e2304aece..3976b2d3cc95cf2bacb37ed649306ec48d1e8248 100644 (file)
@@ -30,12 +30,12 @@ func (getCmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, st
        flags.SetOutput(stderr)
        err = flags.Parse(args)
        if err != nil {
-               return 2
+               return cmd.EX_USAGE
        }
        if len(flags.Args()) != 1 {
                fmt.Fprintf(stderr, "usage of %s:\n", prog)
                flags.PrintDefaults()
-               return 2
+               return cmd.EX_USAGE
        }
        if opts.Short {
                opts.Format = "uuid"
index 2b08ab4822b1d0e7fbd08055db415db56642c685..332e0dcf58b12f5c4caa6a72248578e81e6094da 100644 (file)
@@ -21,6 +21,8 @@ import (
        "github.com/sirupsen/logrus"
 )
 
+const EX_USAGE = 64
+
 type Handler interface {
        RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int
 }
@@ -104,13 +106,13 @@ func (m Multi) RunCommand(prog string, args []string, stdin io.Reader, stdout, s
        } else if len(args) < 1 {
                fmt.Fprintf(stderr, "usage: %s command [args]\n", prog)
                m.Usage(stderr)
-               return 2
+               return EX_USAGE
        } else if cmd, ok = m[args[0]]; ok {
                return cmd.RunCommand(prog+" "+args[0], args[1:], stdin, stdout, stderr)
        } else {
                fmt.Fprintf(stderr, "%s: unrecognized command %q\n", prog, args[0])
                m.Usage(stderr)
-               return 2
+               return EX_USAGE
        }
 }
 
index 2d03722adcc5a31fe1d535c1d213dcdc8e82e14d..b4ce7194c1e020e35ac2bf080a8ad66b95e46f60 100644 (file)
@@ -57,7 +57,7 @@ func (s *CmdSuite) TestUsage(c *check.C) {
        stdout := bytes.NewBuffer(nil)
        stderr := bytes.NewBuffer(nil)
        exited := testCmd.RunCommand("prog", []string{"nosuchcommand", "hi"}, bytes.NewReader(nil), stdout, stderr)
-       c.Check(exited, check.Equals, 2)
+       c.Check(exited, check.Equals, 64)
        c.Check(stdout.String(), check.Equals, "")
        c.Check(stderr.String(), check.Matches, `(?ms)^prog: unrecognized command "nosuchcommand"\n.*echo.*\n`)
 }
index 707cacbf524613e007ab5a6b9bd40abb1eaf5248..d4158a21955607708df65d9afedb5194e4e4ac2f 100644 (file)
@@ -26,7 +26,8 @@ var defaultFlagSet = flag.NewFlagSet("none", flag.ContinueOnError)
 // running normally, or false if it should exit now.
 //
 // If ok is false, the second return value is an appropriate exit
-// code: 0 if "-help" was given, 2 if there was a usage error.
+// code: 0 if "-help" was given, EX_USAGE (64) if there was a usage
+// error.
 func ParseFlags(f FlagSet, prog string, args []string, positional string, stderr io.Writer) (ok bool, exitCode int) {
        f.Init(prog, flag.ContinueOnError)
        f.SetOutput(io.Discard)
@@ -35,7 +36,7 @@ func ParseFlags(f FlagSet, prog string, args []string, positional string, stderr
        case nil:
                if f.NArg() > 0 && positional == "" {
                        fmt.Fprintf(stderr, "unrecognized command line arguments: %v (try -help)\n", f.Args())
-                       return false, 2
+                       return false, EX_USAGE
                }
                return true, 0
        case flag.ErrHelp:
@@ -55,6 +56,6 @@ func ParseFlags(f FlagSet, prog string, args []string, positional string, stderr
                return false, 0
        default:
                fmt.Fprintf(stderr, "error parsing command line arguments: %s (try -help)\n", err)
-               return false, 2
+               return false, EX_USAGE
        }
 }
index 9503a54d2d7c137ec5c2e805a3aaec9b990014ce..123750e76e9fb5c01bfafa3cbfba8d33c11cad21 100644 (file)
@@ -33,7 +33,7 @@ func (s *CommandSuite) SetUpSuite(c *check.C) {
 func (s *CommandSuite) TestDump_BadArg(c *check.C) {
        var stderr bytes.Buffer
        code := DumpCommand.RunCommand("arvados config-dump", []string{"-badarg"}, bytes.NewBuffer(nil), bytes.NewBuffer(nil), &stderr)
-       c.Check(code, check.Equals, 2)
+       c.Check(code, check.Equals, cmd.EX_USAGE)
        c.Check(stderr.String(), check.Equals, "error parsing command line arguments: flag provided but not defined: -badarg (try -help)\n")
 }