Verified Commit 2d41f87a authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Refactor configuration for scord and scord-ctl

scord:
- Configuration file now uses standard YAML format
- Add `--output` CLI argument (SCORD_LOG_OUTPUT)

scord-ctl:
- Add `--output` CLI argument
- Add `--listen` CLI argument (Fixes #126)
- Remove configuration file

Both:
- Remove file_options dependency
- Remove genopts dependency
- Replace yaml-cpp with rapidyaml
- Replace general settings with specific configurations (fixes #20)
- General improvements and bugfixes in `logger`
- Improved `net::server` configuration
- Fix fork()-related bug in `signal_listener`
- Remove environment variables
parent 9d13a456
Loading
Loading
Loading
Loading
Loading
+14 −16
Original line number Diff line number Diff line
@@ -220,29 +220,27 @@ FetchContent_Declare(
FetchContent_MakeAvailable(spdlog)
set_target_properties(spdlog PROPERTIES POSITION_INDEPENDENT_CODE ON)

### file_options: required for reading configuration files
message(STATUS "[${PROJECT_NAME}] Downloading and building file_options")
### rapidyaml: required for reading configuration files
message(STATUS "[${PROJECT_NAME}] Downloading and building rapidyaml")
FetchContent_Declare(
  file_options
  GIT_REPOSITORY https://storage.bsc.es/gitlab/utils/file_options
  GIT_TAG bdb4f7f7f2dd731815241fc41afe6373df8f732a # v0.1.0-pre
  GIT_SHALLOW ON
  GIT_PROGRESS ON
  ryml
  GIT_REPOSITORY https://github.com/biojppm/rapidyaml.git
  GIT_TAG b35ccb150282760cf5c2d316895cb86bd161ac89 #v0.5.0
  GIT_SHALLOW OFF # ensure submodules are checked out
)

FetchContent_MakeAvailable(file_options)
FetchContent_MakeAvailable(ryml)
set_target_properties(ryml PROPERTIES POSITION_INDEPENDENT_CODE ON)

### genopts: required for generating file_options schemas
message(STATUS "[${PROJECT_NAME}] Downloading and building genopts")
FetchContent_Declare(
  genopts
  GIT_REPOSITORY https://storage.bsc.es/gitlab/utils/genopts
  GIT_TAG c456c2d8ec92f26d9074b123446261103e5c847c # v0.1.0-pre
### CLI11: used for parsing command-line options
message(STATUS "[${PROJECT_NAME}] Searching for CLI11")
FetchContent_Declare(cli11
  GIT_REPOSITORY https://github.com/CLIUtils/CLI11
  GIT_TAG 291c58789c031208f08f4f261a858b5b7083e8e2 # v2.3.2
  GIT_SHALLOW ON
  GIT_PROGRESS ON
)

FetchContent_MakeAvailable(genopts)
FetchContent_MakeAvailable(cli11)

### expected: required for using tl::expected in the C++ library implementation
### until std::expected makes it to C++
+4 −17
Original line number Diff line number Diff line
## vim: set filetype=yaml:

## global service settings
global_settings: [

  # if true, dump log messages to syslog
  use_syslog: false,
global_settings:

  # log file
  log_file: "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/@CMAKE_PROJECT_NAME@/@CMAKE_PROJECT_NAME@.log",
  logfile: "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/@CMAKE_PROJECT_NAME@/@CMAKE_PROJECT_NAME@.log"

  # path to pidfile
  pidfile: "@CMAKE_INSTALL_FULL_RUNSTATEDIR@/@CMAKE_PROJECT_NAME@/@CMAKE_PROJECT_NAME@.pid",

  # transport protocol used for communication
  transport_protocol: "@SCORD_TRANSPORT_PROTOCOL@",
  rundir: "@CMAKE_INSTALL_FULL_RUNSTATEDIR@/@CMAKE_PROJECT_NAME@"

  # address to bind to
  bind_address: "@SCORD_BIND_ADDRESS@",

  # incoming port for remote connections
  remote_port: @SCORD_BIND_PORT@,

  # number of worker threads to serve I/O requests
  workers: 4,
]
  address: "@SCORD_TRANSPORT_PROTOCOL@://@SCORD_BIND_ADDRESS@:@SCORD_BIND_PORT@"
+0 −1
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ if(SCORD_BUILD_TESTS)
  file(MAKE_DIRECTORY ${TEST_DIRECTORY})

  set(TEST_ENV)
  list(APPEND TEST_ENV SCORD_LOG=1)
  list(APPEND TEST_ENV SCORD_LOG_OUTPUT=${TEST_DIRECTORY}/scord_daemon.log)

  add_test(start_scord_daemon
+0 −4
Original line number Diff line number Diff line
@@ -29,10 +29,6 @@ add_subdirectory(utils)
target_include_directories(_utils INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
add_library(common::utils ALIAS _utils)

add_subdirectory(config)
target_include_directories(_config INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
add_library(common::config ALIAS _config)

add_subdirectory(logger)
target_include_directories(_logger INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
add_library(common::logger ALIAS _logger)

src/common/config/CMakeLists.txt

deleted100644 → 0
+0 −87
Original line number Diff line number Diff line
################################################################################
# Copyright 2021, Barcelona Supercomputing Center (BSC), Spain                 #
#                                                                              #
# This software was partially supported by the EuroHPC-funded project ADMIRE   #
#   (Project ID: 956748, https://www.admire-eurohpc.eu).                       #
#                                                                              #
# This file is part of scord.                                                  #
#                                                                              #
# scord is free software: you can redistribute it and/or modify                #
# it under the terms of the GNU General Public License as published by         #
# the Free Software Foundation, either version 3 of the License, or            #
# (at your option) any later version.                                          #
#                                                                              #
# scord is distributed in the hope that it will be useful,                     #
# but WITHOUT ANY WARRANTY; without even the implied warranty of               #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
# GNU General Public License for more details.                                 #
#                                                                              #
# You should have received a copy of the GNU General Public License            #
# along with scord.  If not, see <https://www.gnu.org/licenses/>.              #
#                                                                              #
# SPDX-License-Identifier: GPL-3.0-or-later                                    #
################################################################################

# Create a config target for all configuration code
add_library(_config STATIC)

# Since some of the sources will be auto-generated, we need to search for
# includes in ${CMAKE_CURRENT_BINARY_DIR}
target_include_directories(
  _config PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
                 ${CMAKE_CURRENT_BINARY_DIR}
)
set_property(TARGET _config PROPERTY POSITION_INDEPENDENT_CODE ON)

target_sources(
  _config
  PRIVATE config.hpp
          defaults.hpp
          ${CMAKE_CURRENT_BINARY_DIR}/defaults.cpp
          ${CMAKE_CURRENT_BINARY_DIR}/config_options.hpp
          ${CMAKE_CURRENT_BINARY_DIR}/keywords.hpp
          parsers.cpp
          parsers.hpp
          settings.cpp
          settings.hpp
)

target_link_libraries(_config PRIVATE common::utils file_options::file_options)

# ##############################################################################
# Produce several auto-generated files for 'config'
# ##############################################################################

# Default values for options
configure_file(defaults.cpp.in defaults.cpp)

# Automatic generation of file_options schemas. To facilitate the management of
# any file-based configuration options, we generate a C++ schema from a YAML
# file that allows the 'file_options' library to parse them fromm a
# configuration file. The process works as follows:
#  1. We define the desired options in 'file_options.yml'
#  2. We rely on the 'genopts' tool to generate valid C++ schemas for the
#     'file_options' library. This tool can be configured using a 'genopts.yml'
#     configuration file.
#  3. In the daemon code, we use the facilities provided by the 'file_options'
#     library to access the options values.

# Since the configuration in genopts.yml can be path-dependant, we rely on
# CMake to substitute any special @variables@ for their actual values
configure_file(genopts.yml.in genopts.yml @ONLY)

# Define the command that will generate config_options.hpp and keywords.hpp.
# It will be executed since there is a direct dependency between 'config'
# (defined below) and these output files.
# We also make the command depend on file_options.yml and genopts.yml so that
# it gets re-executed if they change.
add_custom_command(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/config_options.hpp
         ${CMAKE_CURRENT_BINARY_DIR}/keywords.hpp
  COMMENT "Generating config_options.hpp, keywords.hpp"
  DEPENDS genopts_virtualenv file_options.yml ${CMAKE_CURRENT_BINARY_DIR}/genopts.yml
  COMMAND
    Genopts::Python3_Interpreter -m genopts --config
    ${CMAKE_CURRENT_BINARY_DIR}/genopts.yml
    ${CMAKE_CURRENT_LIST_DIR}/file_options.yml
)
Loading