You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
// Package pmuxlib implements the process management aspects of the pmux
|
|
// process.
|
|
package pmuxlib
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"sync"
|
|
)
|
|
|
|
type Config struct {
|
|
TimeFormat string `yaml:"timeFormat"`
|
|
Processes []ProcessConfig `yaml:"processes"`
|
|
}
|
|
|
|
// Run runs the given configuration as if this was a real pmux process.
|
|
func Run(ctx context.Context, cfg Config) {
|
|
|
|
stdoutLogger := newLogger(os.Stdout, logSepStdout, cfg.TimeFormat)
|
|
defer stdoutLogger.Close()
|
|
|
|
stderrLogger := newLogger(os.Stderr, logSepStderr, cfg.TimeFormat)
|
|
defer stderrLogger.Close()
|
|
|
|
sysLogger := stderrLogger.withSep(logSepSys)
|
|
defer sysLogger.Println("exited gracefully, ciao!")
|
|
|
|
var wg sync.WaitGroup
|
|
defer wg.Wait()
|
|
|
|
for _, cfgProc := range cfg.Processes {
|
|
wg.Add(1)
|
|
go func(procCfg ProcessConfig) {
|
|
defer wg.Done()
|
|
|
|
stdoutLogger := stdoutLogger.withPName(procCfg.Name)
|
|
stderrLogger := stderrLogger.withPName(procCfg.Name)
|
|
sysLogger := sysLogger.withPName(procCfg.Name)
|
|
|
|
sysLogger.Println("starting process")
|
|
defer sysLogger.Println("stopped process handler")
|
|
|
|
RunProcess(
|
|
ctx, stdoutLogger, stderrLogger, sysLogger, procCfg,
|
|
)
|
|
|
|
}(cfgProc)
|
|
}
|
|
}
|
|
|