Skip to content

Commit

Permalink
feat: add ascii-banners on long-running processes to help debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jul 16, 2020
1 parent f23ebc4 commit 452c508
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ require (
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200506231410-2ff61e1afc86
honnef.co/go/tools v0.0.1-2020.1.4 // indirect
moul.io/banner v1.0.1
moul.io/godev v1.6.0
moul.io/motd v1.0.0
moul.io/roundtripper v1.0.0
moul.io/srand v1.4.0
moul.io/zapgorm v1.0.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions go/cmd/pathwar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/oauth2"
"moul.io/banner"
"moul.io/godev"
"moul.io/motd"
"moul.io/srand"
"pathwar.land/pathwar/v2/go/pkg/errcode"
"pathwar.land/pathwar/v2/go/pkg/pwagent"
Expand Down Expand Up @@ -257,6 +259,9 @@ func main() {
FlagSet: serverFlags,
Options: []ff.Option{ff.WithEnvVarNoPrefix()},
Exec: func(args []string) error {
fmt.Println(motd.Default())
fmt.Println(banner.Inline("api server"))

err := globalPreRun()
if err != nil {
return err
Expand Down Expand Up @@ -824,6 +829,10 @@ func main() {
if err := globalPreRun(); err != nil {
return err
}

fmt.Println(motd.Default())
fmt.Println(banner.Inline("agent"))

cleanup, err := initSentryFromEnv("starting agent")
if err != nil {
return err
Expand Down
14 changes: 12 additions & 2 deletions go/cmd/pwinit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"syscall"

"github.com/peterbourgon/ff/ffcli"
"moul.io/banner"
"pathwar.land/pathwar/v2/go/pkg/errcode"
"pathwar.land/pathwar/v2/go/pkg/pwinit"
)
Expand All @@ -26,6 +27,12 @@ func main() {
Exec: func(args []string) error {
// FIXME: lock to block other commands

if len(args) < 1 {
return flag.ErrHelp
}

fmt.Println(banner.Inline("pwinit"))

_, err := os.Stat("/pwinit/config.json")
if err != nil {
log.Printf("no such config file, skipping on-init hook (%v)", err)
Expand Down Expand Up @@ -117,11 +124,14 @@ func main() {
Usage: "pwinit <subcommand> [flags] [args...]",
LongHelp: "More info here: https://github.com/pathwar/pathwar/wiki/CLI#pwinit",
Subcommands: []*ffcli.Command{entrypoint, env, config, passphrase},
Exec: func([]string) error { return flag.ErrHelp },
Exec: func([]string) error {
fmt.Println(banner.Inline("pwinit"))
return flag.ErrHelp
},
}

args := os.Args[1:]
if args[0] == "entrypoint" && len(args) > 1 && args[1] != "--" {
if len(args) > 0 && args[0] == "entrypoint" && len(args) > 1 && args[1] != "--" {
args = append([]string{"entrypoint", "--"}, args[1:]...)
}
if err := root.Run(args); err != nil {
Expand Down

0 comments on commit 452c508

Please sign in to comment.