From c805e2b371320ceefaf8c9322edd51cb5d964635 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 4 Mar 2014 21:02:20 -0800 Subject: [PATCH] feat(script): Persist transient unit name to disk --- cloudinit/systemd.go | 6 +++--- cloudinit/workspace.go | 5 +++++ coreos-cloudinit.go | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cloudinit/systemd.go b/cloudinit/systemd.go index e7c5f7e..4185e39 100644 --- a/cloudinit/systemd.go +++ b/cloudinit/systemd.go @@ -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 } diff --git a/cloudinit/workspace.go b/cloudinit/workspace.go index c531439..c63d8c0 100644 --- a/cloudinit/workspace.go +++ b/cloudinit/workspace.go @@ -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) +} diff --git a/coreos-cloudinit.go b/coreos-cloudinit.go index 9c73d30..a986aef 100644 --- a/coreos-cloudinit.go +++ b/coreos-cloudinit.go @@ -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) } }