serve restic: don't serve via http if serving via --stdio

Before this change, we started the http listener even if --stdio was
supplied.

This also moves the log message so the user won't see the serving via
HTTP message unless they are really using that.

Fixes 
This commit is contained in:
Nick Craig-Wood 2022-12-22 16:02:17 +00:00
parent 448fff9a04
commit 823d89af9a
1 changed files with 5 additions and 1 deletions
cmd/serve/restic

View File

@ -155,7 +155,6 @@ with a path of ` + "`/<username>/`" + `.
if err != nil { if err != nil {
return err return err
} }
fs.Logf(s.f, "Serving restic REST API on %s", s.URLs())
if s.opt.Stdio { if s.opt.Stdio {
if terminal.IsTerminal(int(os.Stdout.Fd())) { if terminal.IsTerminal(int(os.Stdout.Fd())) {
return errors.New("refusing to run HTTP2 server directly on a terminal, please let restic start rclone") return errors.New("refusing to run HTTP2 server directly on a terminal, please let restic start rclone")
@ -173,6 +172,7 @@ with a path of ` + "`/<username>/`" + `.
httpSrv.ServeConn(conn, opts) httpSrv.ServeConn(conn, opts)
return nil return nil
} }
fs.Logf(s.f, "Serving restic REST API on %s", s.URLs())
s.Wait() s.Wait()
return nil return nil
}) })
@ -242,6 +242,10 @@ func newServer(ctx context.Context, f fs.Fs, opt *Options) (s *server, err error
cache: newCache(opt.CacheObjects), cache: newCache(opt.CacheObjects),
opt: *opt, opt: *opt,
} }
// Don't bind any HTTP listeners if running with --stdio
if opt.Stdio {
opt.HTTP.ListenAddr = nil
}
s.Server, err = libhttp.NewServer(ctx, s.Server, err = libhttp.NewServer(ctx,
libhttp.WithConfig(opt.HTTP), libhttp.WithConfig(opt.HTTP),
libhttp.WithAuth(opt.Auth), libhttp.WithAuth(opt.Auth),