Skip to content

Commit

Permalink
feat #258: Added configurable daemon launch timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Nov 9, 2024
1 parent b34afe4 commit dd2cb88
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions issues/issue_258/process-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/app/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/loader/mutators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

const DefaultNamespace = "default"
const PlaceHolderValue = "-"
const DefaultLaunchTimeout = 5

type Processes map[string]ProcessConfig
type Environment []string
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions www/docs/launcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down

0 comments on commit dd2cb88

Please sign in to comment.