feat(system): add MaskUnit to systemd

This commit is contained in:
Brandon Philips 2014-05-06 16:18:36 -07:00
parent 85a473d972
commit c3f17bd07b
2 changed files with 27 additions and 0 deletions

View File

@ -165,3 +165,11 @@ func MachineID(root string) string {
return id return id
} }
func MaskUnit(unit string, root string) error {
masked := path.Join(root, "etc", "systemd", "system", unit)
if err := os.MkdirAll(path.Dir(masked), os.FileMode(0755)); err != nil {
return err
}
return os.Symlink("/dev/null", masked)
}

View File

@ -123,3 +123,22 @@ func TestMachineID(t *testing.T) {
t.Fatalf("File has incorrect contents") t.Fatalf("File has incorrect contents")
} }
} }
func TestMaskUnit(t *testing.T) {
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
if err != nil {
t.Fatalf("Unable to create tempdir: %v", err)
}
defer os.RemoveAll(dir)
if err := MaskUnit("foo.service", dir); err != nil {
t.Fatalf("Unable to mask unit: %v", err)
}
fullPath := path.Join(dir, "etc", "systemd", "system", "foo.service")
target, err := os.Readlink(fullPath)
if err != nil {
t.Fatalf("Unable to read link", err)
}
if target != "/dev/null" {
t.Fatalf("unit not masked, got unit target", target)
}
}