Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add starting delay when proc start #137

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/goreman
/goxz
*.exe
.idea
.git
.cover
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change requied?

8 changes: 5 additions & 3 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ 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, "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

var re = regexp.MustCompile(`\$([a-zA-Z]+[a-zA-Z0-9_]+)`)
Expand Down Expand Up @@ -180,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 {
Expand Down
17 changes: 17 additions & 0 deletions proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -142,6 +154,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)
Expand Down