Add code to enable service to start at system boot

This commit is contained in:
Filiberto Fuentes 2023-12-14 17:24:44 +00:00
Родитель d5cbe5e896
Коммит 977707aea3
2 изменённых файлов: 19 добавлений и 0 удалений

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

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

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

@ -42,6 +42,13 @@ func InstallRunCommandService(ctx *log.Context) (bool, error) {
return false, errors.Wrap(err, "failed to install service")
}
// Important to enable the service to start automatically at system boot as current
// configuration does not allow that action
_, err = enableService(ctx)
if err != nil {
return false, errors.Wrap(err, "failed to enable service after install")
}
return startService(ctx)
}
@ -143,3 +150,15 @@ func stopService(ctx *log.Context) (bool, error) {
ctx.Log("event", "Run command service has been stopped")
return true, nil
}
// Enables the RunCommand service by invoking 'systemctl enable'
func enableService(ctx *log.Context) (bool, error) {
ctx.Log("event", "Trying to enable run command service to start at system boot")
_, err := exec.Command("systemctl", "enable", systemdServiceName).Output()
if err != nil {
return false, errors.Wrap(err, "failed to enable service")
}
ctx.Log("event", "Run command service has been enable to start at system boot")
return true, nil
}