feat: script and exec runtimes with configurable shell
Add runtime: script (shell file, default /bin/bash, optional stop_script) and runtime: exec (executable with args, optional stop_executable). Both support service_type simple|oneshot and working_dir.
This commit is contained in:
@@ -21,6 +21,14 @@ const (
|
||||
KindStack = "stack"
|
||||
)
|
||||
|
||||
// Runtimes for units that are not containers.
|
||||
const (
|
||||
RuntimeScript = "script" // run a shell script
|
||||
RuntimeExec = "exec" // run an executable directly
|
||||
|
||||
DefaultShell = "/bin/bash"
|
||||
)
|
||||
|
||||
// Unit represents a single managed container unit.
|
||||
type Unit struct {
|
||||
Name string `yaml:"name"`
|
||||
@@ -41,11 +49,38 @@ type Unit struct {
|
||||
WorkingDir string `yaml:"working_dir,omitempty"` // compose project directory
|
||||
ComposeFiles []string `yaml:"compose_files,omitempty"` // relative to working_dir unless absolute
|
||||
ComposeBin string `yaml:"compose_bin,omitempty"` // path to podman-compose
|
||||
|
||||
// Script fields (runtime: script) — run a shell file as a service.
|
||||
Script string `yaml:"script,omitempty"` // path to script run as ExecStart
|
||||
StopScript string `yaml:"stop_script,omitempty"` // optional script run as ExecStop
|
||||
Shell string `yaml:"shell,omitempty"` // interpreter, default /bin/bash
|
||||
|
||||
// Executable fields (runtime: exec) — run a binary directly.
|
||||
Executable string `yaml:"executable,omitempty"` // path to binary run as ExecStart
|
||||
Args []string `yaml:"args,omitempty"` // arguments for executable
|
||||
StopExecutable string `yaml:"stop_executable,omitempty"` // optional binary run as ExecStop
|
||||
|
||||
// Script and exec units: simple (default) | oneshot. WorkingDir is also used.
|
||||
ServiceType string `yaml:"service_type,omitempty"`
|
||||
}
|
||||
|
||||
// IsStack reports whether the unit manages a compose stack.
|
||||
func (u Unit) IsStack() bool { return u.Kind == KindStack }
|
||||
|
||||
// IsScript reports whether the unit runs a shell script.
|
||||
func (u Unit) IsScript() bool { return u.Runtime == RuntimeScript }
|
||||
|
||||
// IsExec reports whether the unit runs an executable directly.
|
||||
func (u Unit) IsExec() bool { return u.Runtime == RuntimeExec }
|
||||
|
||||
// ShellPath returns the configured interpreter, or the default.
|
||||
func (u Unit) ShellPath() string {
|
||||
if u.Shell == "" {
|
||||
return DefaultShell
|
||||
}
|
||||
return u.Shell
|
||||
}
|
||||
|
||||
// Config is the root config structure.
|
||||
type Config struct {
|
||||
Units []Unit `yaml:"units"`
|
||||
|
||||
Reference in New Issue
Block a user