package op

// SystemdUp 启动服务
func SystemdUp(serviceName string) (bool, []string) {
	ok, resultLog := SingleLineCommandExecutor([]string{"systemctl", "enable", serviceName})
	if !ok {
		return false, resultLog
	}
	ok, resultLog = SingleLineCommandExecutor([]string{"systemctl", "start", serviceName})
	if !ok {
		return false, resultLog
	}
	return true, resultLog
}

// SystemdDown 停止服务
func SystemdDown(serviceName string) (bool, []string) {
	ok, resultLog := SingleLineCommandExecutor([]string{"systemctl", "disable", serviceName})
	if !ok {
		return false, resultLog
	}
	ok, resultLog = SingleLineCommandExecutor([]string{"systemctl", "stop", serviceName})
	if !ok {
		return false, resultLog
	}
	return true, resultLog
}

// SystemdStatus 查看服务状态
func SystemdStatus(serviceName string) (bool, []string) {
	ok, resultLog := SingleLineCommandExecutor([]string{"systemctl", "status", serviceName})
	if !ok {
		return false, resultLog
	}
	return true, resultLog
}

// SystemdRestart 重启服务
func SystemdRestart(serviceName string) (bool, []string) {
	ok, resultLog := SingleLineCommandExecutor([]string{"systemctl", "restart", serviceName})
	if !ok {
		return false, resultLog
	}
	return true, resultLog
}

// SystemdReload 重新加载服务
func SystemdReload(serviceName string) (bool, []string) {
	ok, resultLog := SingleLineCommandExecutor([]string{"systemctl", "reload", serviceName})
	if !ok {
		return false, resultLog
	}
	return true, resultLog
}

// SystemdEnable 启用服务
func SystemdEnable(serviceName string) (bool, []string) {
	ok, resultLog := SingleLineCommandExecutor([]string{"systemctl", "enable", serviceName})
	if !ok {
		return false, resultLog
	}
	return true, resultLog
}

// SystemdDisable 禁用服务
func SystemdDisable(serviceName string) (bool, []string) {
	ok, resultLog := SingleLineCommandExecutor([]string{"systemctl", "disable", serviceName})
	if !ok {
		return false, resultLog
	}
	return true, resultLog
}

// SystemdDaemonReload 重新加载服务
func SystemdDaemonReload() (bool, []string) {
	ok, resultLog := SingleLineCommandExecutor([]string{"systemctl", "daemon-reload"})
	if !ok {
		return false, resultLog
	}
	return true, resultLog
}

func SystemIsRunning(serviceName string) (bool, []string) {
	ok, resultLog := SingleLineCommandExecutor([]string{"systemctl", "is-active", serviceName})
	if !ok {
		return false, resultLog
	}
	return true, resultLog
}
