Skip to content

Commit

Permalink
installer (#1715)
Browse files Browse the repository at this point in the history
dlg and files installer

agent is a windows service

add agent version resources

first version of installer

writer review

add installer to CMakeLists.txt

add comments

Apply suggestions from code review

Co-authored-by: sechkem <[email protected]>
Co-authored-by: cg-tw <[email protected]>
  • Loading branch information
3 people authored Sep 30, 2024
1 parent 06f7172 commit 8f4101f
Show file tree
Hide file tree
Showing 121 changed files with 17,777 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .github/scripts/windows-agent-compile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ else {

cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=On -DWINDOWS=On -DBUILD_FROM_CACHE=On -S. -DVCPKG_CRT_LINKAGE=dynamic -DBUILD_SHARED_LIBS=OFF -Bbuild_windows

Write-Host "build agent and tests"

Write-Host "------------- build agent and installer ---------------"

cmake --build build_windows --config Release

27 changes: 11 additions & 16 deletions .github/workflows/windows-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ concurrency:

on:
workflow_dispatch:
inputs:
installer_in_artifact:
description: 'Save installer and binary in artifacts'
required: true
default: false
type: boolean

pull_request:
paths:
- agent/**
Expand Down Expand Up @@ -61,27 +68,15 @@ jobs:
cd build_windows
tests/ut_agent
- name: Zip agent
run: |
$files_to_compress = "agent\conf\centagent.reg", "build_windows\agent\Release\centagent.exe"
Compress-Archive -Path $files_to_compress -DestinationPath centreon-monitoring-agent.zip
- name: Save agent package in cache
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: centreon-monitoring-agent.zip
key: ${{ github.run_id }}-${{ github.sha }}-CMA-${{ github.head_ref || github.ref_name }}
enableCrossOsArchive: ${{ true }}

- name: Upload package artifacts
if: |
github.event_name != 'workflow_dispatch' &&
inputs.installer_in_artifact == true ||
(github.event_name != 'workflow_dispatch' &&
contains(fromJson('["stable"]'), needs.get-version.outputs.stability) &&
! cancelled() &&
! contains(needs.*.result, 'failure') &&
! contains(needs.*.result, 'cancelled')
! contains(needs.*.result, 'cancelled'))
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
with:
name: packages-centreon-monitoring-agent-windows
path: centreon-monitoring-agent.zip
retention-days: 1
path: agent\installer\centreon-monitoring-agent.exe
9 changes: 8 additions & 1 deletion agent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ add_custom_command(
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})



set( SRC_COMMON
${SRC_DIR}/agent.grpc.pb.cc
${SRC_DIR}/agent.pb.cc
Expand All @@ -122,6 +123,9 @@ set( SRC_LINUX
${SRC_DIR}/config.cc
)

#resource version
configure_file("${SRC_DIR}/agent.rc.in"
"${SRC_DIR}/agent.rc")
configure_file("${INCLUDE_DIR}/version.hh.in"
"${INCLUDE_DIR}/version.hh")

Expand Down Expand Up @@ -165,7 +169,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
fmt::fmt
stdc++fs)
else()
add_executable(${CENTREON_AGENT} ${SRC_DIR}/main_win.cc)
add_executable(${CENTREON_AGENT} ${SRC_DIR}/main_win.cc ${SRC_DIR}/agent.rc)

target_link_libraries(
${CENTREON_AGENT} PRIVATE
Expand All @@ -177,6 +181,9 @@ else()
absl::any absl::log absl::base absl::bits
Boost::program_options
fmt::fmt)

add_subdirectory(installer)

endif()


Expand Down
64 changes: 64 additions & 0 deletions agent/installer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# Copyright 2024 Centreon
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# For more information : [email protected]
#

project("Centreon agent Installer")


# Set directories.
set(CENTAGENT_PATH_OUTPUT_DIR ${Centreon\ agent_BINARY_DIR})

if( ${CMAKE_GENERATOR} MATCHES "Visual Studio.*" )
set(CENTAGENT_PATH "${Centreon\ agent_BINARY_DIR}/${CMAKE_BUILD_TYPE}/centagent.exe")
else()
set(CENTAGENT_PATH "${Centreon\ agent_BINARY_DIR}/centagent.exe")
endif()

string(REPLACE "/" "\\" CENTAGENT_PATH "${CENTAGENT_PATH}")

#uncomment if makensis is not in the path
set(MKNSIS "C:/Program Files (x86)/NSIS/Bin/makensis.exe")

#set(MKNSIS "makensis.exe")

# Configure files.
configure_file("${PROJECT_SOURCE_DIR}/version.nsi.in" "${PROJECT_SOURCE_DIR}/version.nsi")

file(GLOB COMMON_INSTALLERS_FILES "${PROJECT_SOURCE_DIR}/version.nsi" "${PROJECT_SOURCE_DIR}/dlg_helper.nsi" "${PROJECT_SOURCE_DIR}/resources/*")

message(NOTICE "---------------- Generate installer in ${PROJECT_SOURCE_DIR} ---------------")

# modify binary called from the application manager
# embedded in installer
add_custom_command(
DEPENDS "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent-modify.nsi" ${COMMON_INSTALLERS_FILES} ${CENTREON_AGENT}
COMMENT "--------- Generating cma configuration modifier --------"
OUTPUT "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent-modify.exe"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMAND ${MKNSIS} "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent-modify.nsi")


#final installer
add_custom_command(
DEPENDS "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent.nsi" "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent-modify.exe" ${COMMON_INSTALLERS_FILES}
COMMENT "--------- Generating cma configuration installer --------"
OUTPUT "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent.exe"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMAND ${MKNSIS} "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent.nsi")

add_custom_target("centreon-monitoring-agent-installer" ALL DEPENDS "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent.exe")

123 changes: 123 additions & 0 deletions agent/installer/centreon-monitoring-agent-modify.nsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#
# Copyright 2024 Centreon
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# For more information : [email protected]
#

XPStyle on

Unicode false

!define APPNAME "CentreonMonitoringAgent"
!define COMPANYNAME "Centreon"
!define DESCRIPTION "The Centreon Monitoring Agent (CMA) collects metrics and computes statuses on the servers it monitors, and sends them to Centreon."

!define SERVICE_NAME ${APPNAME}

!define CMA_REG_KEY "SOFTWARE\${COMPANYNAME}\${APPNAME}"

!include "LogicLib.nsh"
!include "nsDialogs.nsh"
!include "mui.nsh"
!include "Sections.nsh"
!include "StrFunc.nsh"
!include "FileFunc.nsh"

!include "nsis_service_lib.nsi"

${Using:StrFunc} StrCase

!define NSISCONF_3 ";" ; NSIS 2 tries to parse some preprocessor instructions inside "!if 0" blocks!
!addincludedir "nsis_pcre"
!define /redef NSISCONF_3 ""
${NSISCONF_3}!addplugindir /x86-ansi "nsis_pcre"
!undef NSISCONF_3


!include "version.nsi"
!include "resources\setup_dlg.nsdinc"
!include "resources\encryption_dlg.nsdinc"
!include "resources\log_dlg.nsdinc"
#let it after dialog boxes
!include "dlg_helper.nsi"

Name "Centreon Monitoring Agent ${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}"
Icon "resources/logo_centreon.ico"
RequestExecutionLevel admin
AllowRootDirInstall true



!macro VerifyUserIsAdmin
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights
messageBox mb_iconstop "Administrator rights required!"
setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
quit
${EndIf}
!macroend

function .onInit
setShellVarContext all
!insertmacro VerifyUserIsAdmin
functionEnd

/**
* @brief at the end of the installer, we stop and start cma
*/
Function encryption_next_and_restart_centagent
Call encryption_dlg_onNext

!insertmacro SERVICE "stop" "${SERVICE_NAME}" ""

;wait for service stop
StrCpy $0 ""
${Do}
Push "running"
Push ${SERVICE_NAME}
Push ""
Call Service
Pop $0
${If} $0 != "true"
${Break}
${EndIf}
Sleep 500
${Loop}
; even if service is stopped, process can be stopping so we wait a little more
Sleep 500

!insertmacro SERVICE "start" "${SERVICE_NAME}" ""
MessageBox MB_OK "The Centreon Monitoring Agent has now restarted"
Quit
FunctionEnd


/**
* @brief this fake page is used to have a close button after restart cma confirmation
*/
Function dummy_page
FunctionEnd

Page custom fnc_cma_Show setup_dlg_onNext
Page custom fnc_log_dlg_Show log_dlg_onNext ": logging"
Page custom fnc_encryption_Show encryption_next_and_restart_centagent ": encryption"
Page custom dummy_page

/**
* @brief this installer only update agent config, no installation
*/
Section "update config"
SectionEnd
Loading

0 comments on commit 8f4101f

Please sign in to comment.