Skip to content

Commit

Permalink
add install scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-christophe81 committed Jun 19, 2024
1 parent 93afcbf commit ae0216c
Show file tree
Hide file tree
Showing 16 changed files with 517 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ endif()
# ########### CONSTANTS ###########
set(USER_BROKER centreon-broker)
set(USER_ENGINE centreon-engine)
set(USER_AGENT centreon-agent)


find_package(fmt CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
Expand Down
30 changes: 25 additions & 5 deletions agent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ project("Centreon agent" C CXX)
# Set directories.
set(INCLUDE_DIR "${PROJECT_SOURCE_DIR}/inc/com/centreon/agent")
set(SRC_DIR "${PROJECT_SOURCE_DIR}/src")
set(SCRIPT_DIR "${PROJECT_SOURCE_DIR}/scripts")


add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1")
Expand Down Expand Up @@ -130,8 +131,6 @@ target_link_libraries(
${CENTREON_AGENT} PRIVATE
-L${PROTOBUF_LIB_DIR}
gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts
# cerpc
# berpc
centagent_lib
centreon_common
centreon_grpc
Expand All @@ -157,7 +156,28 @@ if(WITH_TESTING)
add_subdirectory(test)
endif()

#if(WITH_CONF)
# add_subdirectory(conf)
#endif()

set(PREFIX_AGENT_CONF "${CMAKE_INSTALL_FULL_SYSCONFDIR}/centreon-agent")


if(WITH_CONF)
add_subdirectory(conf)
endif()

# Generate Systemd script.
message(STATUS "Generating systemd startup script.")
configure_file("${SCRIPT_DIR}/centagent.service.in"
"${SCRIPT_DIR}/centagent.service")

# Startup dir.
if(WITH_STARTUP_DIR)
set(STARTUP_DIR "${WITH_STARTUP_DIR}")
else()
set(STARTUP_DIR "/etc/systemd/system")
endif()

# Script install rule.
install(
PROGRAMS "${SCRIPT_DIR}/centagent.service"
DESTINATION "${STARTUP_DIR}"
COMPONENT "runtime")
137 changes: 137 additions & 0 deletions agent/conf/centagent.cfg.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
##
## Copyright 2024 Centreon
##
## This file is part of Centreon Agent.
##
## 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]
##

# file: centagent.cfg
# brief: Sample main config file for Centreon Agent @VERSION@
#
# Read the documentation for more information on this configuration file. I've
# provided some comments here, but things may not be so clear without further
# explanation.
# If you want to have a list of all options,
# in a terminal, executes @CMAKE_INSTALL_FULL_BINDIR@/@CENTREON_AGENT@ --help


# var: log_file
# brief: This is the main log file where service and host events are logged for
# historical purposes. This should be the first option specified in the
# config file!

log_file=@AGENT_VAR_LOG_DIR@/@[email protected]


# var: log_level
# brief: You can choose log verbosity:
# critical, error, info, debug, trace
# You can change log verbosity during runtime with USR1 and USR2 signals
# Ex: kill -USR1 <pid> to increase verbosity (error => info for example)
# kill -USR2 <pid> to decrease verbosity

log_level=info


# var: logger-type
# brief: type of log output: stdout or to a file

logger-type=file


# var: logger-file
# brief: in case of logger-type=file, logs will be written in this file

logger-file=/var/log/centreon-agent/centagent.log


# var: logger-max-file-size
# brief: max log file size in bytes until rotate

logger-max-file-size=10000000


# var: logger-max-files
# brief: max number of log files (oldest will be removed)

logger-max-files=3


# var: endpoint
# brief: This parameter is mandatory
# In normal case (agent connects to engine), this endpoint is the
# opentelemetry listening endpoint of engine
# His syntax is <ip or dns name>:port

#endpoint=<poller ip>:4317


# var: encryption
# brief: false by default
# set to true to enable encryption between engine and agent

encryption=false


# var: certificate
# brief: path of the certificate file used by encryption

#certificate=/etc/centron-agent/certif.crt


# var: private_key
# brief: path of the key file of the certificate file

#private_key=/etc/centreon-agent/certif.key


# var: ca_certificate
# brief: path of the authority certificate file used by encryption

#ca_certificate=/etc/centreon-agent/ca.crt


# var: ca_name
# brief: name of the host declared in authority certificate

#ca_name=


# var: host
# brief: name of the host declared in centreon configuration
# if not given, hostname of the computer will be used

#host=


# var: reversed-grpc-streaming
# brief: used when centreon agent is not allowed to connect to poller
# if this option if set to true, centreon agent become a
# grpc server listening on pair interface:port given by
# endpoint parameter where poller will have to connect to

reversed-grpc-streaming=false


# var: host
# brief: name of the host declared in centreon configuration
# if not given, hostname of the computer will be used

#host=




27 changes: 27 additions & 0 deletions agent/scripts/centagent.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright 2016 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]
#

[Unit]
Description=Centreon Agent

[Service]
ExecStart=@CMAKE_INSTALL_FULL_BINDIR@/@CENTREON_AGENT@ @PREFIX_AGENT_CONF@/@[email protected]
ExecReload=/bin/kill -HUP $MAINPID
Type=simple
User=centreon-agent

34 changes: 34 additions & 0 deletions packaging/centagent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,43 @@ homepage: "https://www.centreon.com"
license: "Apache-2.0"

contents:
- src: "../agent/conf/centagent.cfg"
dst: "/etc/centreon-agent/centagent.cfg"
type: config|noreplace
file_info:
mode: 0664
owner: centreon-agent
group: centreon-agent

- src: "../build/agent/centagent"
dst: "/usr/bin/centagent"

- dst: "/etc/centreon-agent"
type: dir
file_info:
mode: 0775
owner: centreon-agent
group: centreon-agent

- dst: "/var/log/centreon-agent"
type: dir
file_info:
mode: 0755
owner: centreon-agent
group: centreon-agent

- src: "/usr/lib/nagios/plugins"
dst: "/usr/lib64/nagios/plugins"
type: symlink
packager: deb

scripts:
preinstall: ./scripts/centreon-agent-daemon-preinstall.sh
postinstall: ./scripts/centreon-agent-daemon-postinstall.sh
preremove: ./scripts/centreon-agent-daemon-preremove.sh
postremove: ./scripts/centreon-agent-daemon-postremove.sh


rpm:
summary: Centreon Collect Agent. It can be used to execute remotely plugins
compression: zstd
Expand Down
40 changes: 40 additions & 0 deletions packaging/centreon-agent-selinux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "centreon-agent-selinux"
arch: "${ARCH}"
platform: "linux"
version_schema: "none"
version: "${VERSION}"
release: "${RELEASE}${DIST}"
section: "default"
priority: "optional"
maintainer: "Centreon <[email protected]>"
description: |
SELinux context for centreon-agent
vendor: "Centreon"
homepage: "https://centreon.com"
license: "Apache-2.0"

depends:
- policycoreutils
- centreon-common-selinux
replaces:
- centreon-agent-selinux-debuginfo
conflicts:
- centreon-agent-selinux-debuginfo
provides:
- centreon-agent-selinux-debuginfo

contents:
- src: "../selinux/centreon-agent/centreon-agent.pp"
dst: "/usr/share/selinux/packages/centreon/centreon-agent.pp"
file_info:
mode: 0655

scripts:
postinstall: ./scripts/centreon-agent-selinux-postinstall.sh
preremove: ./scripts/centreon-agent-selinux-preremove.sh

rpm:
summary: SELinux context for centreon-agent
signature:
key_file: ${RPM_SIGNING_KEY_FILE}
key_id: ${RPM_SIGNING_KEY_ID}
25 changes: 25 additions & 0 deletions packaging/scripts/centreon-agent-daemon-postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

startCentagent() {
systemctl daemon-reload ||:
systemctl unmask centagent.service ||:
systemctl preset centagent.service ||:
systemctl enable centagent.service ||:
systemctl restart centagent.service ||:
}

# on debian, it is needed to recreate centreon-agent user at each upgrade because it is removed on postrm step on versions < 23.10
if [ "$1" = "configure" ] ; then
if [ ! "$(getent passwd centreon-agent)" ]; then
adduser --system --group --shell /bin/bash --no-create-home centreon-agent
fi
if [ "$(getent passwd nagios)" ]; then
usermod -a -G centreon-agent nagios
fi
chown -R centreon-agent:centreon-agent \
/etc/centreon-agent \
/var/log/centreon-agent
fi

startCentagent

8 changes: 8 additions & 0 deletions packaging/scripts/centreon-agent-daemon-postremove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

case "$1" in
purge)
deluser centreon-agent || :
delgroup centreon-agent || :
;;
esac
10 changes: 10 additions & 0 deletions packaging/scripts/centreon-agent-daemon-preinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

if ! id centreon-agent > /dev/null 2>&1; then
useradd -r centreon-agent > /dev/null 2>&1
fi

if id -g nagios > /dev/null 2>&1; then
usermod -a -G centreon-agent nagios
fi

3 changes: 3 additions & 0 deletions packaging/scripts/centreon-agent-daemon-preremove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

systemctl stop centagent.service ||:
25 changes: 25 additions & 0 deletions packaging/scripts/centreon-agent-selinux-postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

install() {
semodule -i /usr/share/selinux/packages/centreon/centreon-engine.pp > /dev/null 2>&1 || :
}

upgrade() {
semodule -i /usr/share/selinux/packages/centreon/centreon-engine.pp > /dev/null 2>&1 || :
}

action="$1"
if [ "$1" = "configure" ] && [ -z "$2" ]; then
action="install"
elif [ "$1" = "configure" ] && [ -n "$2" ]; then
action="upgrade"
fi

case "$action" in
"1" | "install")
install
;;
"2" | "upgrade")
upgrade
;;
esac
5 changes: 5 additions & 0 deletions packaging/scripts/centreon-agent-selinux-preremove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

if [ "$1" -lt "1" ]; then # Final removal
semodule -r centreon-agent > /dev/null 2>&1 || :
fi
1 change: 1 addition & 0 deletions selinux/centreon-agent/centreon-agent.fc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/bin/centagent -- gen_context(system_u:object_r:centreon_agent_exec_t,s0)
1 change: 1 addition & 0 deletions selinux/centreon-agent/centreon-agent.if
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## <summary>Centreon Agent monitoring agent.</summary>
Loading

0 comments on commit ae0216c

Please sign in to comment.