Stop the Icinga service before uninstalling the files.

Refs #4865
This commit is contained in:
Gunnar Beutner 2014-04-20 15:35:51 +02:00
parent 088b15e964
commit ad894c367a
3 changed files with 14 additions and 22 deletions

View File

@ -146,6 +146,7 @@ set(CPACK_SOURCE_IGNORE_FILES "/.git/" "/debian/" "/.vagrant/" "/release/" "/deb
set(CPACK_NSIS_EXECUTABLES_DIRECTORY "sbin") set(CPACK_NSIS_EXECUTABLES_DIRECTORY "sbin")
set(CPACK_PACKAGE_EXECUTABLES "Icinga2SetupAgent;Icinga 2 Agent Wizard") set(CPACK_PACKAGE_EXECUTABLES "Icinga2SetupAgent;Icinga 2 Agent Wizard")
set(CPACK_NSIS_MUI_FINISHPAGE_RUN "Icinga2SetupAgent") set(CPACK_NSIS_MUI_FINISHPAGE_RUN "Icinga2SetupAgent")
set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "nsExec::Exec '\\\"$INSTDIR\\\\sbin\\\\icinga2\\\" --scm-uninstall'")
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE) set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
include(InstallRequiredSystemLibraries) include(InstallRequiredSystemLibraries)

View File

@ -471,9 +471,12 @@ static int SetupService(bool install, int argc, char **argv)
for (int i = 0; i < argc; i++) for (int i = 0; i < argc; i++)
szArgs += " " + Utility::EscapeShellArg(argv[i]); szArgs += " " + Utility::EscapeShellArg(argv[i]);
SC_HANDLE schService = OpenService(schSCManager, "icinga2", DELETE); SC_HANDLE schService = OpenService(schSCManager, "icinga2", DELETE | SERVICE_STOP);
if (schService != NULL) { if (schService != NULL) {
SERVICE_STATUS status;
ControlService(schService, SERVICE_CONTROL_STOP, &status);
if (!DeleteService(schService)) { if (!DeleteService(schService)) {
printf("DeleteService failed (%d)\n", GetLastError()); printf("DeleteService failed (%d)\n", GetLastError());
CloseServiceHandle(schService); CloseServiceHandle(schService);
@ -513,6 +516,13 @@ static int SetupService(bool install, int argc, char **argv)
SERVICE_DESCRIPTION sdDescription = { "The Icinga 2 monitoring application" }; SERVICE_DESCRIPTION sdDescription = { "The Icinga 2 monitoring application" };
ChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &sdDescription); ChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &sdDescription);
if (!StartService(schService, 0, NULL)) {
printf("StartService failed (%d)\n", GetLastError());
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return 1;
}
CloseServiceHandle(schService); CloseServiceHandle(schService);
} }

View File

@ -157,7 +157,7 @@ namespace Icinga
EnableFeature("agent"); EnableFeature("agent");
EnableFeature("checker"); EnableFeature("checker");
SetConfigureStatus(10, "Setting ACLs for the Icinga 2 directory..."); SetConfigureStatus(50, "Setting ACLs for the Icinga 2 directory...");
DirectoryInfo di = new DirectoryInfo(Icinga2InstallDir); DirectoryInfo di = new DirectoryInfo(Icinga2InstallDir);
DirectorySecurity ds = di.GetAccessControl(); DirectorySecurity ds = di.GetAccessControl();
FileSystemAccessRule rule = new FileSystemAccessRule("NT AUTHORITY\\NetworkService", FileSystemAccessRule rule = new FileSystemAccessRule("NT AUTHORITY\\NetworkService",
@ -166,16 +166,7 @@ namespace Icinga
ds.AddAccessRule(rule); ds.AddAccessRule(rule);
di.SetAccessControl(ds); di.SetAccessControl(ds);
// TODO: Update config SetConfigureStatus(75, "Installing the Icinga 2 service...");
SetConfigureStatus(25, "Stopping the Icinga 2 service...");
try {
using (ServiceController sc = new ServiceController("icinga2")) {
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped);
}
} catch (Exception) { }
SetConfigureStatus(50, "Installing the Icinga 2 service...");
ProcessStartInfo psi = new ProcessStartInfo(); ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = Icinga2InstallDir + "\\sbin\\icinga2.exe"; psi.FileName = Icinga2InstallDir + "\\sbin\\icinga2.exe";
psi.Arguments = "--scm-install -c \"" + Icinga2InstallDir + "\\etc\\icinga2\\icinga2.conf\""; psi.Arguments = "--scm-install -c \"" + Icinga2InstallDir + "\\etc\\icinga2\\icinga2.conf\"";
@ -189,16 +180,6 @@ namespace Icinga
FatalError("The Windows service could not be installed."); FatalError("The Windows service could not be installed.");
} }
SetConfigureStatus(75, "Starting the Icinga 2 service...");
try {
using (ServiceController sc = new ServiceController("icinga2")) {
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running);
}
} catch (Exception ex) {
FatalError("Could not start the Icinga 2 service: " + ex.Message);
}
SetConfigureStatus(100, "Finished."); SetConfigureStatus(100, "Finished.");
FinishConfigure(); FinishConfigure();