Skip to content

Commit

Permalink
Add custom process environment (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkmw authored Jul 21, 2020
1 parent d797359 commit 03f8ce6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ job "foo" {
}
```
You can append a custom environment to the process by setting `env`:
```hcl
job "foo" {
command = "/usr/local/bin/foo"
args = ["bar"]
env = ["ENABLED=1", "BAR=\"BAZ\""]
maxAttempts = 3
canFail = false
}
```
You can configure a Job to watch files and to send a signal to the managed process if that file changes. This can be used, for example, to send a `SIGHUP` to a process to reload its configuration file when it changes.
```hcl
Expand Down
1 change: 1 addition & 0 deletions internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type JobConfig struct {
Name string `hcl:",key"`
Command string `hcl:"command"`
Args []string `hcl:"args"`
Env []string `hcl:"env"`
Watches []Watch `hcl:"watch"`
MaxAttempts_ int `hcl:"max_attempts"` // deprecated
MaxAttempts int `hcl:"maxAttempts"`
Expand Down
6 changes: 5 additions & 1 deletion pkg/proc/job_lazy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package proc
import (
"context"
"fmt"
log "github.com/sirupsen/logrus"
"os"
"os/exec"

log "github.com/sirupsen/logrus"
)

func (job *Job) CanStartLazily() bool {
Expand Down Expand Up @@ -64,6 +65,9 @@ func (job *Job) start(ctx context.Context, process chan<- *os.Process) error {
job.cmd = exec.CommandContext(ctx, job.Config.Command, job.Config.Args...)
job.cmd.Stdout = os.Stdout
job.cmd.Stderr = os.Stderr
if job.Config.Env != nil {
job.cmd.Env = append(os.Environ(), job.Config.Env...)
}

for { // restart failed jobs as long mittnite is running
l.Info("starting job")
Expand Down

0 comments on commit 03f8ce6

Please sign in to comment.