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 efa6f7f
Show file tree
Hide file tree
Showing 20 changed files with 588 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/package-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
if: ${{ matrix.package_extension == 'rpm' }}
run: |
cd selinux
for MODULE in "centreon-engine" "centreon-broker"; do
for MODULE in "centreon-engine" "centreon-broker" "centreon-agent"; do
cd $MODULE
sed -i "s/@VERSION@/${{ inputs.version }}/g" $MODULE.te
make -f /usr/share/selinux/devel/Makefile
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ log.html
output.xml
report.html

# agent
agent/scripts/centagent.service
opentelemetry-proto

# bbdo
bbdo/*_accessor.hh

Expand Down Expand Up @@ -140,3 +144,4 @@ tests/bench.unqlite
tests/resources/*_pb2.py
tests/resources/*_pb2_grpc.py
tests/resources/grpc_stream.proto
tests/resources/opentelemetry
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")
43 changes: 43 additions & 0 deletions agent/conf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# 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]
#

# Set directories.
set(SRC_DIR "${PROJECT_SOURCE_DIR}/conf")

# Configure files.
configure_file("${SRC_DIR}/centagent.cfg.in"
"${SRC_DIR}/centagent.cfg")

# Install files if necessary.
option(WITH_SAMPLE_CONFIG "Install sample configuration files." ON)
if (WITH_SAMPLE_CONFIG)
install(DIRECTORY "${SRC_DIR}/"
DESTINATION "${PREFIX_AGENT_CONF}"
COMPONENT "runtime"
FILES_MATCHING PATTERN "*.cfg")

install(CODE "
function(my_chown user group file)
if (APPLE OR (UNIX AND NOT CYGWIN))
execute_process(COMMAND \"chown\" \"\${user}:\${group}\" \"\${file}\")
endif ()
endfunction()
my_chown(\"${USER_AGENT}\" \"${USER_AGENT}\" \"${PREFIX_AGENT_CONF}/centagent.cfg\")
")
endif ()
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: log-type
# brief: type of log output: stdout or to a file

log-type=file


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

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


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

log-max-file-size=10000000


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

log-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=




32 changes: 32 additions & 0 deletions agent/scripts/centagent.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# 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
PartOf=centreon.service
After=centreon.service
ReloadPropagatedFrom=centreon.service

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

[Install]
WantedBy=centreon.service
10 changes: 5 additions & 5 deletions agent/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ int main(int argc, char* argv[]) {
"this agent connect to engine in streaming mode")(
"reversed-grpc-streaming", po::value<bool>()->default_value(false),
"this agent accept connection from engine in streaming mode")(
"logger-type", po::value<std::string>()->default_value("stdout"),
"log-type", po::value<std::string>()->default_value("stdout"),
"type of logger: stdout, file")(
"logger-file", po::value<std::string>(),
"log file used in case of logger_type = file")(
"logger-max-file-size", po::value<unsigned>(),
"log-file", po::value<std::string>(),
"log file used in case of log_type = file")(
"log-max-file-size", po::value<unsigned>(),
"max size of log file in Mo before rotate")(
"logger-max-files", po::value<unsigned>(), "max log files");
"log-max-files", po::value<unsigned>(), "max log files");

po::variables_map vm;

Expand Down
47 changes: 46 additions & 1 deletion packaging/centagent.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "centagent"
name: "centreon-agent"
arch: "${ARCH}"
platform: "linux"
version_schema: "none"
Expand All @@ -15,9 +15,54 @@ 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: "../agent/scripts/centagent.service"
dst: "/usr/lib/systemd/system/centagent.service"
file_info:
mode: 0644
packager: rpm
- src: "../agent/scripts/centagent.service"
dst: "/lib/systemd/system/centagent.service"
file_info:
mode: 0644
packager: deb

- 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
Loading

0 comments on commit efa6f7f

Please sign in to comment.