Skip to content

Commit e3abb46

Browse files
committed
Signal replicator will now use the name of the process managers when notifing what signal was caught.
Processes can set a working directory. Updating the readme files.
1 parent 3b11d55 commit e3abb46

File tree

8 files changed

+47
-29
lines changed

8 files changed

+47
-29
lines changed

READMEs/ConfigrationFile.md

+8
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ processes:
7777
# skip stops this execution if required.
7878
# Use the template functions to set this value.
7979
skip: false
80+
# Run the process using this dir as the base directory.
81+
working_dir: /some/dir
8082
# init_processes start after secrets and run sequentially
8183
# This is a list and can have as many items as required.
8284
init_processes:
@@ -95,6 +97,8 @@ processes:
9597
# termination_timeout_seconds how long the grace period is for processes to terminate.
9698
# The default is 1 second.
9799
termination_timeout_seconds: 3
100+
# Run the process using this dir as the base directory.
101+
working_dir: /some/dir
98102
# logging_config is used to forward on the logs from this process.
99103
logging_config:
100104
# This section contains a Logging config _see below_
@@ -116,6 +120,10 @@ processes:
116120
- 1
117121
- -b
118122
- foo and bar
123+
# Run the process using this dir as the base directory.
124+
working_dir: /some/dir
125+
# Delay the start of a process for x number of seconds.
126+
start_delay_seconds: 60
119127
logging_config:
120128
# This section contains a Logging config _see below_
121129
```

READMEs/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Take a look around.
77

88
### Configuration files
99

10-
[Configuration Documentation](ConfigurationFile.md)
10+
[Configuration Documentation](./ConfigurationFile.md)
1111

1212
### Logging
1313

14-
[Logging Documentation](Logging.md)
14+
[Logging Documentation](./Logging.md)
1515

1616
### Secrets
1717

18-
[Secrets Documentation](Secrets.md)
18+
[Secrets Documentation](./Secrets.md)

build_and_test.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/bash
2+
set -e
3+
24
# Use "./build_and_test.sh" to run only the tests
35
# Use "./build_and_test.sh gobuild" to also rebuild the go project
46

configfile/processes.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@ type Processes struct {
1010
// Process is a struct that consumes a yaml configration and holds config for a
1111
// process that needs to be run.
1212
type Process struct {
13-
Name string `yaml:"name"`
14-
CMD string `yaml:"command"`
15-
Args []string `yaml:"arguments"`
16-
LoggerConfig LoggingConfig `yaml:"logging_config"`
17-
CombindOutput bool `yaml:"combine_output,omitempty"`
18-
TermTimeout int `yaml:"termination_timeout_seconds,omitempty"`
19-
StartDelay int `yaml:"start_delay_seconds,omitempty"`
13+
Name string `yaml:"name"`
14+
CMD string `yaml:"command"`
15+
Args []string `yaml:"arguments"`
16+
LoggerConfig LoggingConfig `yaml:"logging_config"`
17+
CombindOutput bool `yaml:"combine_output,omitempty"`
18+
TermTimeout int `yaml:"termination_timeout_seconds,omitempty"`
19+
StartDelay int `yaml:"start_delay_seconds,omitempty"`
20+
WorkingDirectory string `yaml:"working_dir,omitempty"`
2021
}
2122

2223
// SecretProcess is a struct that consumes a yaml configration and holds config for a
2324
// secret collection process that needs to be run.
2425
type SecretProcess struct {
25-
Name string `yaml:"name"`
26-
CMD string `yaml:"command"`
27-
Args []string `yaml:"arguments"`
28-
TermTimeout int `yaml:"termination_timeout_seconds,omitempty"`
29-
Skip bool `yaml:"skip"`
26+
Name string `yaml:"name"`
27+
CMD string `yaml:"command"`
28+
Args []string `yaml:"arguments"`
29+
TermTimeout int `yaml:"termination_timeout_seconds,omitempty"`
30+
Skip bool `yaml:"skip"`
31+
WorkingDirectory string `yaml:"working_dir,omitempty"`
3032
}

main.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ The error was: %s`, err)
6363
// Setup signal capture
6464
signals := make(chan os.Signal, 1)
6565
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
66-
go func() {
67-
for receivedSignal := range signals {
68-
// Signals can come from inside and outside. The signals can come from the user/deamon running the container
69-
// or it can come from a process termination. In either case we need to send the signals to the replicator
70-
// to forward it onto the running processes.
71-
signalreplicator.Send(receivedSignal)
72-
}
73-
}()
7466

7567
// Create a limited logger that will be thrown away once we fired up our actual loggers.
7668
loggers := processlogger.New(
@@ -92,6 +84,17 @@ The error was: %s`, err)
9284
terminate(1, loggers)
9385
}
9486

87+
// At this point we can start to handle signals.
88+
go func() {
89+
for receivedSignal := range signals {
90+
// Signals can come from inside and outside. The signals can come from the user/deamon running the container
91+
// or it can come from a process termination. In either case we need to send the signals to the replicator
92+
// to forward it onto the running processes.
93+
pmlogger.Printf("Got signal '%s'\n", receivedSignal)
94+
signalreplicator.Send(receivedSignal)
95+
}
96+
}()
97+
9598
// Collect secrets
9699
// This can only use the temp logger because we can't yet start the
97100
// the full loggers. Some of them will require secrets from the collection

processmanager/process.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (p *Process) processStartDelay() {
5050
// has exited either good or bad.
5151
func (p *Process) runProcess(processType string) *processEnd {
5252
finalState := &processEnd{
53-
Name: p.config.CMD,
53+
Name: p.config.Name,
5454
ProcessType: processType,
5555
ExitCode: -1,
5656
}

processmanager/processmanager.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (pm *ProcessManger) exitStatusFormatter() string {
197197
// Setup Process will link create the process object and also link the stdout and stderr.
198198
// An error is returned if anything fails.
199199
func (pm *ProcessManger) setupProcess(proc *Process) error {
200-
execProc, stdout, stderr, err := createRunableProcess(proc.config.CMD, proc.config.Args, proc.sigChan)
200+
execProc, stdout, stderr, err := createRunableProcess(proc.config, proc.sigChan)
201201
if err != nil {
202202
return err
203203
}
@@ -214,12 +214,16 @@ func (pm *ProcessManger) setupProcess(proc *Process) error {
214214
// We can use this in processes managed by the process manager or secret processes which are just
215215
// single processes.
216216
func createRunableProcess(
217-
command string,
218-
arguments []string,
217+
config *configfile.Process,
219218
signalChan chan os.Signal,
220219
) (*exec.Cmd, io.ReadCloser, io.ReadCloser, error) {
221220
signalreplicator.Register(signalChan)
222-
execProc := exec.Command(command, arguments...)
221+
execProc := exec.Command(config.CMD, config.Args...)
222+
223+
// If we have a working dir. Set it here.
224+
if config.WorkingDirectory != "" {
225+
execProc.Dir = config.WorkingDirectory
226+
}
223227

224228
stdout, err := execProc.StdoutPipe()
225229
if err != nil {

signalreplicator/signal.go

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func Remove(ch chan os.Signal) {
3030

3131
// Send will take a signal that needs to be replicated
3232
func Send(s os.Signal) {
33-
fmt.Println("got signal", s)
3433
globalReplicator.input <- s
3534
}
3635

0 commit comments

Comments
 (0)