Verified Commit 4231f53c authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Add `cargoctl` CLI util

parent a0ce9e2e
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -149,6 +149,11 @@ message(STATUS "[${PROJECT_NAME}] server bind port: ${CARGO_BIND_PORT}")

option(CARGO_BUILD_TESTS "Build tests (disabled by default)" OFF)

### MPI options that should be passed to ${MPIEXEC_EXECUTABLE} when starting
### the server via the `cargoctl` script
set(CARGOCTL_MPIEXEC_OPTIONS "--map-by node --oversubscribe" CACHE STRING
  "Options passed to `${MPIEXEC_EXECUTABLE}` by `cargoctl` when starting the server")

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# ##############################################################################
@@ -324,6 +329,10 @@ add_subdirectory(cli)
add_subdirectory(lib)
add_subdirectory(src)

if (CARGO_SYSTEMD_SUPPORT)
  add_subdirectory(systemd)
endif ()

if(CARGO_BUILD_TESTS)
  add_subdirectory(tests)
endif()
@@ -334,6 +343,11 @@ endif()
# using find_package()
# ##############################################################################

set(BIN_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}"
    CACHE PATH "Path where ${PROJECT_NAME} binaries will be installed")
set(DATA_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}"
    CACHE PATH "Path where ${PROJECT_NAME} data files will be installed")

include(CMakePackageConfigHelpers)

configure_package_config_file(
@@ -341,6 +355,7 @@ configure_package_config_file(
  "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
  INSTALL_DESTINATION
  "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${PROJECT_VERSION}"
  PATH_VARS BIN_INSTALL_DIR DATA_INSTALL_DIR
)

write_basic_package_version_file(
+20 −0
Original line number Diff line number Diff line
@@ -22,6 +22,19 @@
# SPDX-License-Identifier: GPL-3.0-or-later                                    #
################################################################################

################################################################################
## cargoctl: A CLI tool to interact with a Cargo server
# TODO: This is a hack: `cargoctl` needs to know the full path to the
# installed `cargo` and `cargo_shutdown` programs but CMake doesn't seem to
# provide a way to get this information at this stage. Thus, we set it manually
# here :(
set(CARGO_PROGRAM ${CMAKE_INSTALL_FULL_BINDIR}/cargo)
set(CARGO_SHUTDOWN_PROGRAM ${CMAKE_INSTALL_FULL_BINDIR}/cargo_shutdown)
configure_file(cargoctl.in cargoctl @ONLY)


################################################################################
## cargo_ping: A CLI tool to check if a Cargo server is running
add_executable(cargo_ping)

target_sources(cargo_ping
@@ -37,6 +50,8 @@ target_link_libraries(cargo_ping
    cargo
)

################################################################################
## cargo_shutdown: A CLI tool to shutdown a Cargo server
add_executable(cargo_shutdown)

target_sources(cargo_shutdown
@@ -52,6 +67,8 @@ target_link_libraries(cargo_shutdown
        cargo
)

################################################################################
## ccp: A CLI tool to request a Cargo server to copy files between storage tiers
add_executable(ccp)

target_sources(ccp
@@ -70,3 +87,6 @@ target_link_libraries(ccp
install(TARGETS cargo_ping cargo_shutdown ccp
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/cargoctl
        DESTINATION ${CMAKE_INSTALL_BINDIR})

cli/cargoctl.in

0 → 100755
+172 −0
Original line number Diff line number Diff line
#!/bin/bash
################################################################################
# Copyright 2022-2023, 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 Cargo.                                                  #
#                                                                              #
# Cargo 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.                                          #
#                                                                              #
# Cargo 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 Cargo.  If not, see <https://www.gnu.org/licenses/>.              #
#                                                                              #
# SPDX-License-Identifier: GPL-3.0-or-later                                    #
################################################################################

progname=$(basename "$0")

usage() {
  echo "Usage: $progname COMMAND <OPTIONS>"
  echo ""
  echo "  -h, --help:     Show this help message and exit"
  echo ""
  echo "Valid commands:"
  echo ""
  echo "Start a Cargo server listening on a address <ADDR>, with <N> workers "
  echo "distributed over a pool of hosts <host1, host2, ..., hostN>:"
  echo "  $progname start -s <ADDR> -H <host1,host2,...,hostN> -n <N> "
  echo ""
  echo "NOTE: ADDR must be a valid Mercury address, and host1, host2, ..., "
  echo "hostN must be valid hostnames. Also, ADDR should refer to one of the "
  echo "defined hosts in the host pool."
  echo ""
  echo "Stop a Cargo server listening on a given address <ADDR>:"
  echo "  $progname stop -s <ADDR>"
  exit 1
}

start() {
  if [ $# -eq 0 ]; then
    echo "$progname: ERROR: No options provided" >&2
    usage
  fi

  local OPTIND opt workers address

  while getopts ":s:H:n:" opt; do
    case $opt in
    s)
      address="$OPTARG"
      ;;
    H)
      hosts="$OPTARG"
      ;;
    n)
      workers="$OPTARG"
      ;;
    \?)
      echo "$progname: Invalid option: '-$OPTARG'" >&2
      usage
      ;;
    :)
      echo "Option -$OPTARG requires an argument." >&2
      usage
      ;;
    esac
  done

  if [ -z "$workers" ]; then
    echo "$progname: ERROR: Number of workers not provided" >&2
    usage
  fi

  if [ -z "$address" ]; then
    echo "$progname: ERROR: Bind address not provided" >&2
    usage
  fi

  echo "Starting the Cargo server"
  echo "  Hosts: $hosts"
  echo "  Workers: $workers"
  echo "  Master address: $address"

  if ! @MPIEXEC_EXECUTABLE@ \
    -H "$hosts" \
    -np "$workers" \
    @CARGOCTL_MPIEXEC_OPTIONS@ \
    @CARGO_PROGRAM@ --listen "$address"; then
    echo "Failed to start the Cargo server"
    exit 1
  fi
}

stop() {

  if [ $# -eq 0 ]; then
    echo "$progname: ERROR: No options provided" >&2
    usage
  fi

  local OPTIND opt address

  while getopts ":s:" opt; do
    case $opt in
    s)
      address="$OPTARG"
      ;;
    \?)
      echo "$progname: Invalid option: '-$OPTARG'" >&2
      usage
      ;;
    :)
      echo "Option -$OPTARG requires an argument." >&2
      usage
      ;;
    esac
  done

  if [ -z "$address" ]; then
    echo "$progname: ERROR: Server address not provided" >&2
    usage
  fi

  echo "Stopping the Cargo server at $address"
  @CARGO_SHUTDOWN_PROGRAM@ -s "$address"
}

main() {
  if [ $# -lt 1 ]; then
    usage
  fi

  echo "Running $progname $*"

  local cmd

  for arg in "$@"; do
    case $arg in
    "-h" | "--help")
      usage
      ;;
    *) ;;

    esac
  done

  while [ $# -gt 0 ]; do
    case $1 in
    "start" | "stop")
      cmd="$1"
      shift
      "$cmd" "$@"
      exit 0
      ;;
    *)
      echo "$progname: Invalid option: $1" >&2
      usage
      ;;
    esac
  done
}

main "$@"