feat(script): Persist transient unit name to disk
This commit is contained in:
parent
6ae122f959
commit
c805e2b371
@ -20,7 +20,7 @@ func StartUnit(name string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func ExecuteScript(scriptPath string) error {
|
||||
func ExecuteScript(scriptPath string) (string, error) {
|
||||
props := []dbus.Property{
|
||||
dbus.PropDescription("Unit generated and executed by coreos-cloudinit on behalf of user"),
|
||||
dbus.PropExecStart([]string{"/bin/bash", scriptPath}, false),
|
||||
@ -33,9 +33,9 @@ func ExecuteScript(scriptPath string) error {
|
||||
|
||||
conn, err := dbus.New()
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
|
||||
_, err = conn.StartTransientUnit(name, "replace", props...)
|
||||
return err
|
||||
return name, err
|
||||
}
|
||||
|
@ -59,3 +59,8 @@ func PersistScriptInWorkspace(script Script, workspace string) (string, error) {
|
||||
|
||||
return f.Name(), nil
|
||||
}
|
||||
|
||||
func PersistScriptUnitNameInWorkspace(name string, workspace string) error {
|
||||
unitPath := path.Join(workspace, "scripts", "unit-name")
|
||||
return ioutil.WriteFile(unitPath, []byte(name), 644)
|
||||
}
|
||||
|
@ -75,7 +75,9 @@ func main() {
|
||||
var path string
|
||||
path, err = cloudinit.PersistScriptInWorkspace(t, workspace)
|
||||
if err == nil {
|
||||
err = cloudinit.ExecuteScript(path)
|
||||
var name string
|
||||
name, err = cloudinit.ExecuteScript(path)
|
||||
cloudinit.PersistScriptUnitNameInWorkspace(name, workspace)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user