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)
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);
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);
}
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",
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\"";
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();