feat(system): add MaskUnit to systemd
This commit is contained in:
parent
85a473d972
commit
c3f17bd07b
@ -165,3 +165,11 @@ func MachineID(root string) string {
|
||||
|
||||
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)
|
||||
}
|
||||
|
@ -123,3 +123,22 @@ func TestMachineID(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user