diff --git a/main.go b/main.go index 0a5fadd..dc85f73 100644 --- a/main.go +++ b/main.go @@ -61,6 +61,7 @@ func setupStartCmd() cli.Command { cli.BoolFlag{Name: "daemonize, D", EnvVar: "OVERMIND_DAEMONIZE", Usage: "Launch Overmind as a daemon. Use 'overmind echo' to view logs and 'overmind quit' to gracefully quit daemonized instance", Destination: &c.Daemonize}, cli.StringFlag{Name: "tmux-config, F", EnvVar: "OVERMIND_TMUX_CONFIG", Usage: "Specify an alternative tmux config path to be used by Overmind", Destination: &c.TmuxConfigPath}, cli.StringFlag{Name: "ignored-processes, x", EnvVar: "OVERMIND_IGNORED_PROCESSES", Usage: "Specify process names to prevent from launching. Useful if you want to run all but one or two processes. Divide names with comma. Takes precedence over the 'processes' flag.", Destination: &c.IgnoredProcNames}, + cli.StringFlag{Name: "delayed-processes, X", EnvVar: "OVERMIND_DELAYED_PROCESSES", Usage: "Specify process names to prevent from launching right now. Useful if you want to run one or two processes later. Divide names with comma. Takes precedence over the 'processes' flag.", Destination: &c.DelayedProcNames}, cli.StringFlag{Name: "shell, H", EnvVar: "OVERMIND_SHELL", Usage: "Specify shell to run processes with.", Value: "sh", Destination: &c.Shell}, }, socketFlags(&c.SocketPath, &c.Network)..., diff --git a/start/command.go b/start/command.go index 57ab26b..45c7b4e 100644 --- a/start/command.go +++ b/start/command.go @@ -68,6 +68,7 @@ func newCommand(h *Handler) (*command, error) { procNames := utils.SplitAndTrim(h.ProcNames) ignoredProcNames := utils.SplitAndTrim(h.IgnoredProcNames) + delayedProcNames := utils.SplitAndTrim(h.DelayedProcNames) colors := defaultColors if len(h.Colors) > 0 { @@ -80,9 +81,18 @@ func newCommand(h *Handler) (*command, error) { c.scriptDir = filepath.Join(os.TempDir(), instanceID) os.MkdirAll(c.scriptDir, 0700) + delayedScriptFilePath := c.createScriptFile(&procfileEntry{ + Name: "delayed", + OrigName: "delayed", + Command: ":", + Port: 0, + StopSignal: syscall.SIGINT, + }, h.Shell, !h.NoPort) + for i, e := range pf { shouldRun := len(procNames) == 0 || utils.StringsContain(procNames, e.OrigName) isIgnored := len(ignoredProcNames) != 0 && utils.StringsContain(ignoredProcNames, e.OrigName) + isDelayed := len(delayedProcNames) != 0 && utils.StringsContain(delayedProcNames, e.OrigName) if shouldRun && !isIgnored { scriptFilePath := c.createScriptFile(&e, h.Shell, !h.NoPort) @@ -92,8 +102,10 @@ func newCommand(h *Handler) (*command, error) { e.Name, colors[i%len(colors)], scriptFilePath, + delayedScriptFilePath, c.output, - (h.AnyCanDie || utils.StringsContain(canDie, e.OrigName)), + isDelayed, + (h.AnyCanDie || utils.StringsContain(canDie, e.OrigName) || isDelayed), (utils.StringsContain(autoRestart, e.OrigName) || utils.StringsContain(autoRestart, "all")), e.StopSignal, )) diff --git a/start/handler.go b/start/handler.go index 4244519..d5242c8 100644 --- a/start/handler.go +++ b/start/handler.go @@ -35,6 +35,7 @@ type Handler struct { PortBase, PortStep int ProcNames string IgnoredProcNames string + DelayedProcNames string SocketPath string Network string CanDie string diff --git a/start/process.go b/start/process.go index 358bed5..bca9cff 100644 --- a/start/process.go +++ b/start/process.go @@ -19,6 +19,7 @@ type process struct { pid int stopSignal syscall.Signal + delayed bool canDie bool canDieNow bool autoRestart bool @@ -32,12 +33,13 @@ type process struct { in io.Writer out io.ReadCloser - Name string - Color int - Command string + Name string + Color int + Command string + DelayedCommand string } -func newProcess(tmux *tmuxClient, name string, color int, command string, output *multiOutput, canDie bool, autoRestart bool, stopSignal syscall.Signal) *process { +func newProcess(tmux *tmuxClient, name string, color int, command string, delayedCommand string, output *multiOutput, delayed bool, canDie bool, autoRestart bool, stopSignal syscall.Signal) *process { out, in := io.Pipe() proc := &process{ @@ -45,6 +47,7 @@ func newProcess(tmux *tmuxClient, name string, color int, command string, output tmux: tmux, stopSignal: stopSignal, + delayed: delayed, canDie: canDie, canDieNow: canDie, autoRestart: autoRestart, @@ -52,9 +55,10 @@ func newProcess(tmux *tmuxClient, name string, color int, command string, output in: in, out: out, - Name: name, - Color: color, - Command: command, + Name: name, + Color: color, + Command: command, + DelayedCommand: delayedCommand, } tmux.AddProcess(proc) diff --git a/start/tmux.go b/start/tmux.go index 55b37c9..28d9f94 100644 --- a/start/tmux.go +++ b/start/tmux.go @@ -79,10 +79,17 @@ func (t *tmuxClient) Start() error { for _, p := range t.processes { tmuxPaneMsg := fmt.Sprintf(tmuxPaneMsgFmt, p.Name) + var command string + if p.delayed { + command = p.DelayedCommand + } else { + command = p.Command + } + if first { first = false - args = append(args, "new", "-n", p.Name, "-s", t.Session, "-P", "-F", tmuxPaneMsg, p.Command, ";") + args = append(args, "new", "-n", p.Name, "-s", t.Session, "-P", "-F", tmuxPaneMsg, command, ";") if w, h, err := term.GetSize(int(os.Stdin.Fd())); err == nil { if w > t.outputOffset { @@ -95,7 +102,7 @@ func (t *tmuxClient) Start() error { args = append(args, "setw", "-g", "remain-on-exit", "on", ";") args = append(args, "setw", "-g", "allow-rename", "off", ";") } else { - args = append(args, "neww", "-n", p.Name, "-P", "-F", tmuxPaneMsg, p.Command, ";") + args = append(args, "neww", "-n", p.Name, "-P", "-F", tmuxPaneMsg, command, ";") } }