in internal/immediatecmds/immediatecmds.go [77:113]
func Enable(ctx *log.Context, h types.HandlerEnvironment, extName string, seqNum int, cfg handlersettings.HandlerSettings) (int, error) {
// If installService == true, then install RunCommand as a service
if cfg.InstallAsService() {
isInstalled, err2 := service.IsInstalled(ctx)
if err2 != nil {
ctx.Log("message", "could not check if service is already installed. Proceeding to overwrite configuration file to make sure it gets installed.")
}
if !isInstalled {
err3 := service.Register(ctx)
if err3 != nil {
return constants.ExitCode_InstallServiceFailed, errors.Wrap(err3, "failed to install RunCommand as a service")
}
} else {
isEnabled, err3 := service.IsEnabled(ctx)
if err3 != nil {
return constants.ExitCode_InstallServiceFailed, errors.Wrap(err3, "failed to check if service is already enabled")
}
if !isEnabled {
err4 := service.Enable(ctx)
if err4 != nil {
return constants.ExitCode_InstallServiceFailed, errors.Wrap(err4, "failed to enable service")
}
err5 := service.Start(ctx)
if err5 != nil {
return constants.ExitCode_InstallServiceFailed, errors.Wrap(err5, "failed to start service")
}
}
}
}
return constants.ExitCode_Okay, nil
}