feat(script): Persist transient unit name to disk

This commit is contained in:
Brian Waldon 2014-03-04 21:02:20 -08:00
parent 6ae122f959
commit c805e2b371
3 changed files with 11 additions and 4 deletions

View File

@ -20,7 +20,7 @@ func StartUnit(name string) error {
return err return err
} }
func ExecuteScript(scriptPath string) error { func ExecuteScript(scriptPath string) (string, error) {
props := []dbus.Property{ props := []dbus.Property{
dbus.PropDescription("Unit generated and executed by coreos-cloudinit on behalf of user"), dbus.PropDescription("Unit generated and executed by coreos-cloudinit on behalf of user"),
dbus.PropExecStart([]string{"/bin/bash", scriptPath}, false), dbus.PropExecStart([]string{"/bin/bash", scriptPath}, false),
@ -33,9 +33,9 @@ func ExecuteScript(scriptPath string) error {
conn, err := dbus.New() conn, err := dbus.New()
if err != nil { if err != nil {
return err return "", err
} }
_, err = conn.StartTransientUnit(name, "replace", props...) _, err = conn.StartTransientUnit(name, "replace", props...)
return err return name, err
} }

View File

@ -59,3 +59,8 @@ func PersistScriptInWorkspace(script Script, workspace string) (string, error) {
return f.Name(), nil 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)
}

View File

@ -75,7 +75,9 @@ func main() {
var path string var path string
path, err = cloudinit.PersistScriptInWorkspace(t, workspace) path, err = cloudinit.PersistScriptInWorkspace(t, workspace)
if err == nil { if err == nil {
err = cloudinit.ExecuteScript(path) var name string
name, err = cloudinit.ExecuteScript(path)
cloudinit.PersistScriptUnitNameInWorkspace(name, workspace)
} }
} }