Resolve "Add `systemd` service files for Cargo"

Closes #20 (closed)

Merge request reports

Loading

cli/CMakeLists.txt

0 → 100644
+92 −0
Changes for cli/CMakeLists.txt: 92 added lines, 0 removed lines.
Original line number Diff line number Diff line
################################################################################
# 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                                    #
################################################################################

################################################################################
## 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
  PRIVATE
    ping.cpp
)

target_link_libraries(cargo_ping
  PUBLIC
    fmt::fmt
    CLI11::CLI11
    net::rpc_client
    cargo
)

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

target_sources(cargo_shutdown
  PRIVATE
    shutdown.cpp
)

target_link_libraries(cargo_shutdown
        PUBLIC
        fmt::fmt
        CLI11::CLI11
        net::rpc_client
        cargo
)

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

target_sources(ccp
  PRIVATE
    copy.cpp
)

target_link_libraries(ccp
  PUBLIC
    fmt::fmt
    CLI11::CLI11
    net::rpc_client
    cargo
)

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
Changes for cli/cargoctl.in: 172 added lines, 0 removed lines.
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 "$@"
+0 −0

File moved.

+0 −0

File moved.

+0 −0

File moved.

Loading
Loading