diff --git a/issues/issue_258/process-compose.yaml b/issues/issue_258/process-compose.yaml index a4e94f3..53b1327 100644 --- a/issues/issue_258/process-compose.yaml +++ b/issues/issue_258/process-compose.yaml @@ -8,6 +8,7 @@ processes: postgresql: command: "exec pg_ctl start -o \"-k /home/eugene/projects/go/process-compose/issues/issue_258/.devbox/virtenv/postgresql\" && wait" is_daemon: true + launch_timeout_seconds: 2 shutdown: command: "pg_ctl stop -m fast" availability: diff --git a/src/app/process.go b/src/app/process.go index 6b87ba5..206e8ae 100644 --- a/src/app/process.go +++ b/src/app/process.go @@ -176,7 +176,7 @@ func (p *Process) run() int { func (p *Process) waitForStdOutErr() { ctx, cancel := context.WithCancel(context.Background()) if p.procConf.IsDaemon { - ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second) + ctx, cancel = context.WithTimeout(context.Background(), time.Duration(p.procConf.LaunchTimeout)*time.Second) } defer cancel() if p.stdOutDone != nil { diff --git a/src/loader/mutators.go b/src/loader/mutators.go index 99b1d00..1023719 100644 --- a/src/loader/mutators.go +++ b/src/loader/mutators.go @@ -46,6 +46,9 @@ func assignDefaultProcessValues(p *types.Project) { if proc.Replicas == 0 { proc.Replicas = 1 } + if proc.LaunchTimeout < 1 { + proc.LaunchTimeout = types.DefaultLaunchTimeout + } proc.Name = name p.Processes[name] = proc } diff --git a/src/types/process.go b/src/types/process.go index 9a5b408..b90e85d 100644 --- a/src/types/process.go +++ b/src/types/process.go @@ -14,6 +14,7 @@ import ( const DefaultNamespace = "default" const PlaceHolderValue = "-" +const DefaultLaunchTimeout = 5 type Processes map[string]ProcessConfig type Environment []string @@ -42,6 +43,7 @@ type ProcessConfig struct { IsForeground bool `yaml:"is_foreground"` IsTty bool `yaml:"is_tty"` IsElevated bool `yaml:"is_elevated"` + LaunchTimeout int `yaml:"launch_timeout_seconds"` ReplicaNum int ReplicaName string Executable string diff --git a/www/docs/launcher.md b/www/docs/launcher.md index 05a489e..f0c873a 100644 --- a/www/docs/launcher.md +++ b/www/docs/launcher.md @@ -184,6 +184,7 @@ processes: nginx: command: "docker run -d --rm --name nginx_test nginx" # note the '-d' for detached mode is_daemon: true # this flag is required for background processes (default false) + launch_timeout_seconds: 2 # default 5s shutdown: command: "docker stop nginx_test" timeout_seconds: 10 # default 10 @@ -196,6 +197,8 @@ processes: 3. Daemon processes can only be stopped with the `$PROCESSNAME.shutdown.command` as in the example above. +4. If parent process (starter) won’t close `stdout` and `stderr` within specified `launch_timeout_seconds`, (default 5 seconds) process compose will stop waiting for its log completion and start waiting for process termination. (more details are [here](https://github.com/F1bonacc1/process-compose/issues/258#issuecomment-2439544894)) + ## Foreground Processes ```yaml hl_lines="4"