Install service only when it still does not exist

This commit is contained in:
Filiberto Fuentes 2023-12-14 17:38:05 +00:00
Родитель 566e2e6dab
Коммит 663e7feb89
3 изменённых файлов: 14 добавлений и 5 удалений

Просмотреть файл

@ -229,13 +229,22 @@ func enable(ctx *log.Context, h HandlerEnvironment, report *RunCommandInstanceVi
// If installService == true, then install RunCommand as a service
if cfg.installAsService() {
serviceWasInstalled, err1 := InstallRunCommandService(ctx)
serviceExists, err1 := RunCommandServiceIsInstalled(ctx)
if err1 != nil {
return "", "", errors.Wrap(err1, "failed to install RunCommand as a service"), ExitCode_InstallServiceFailed
ctx.Log("event",
fmt.Sprintf("could not check if service is already installed. Proceeding to overwrite configuration file to make sure it is installed. %v"),
errors.Wrap(err1, "failed to check if service was previously installed"))
}
if serviceWasInstalled {
ctx.Log("message", "RunCommand service successfully installed")
if serviceExists == false {
serviceWasInstalled, err2 := InstallRunCommandService(ctx)
if err2 != nil {
return "", "", errors.Wrap(err2, "failed to install RunCommand as a service"), ExitCode_InstallServiceFailed
}
if serviceWasInstalled {
ctx.Log("event", "RunCommand service successfully installed")
}
}
}

Двоичные данные
main/run-command-handler

Двоичный файл не отображается.

Просмотреть файл

@ -128,7 +128,7 @@ func createOrUpdateRunCommandService(ctx *log.Context) (bool, error) {
// Starts the RunCommand service by invoking 'systemctl start'
func startService(ctx *log.Context) (bool, error) {
ctx.Log("event", "Trying to start run command service")
output, err := exec.Command("systemctl", "start", systemdServiceName).Output()
_, err := exec.Command("systemctl", "start", systemdServiceName).Output()
if err != nil {
return false, errors.Wrap(err, "failed to start service")
}