]> granicus.if.org Git - icinga2/commitdiff
Stop the Icinga service before uninstalling the files.
authorGunnar Beutner <gunnar@beutner.name>
Sun, 20 Apr 2014 13:35:51 +0000 (15:35 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Sun, 20 Apr 2014 13:35:51 +0000 (15:35 +0200)
Refs #4865

CMakeLists.txt
icinga-app/icinga.cpp
tools/icinga2-setup-agent/AgentWizard.cs

index b6156f9434c699d7b8e4d08978dfa0d57fb0202d..9ad2361ddda3aca211e21b5ce2aa2ec109ead480 100644 (file)
@@ -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)
index 07ffdf43f4b1f4abef2be625d6a66dbbff43f89a..4b80fe3a32cadc214a137541d2a215872ba11029 100644 (file)
@@ -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);
        }
 
index 2da6fcd3644927f11eb4fe2150324b80546d88cd..eb0a24a00f843051ec3bcf08ebe6be345e982eb2 100644 (file)
@@ -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();