From c21593656efaa34cdf934749460effc9c1a09c66 Mon Sep 17 00:00:00 2001 From: liby71 Date: Thu, 16 Mar 2023 10:20:50 +0800 Subject: [PATCH 1/4] add starting delay when proc start --- .gitignore | 7 ++++--- main.go | 3 +++ proc.go | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 808f7d7..e5ebfae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -/goreman -/goxz -*.exe + +.idea +.git +.cover diff --git a/main.go b/main.go index f1f398e..117a563 100644 --- a/main.go +++ b/main.go @@ -98,6 +98,9 @@ var exitOnStop = flag.Bool("exit-on-stop", true, "Exit goreman if all subprocess // show timestamp in log var logTime = flag.Bool("logtime", true, "show timestamp in log") +// start proc interval (sec) +var interval = flag.Uint("interval", 0, "start proc interval (sec)") + var maxProcNameLength = 0 var re = regexp.MustCompile(`\$([a-zA-Z]+[a-zA-Z0-9_]+)`) diff --git a/proc.go b/proc.go index 01b4c70..bd6d941 100644 --- a/proc.go +++ b/proc.go @@ -142,6 +142,11 @@ func startProcs(sc <-chan os.Signal, rpcCh <-chan *rpcMessage, exitOnError bool) for _, proc := range procs { startProc(proc.name, &wg, errCh) + // sleep N sec. because sometimes, dependencies checking between stateful services (procs) + // will let it starting fail . + if *interval > 0 { + time.Sleep(time.Second * time.Duration(*interval)) + } } allProcsDone := make(chan struct{}, 1) From 451c9b05d01f8c3a1f6887a332547bfa177fd8e8 Mon Sep 17 00:00:00 2001 From: liby71 Date: Thu, 16 Mar 2023 19:15:11 +0800 Subject: [PATCH 2/4] reverse procs sort when stopProc --- main.go | 5 ++++- proc.go | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 117a563..b5323b2 100644 --- a/main.go +++ b/main.go @@ -99,7 +99,10 @@ var exitOnStop = flag.Bool("exit-on-stop", true, "Exit goreman if all subprocess var logTime = flag.Bool("logtime", true, "show timestamp in log") // start proc interval (sec) -var interval = flag.Uint("interval", 0, "start proc interval (sec)") +var interval = flag.Uint("interval", 0, "show timestamp in log") + +// reverse procs sort when stop +var reverseOnStop = flag.Bool("reverse-on-stop", false, "reverse procs sort when stop") var maxProcNameLength = 0 diff --git a/proc.go b/proc.go index bd6d941..5781d2a 100644 --- a/proc.go +++ b/proc.go @@ -126,11 +126,23 @@ func restartProc(name string) error { // opportunity to stop. func stopProcs(sig os.Signal) error { var err error + // reverse procs sort when stop + if *reverseOnStop { + tmp := make([]*procInfo, len(procs)) + for i := 0; i < len(procs); i++ { + tmp[i] = procs[(len(procs)-1)-i] + } + procs = tmp + } + for _, proc := range procs { stopErr := stopProc(proc.name, sig) if stopErr != nil { err = stopErr } + if *interval > 0 { + time.Sleep(time.Second * time.Duration(*interval)) + } } return err } From f86c80d662e4a212c32740be50c51608a91c911c Mon Sep 17 00:00:00 2001 From: liby71 Date: Fri, 17 Mar 2023 09:37:47 +0800 Subject: [PATCH 3/4] fix: can't change rpc port when RUN rpc method --- log.go | 8 +++++--- main.go | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/log.go b/log.go index 456b249..d357aa7 100644 --- a/log.go +++ b/log.go @@ -20,12 +20,14 @@ type clogger struct { } var colors = []int{ + //30, // break + 31, // red 32, // green - 36, // cyan - 35, // magenta 33, // yellow 34, // blue - 31, // red + 35, // magenta + 36, // cyan + 37, // write txt, break ground } var mutex = new(sync.Mutex) diff --git a/main.go b/main.go index b5323b2..c760ce8 100644 --- a/main.go +++ b/main.go @@ -186,7 +186,10 @@ func defaultServer(serverPort uint) string { if s, ok := os.LookupEnv("GOREMAN_RPC_SERVER"); ok { return s } - return fmt.Sprintf("127.0.0.1:%d", defaultPort()) + if serverPort == 0 { + serverPort = defaultPort() + } + return fmt.Sprintf("127.0.0.1:%d", serverPort) } func defaultAddr() string { From 4cb6ee44fd585062c19b4500ed7cf2920a4af401 Mon Sep 17 00:00:00 2001 From: liby71 Date: Fri, 17 Mar 2023 10:49:16 +0800 Subject: [PATCH 4/4] update --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e5ebfae..9d1c772 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ - +/goreman +/goxz +*.exe .idea .git .cover