diff --git a/CMakeLists.txt b/CMakeLists.txt index b6156f943..9ad2361dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,6 +146,7 @@ set(CPACK_SOURCE_IGNORE_FILES "/.git/" "/debian/" "/.vagrant/" "/release/" "/deb set(CPACK_NSIS_EXECUTABLES_DIRECTORY "sbin") set(CPACK_PACKAGE_EXECUTABLES "Icinga2SetupAgent;Icinga 2 Agent Wizard") 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) include(InstallRequiredSystemLibraries) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 07ffdf43f..4b80fe3a3 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -471,9 +471,12 @@ 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); + SC_HANDLE schService = OpenService(schSCManager, "icinga2", DELETE | SERVICE_STOP); if (schService != NULL) { + SERVICE_STATUS status; + ControlService(schService, SERVICE_CONTROL_STOP, &status); + if (!DeleteService(schService)) { printf("DeleteService failed (%d)\n", GetLastError()); CloseServiceHandle(schService); @@ -513,6 +516,13 @@ static int SetupService(bool install, int argc, char **argv) SERVICE_DESCRIPTION sdDescription = { "The Icinga 2 monitoring application" }; 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); } diff --git a/tools/icinga2-setup-agent/AgentWizard.cs b/tools/icinga2-setup-agent/AgentWizard.cs index 2da6fcd36..eb0a24a00 100644 --- a/tools/icinga2-setup-agent/AgentWizard.cs +++ b/tools/icinga2-setup-agent/AgentWizard.cs @@ -157,7 +157,7 @@ namespace Icinga EnableFeature("agent"); 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); DirectorySecurity ds = di.GetAccessControl(); FileSystemAccessRule rule = new FileSystemAccessRule("NT AUTHORITY\\NetworkService", @@ -166,16 +166,7 @@ namespace Icinga ds.AddAccessRule(rule); di.SetAccessControl(ds); - // TODO: Update config - 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..."); + SetConfigureStatus(75, "Installing the Icinga 2 service..."); ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = Icinga2InstallDir + "\\sbin\\icinga2.exe"; psi.Arguments = "--scm-install -c \"" + Icinga2InstallDir + "\\etc\\icinga2\\icinga2.conf\""; @@ -189,16 +180,6 @@ namespace Icinga 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."); FinishConfigure();