61
62
type systemdDependencyLoop struct{}
63
64
func (systemdDependencyLoop) set(c *check.C) {
64
installService(c, "deadlock", deadlockService, BaseAltPartitionPath)
65
installService(c, "emerg-reboot", rebootService, BaseAltPartitionPath)
65
installService(c, "deadlock", deadlockService, common.BaseAltPartitionPath)
66
installService(c, "emerg-reboot", rebootService, common.BaseAltPartitionPath)
68
69
func (systemdDependencyLoop) unset(c *check.C) {
69
unInstallService(c, "deadlock", BaseAltPartitionPath)
70
unInstallService(c, "emerg-reboot", BaseAltPartitionPath)
70
unInstallService(c, "deadlock", common.BaseAltPartitionPath)
71
unInstallService(c, "emerg-reboot", common.BaseAltPartitionPath)
73
74
func installService(c *check.C, serviceName, serviceCfg, basePath string) {
74
MakeWritable(c, basePath)
75
defer MakeReadonly(c, basePath)
75
common.MakeWritable(c, basePath)
76
defer common.MakeReadonly(c, basePath)
77
78
// Create service file
78
79
serviceFile := fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName)
79
ExecCommand(c, "sudo", "chmod", "a+w", fmt.Sprintf("%s%s", basePath, baseSystemdPath))
80
ExecCommandToFile(c, serviceFile, "sudo", "echo", serviceCfg)
80
cli.ExecCommand(c, "sudo", "chmod", "a+w", fmt.Sprintf("%s%s", basePath, baseSystemdPath))
81
cli.ExecCommandToFile(c, serviceFile, "sudo", "echo", serviceCfg)
82
83
// Create requires directory
83
84
requiresDirPart := fmt.Sprintf("%s/%s", baseSystemdPath, systemdTargetRequiresDir)
84
85
requiresDir := fmt.Sprintf("%s%s", basePath, requiresDirPart)
85
ExecCommand(c, "sudo", "mkdir", "-p", requiresDir)
86
cli.ExecCommand(c, "sudo", "mkdir", "-p", requiresDir)
87
88
// Symlink from the requires dir to the service file (with chroot for being
88
89
// usable in the other partition)
89
ExecCommand(c, "sudo", "chroot", basePath, "ln", "-s",
90
cli.ExecCommand(c, "sudo", "chroot", basePath, "ln", "-s",
90
91
fmt.Sprintf("%s/%s.service", baseSystemdPath, serviceName),
91
92
fmt.Sprintf("%s/%s.service", requiresDirPart, serviceName),
95
96
func unInstallService(c *check.C, serviceName, basePath string) {
96
MakeWritable(c, basePath)
97
defer MakeReadonly(c, basePath)
97
common.MakeWritable(c, basePath)
98
defer common.MakeReadonly(c, basePath)
99
100
// Disable the service
100
ExecCommand(c, "sudo", "chroot", basePath,
101
cli.ExecCommand(c, "sudo", "chroot", basePath,
101
102
"systemctl", "disable", fmt.Sprintf("%s.service", serviceName))
103
104
// Remove the service file
104
ExecCommand(c, "sudo", "rm",
105
cli.ExecCommand(c, "sudo", "rm",
105
106
fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName))
107
108
// Remove the requires symlink
108
ExecCommand(c, "sudo", "rm",
109
cli.ExecCommand(c, "sudo", "rm",
109
110
fmt.Sprintf("%s%s/%s/%s.service", basePath, baseSystemdPath, systemdTargetRequiresDir, serviceName))