Make sure that --scm-install doesn't fail when the service already exists

fixes #9255
This commit is contained in:
Gunnar Beutner 2015-05-12 14:39:44 +02:00
parent 85d773a21b
commit 01729087e9
1 changed files with 21 additions and 20 deletions

View File

@ -515,7 +515,7 @@ static int SetupService(bool install, int argc, char **argv)
for (int i = 0; i < argc; i++)
szArgs += " " + Utility::EscapeShellArg(argv[i]);
SC_HANDLE schService = OpenService(schSCManager, "icinga2", DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);
SC_HANDLE schService = OpenService(schSCManager, "icinga2", SERVICE_ALL_ACCESS);
if (schService != NULL) {
SERVICE_STATUS status;
@ -537,21 +537,7 @@ static int SetupService(bool install, int argc, char **argv)
return 1;
}
}
if (!DeleteService(schService)) {
printf("DeleteService failed (%d)\n", GetLastError());
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return 1;
}
if (!install)
printf("Service uninstalled successfully\n");
CloseServiceHandle(schService);
}
if (install) {
} else if (install) {
schService = CreateService(
schSCManager,
"icinga2",
@ -571,11 +557,25 @@ static int SetupService(bool install, int argc, char **argv)
printf("CreateService failed (%d)\n", GetLastError());
CloseServiceHandle(schSCManager);
return 1;
} else
printf("Service installed successfully\n");
}
} else {
printf("Service isn't installed.\n");
CloseServiceHandle(schSCManager);
return 0;
}
if (!install) {
if (!DeleteService(schService)) {
printf("DeleteService failed (%d)\n", GetLastError());
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return 1;
}
printf("Service uninstalled successfully\n");
} else {
ChangeServiceConfig(schService, SERVICE_NO_CHANGE, SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
SERVICE_ERROR_NORMAL, szArgs.CStr(), NULL, NULL, NULL, NULL, NULL, NULL);
SERVICE_DESCRIPTION sdDescription = { "The Icinga 2 monitoring application" };
ChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &sdDescription);
@ -587,9 +587,10 @@ static int SetupService(bool install, int argc, char **argv)
return 1;
}
CloseServiceHandle(schService);
printf("Service installed successfully\n");
}
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return 0;