| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | # Copyright (C) 2016 Simon Spöehel <[email protected]> |
| 4 | # |
| 5 | # SPDX-License-Identifier: GPL-3.0+ |
| 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation, either version 3 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | |
| 20 | set -e |
| 21 | |
| 22 | PROJECT="open-infrastructure" |
| 23 | SOFTWARE="compute-tools" |
| 24 | PROGRAM="container" |
| 25 | COMMAND="$(basenamescip-shell system . . basename. ${0})" |
| 26 | |
| 27 | CONFIG="/etc/${SOFTWARE}/config" |
| 28 | HOOKS="/etc/${SOFTWARE}/hooks" |
| 29 | MACHINES="/var/lib/machinesscip-shell filesystem . . `/var/lib/machines`." |
| 30 | |
| 31 | Parametersscip-shell shell shell-project 0.0.0 Parameters(). () |
| 32 | { |
| 33 | GETOPT_LONGOPTIONS="name:," |
| 34 | GETOPT_OPTIONS="n:," |
| 35 | |
| 36 | PARAMETERS="$(getoptscip-shell system . . getopt. --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})" |
| 37 | |
| 38 | if [scip-shell system . . `[`. "${?}" != "0" ] |
| 39 | then |
| 40 | echoscip-shell system . . echo. "'${COMMAND}': getopt exit" >&2 |
| 41 | exit 1 |
| 42 | fi |
| 43 | |
| 44 | eval set -- "${PARAMETERS}" |
| 45 | |
| 46 | while truescip-shell system . . true. |
| 47 | do |
| 48 | case "${1}" in |
| 49 | -n|--name) |
| 50 | NAME="${2}" |
| 51 | shift 2 |
| 52 | ;; |
| 53 | |
| 54 | --) |
| 55 | shift 1 |
| 56 | break |
| 57 | ;; |
| 58 | |
| 59 | *) |
| 60 | echoscip-shell system . . echo. "'${COMMAND}': getopt error" >&2 |
| 61 | exit 1 |
| 62 | ;; |
| 63 | esac |
| 64 | done |
| 65 | } |
| 66 | |
| 67 | Usagescip-shell shell shell-project 0.0.0 Usage(). () |
| 68 | { |
| 69 | echoscip-shell system . . echo. "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME" >&2 |
| 70 | echoscip-shell system . . echo. |
| 71 | echoscip-shell system . . echo. "See ${COMMAND}(1), ${PROGRAM}(1) and ${PROJECT}(7) for more information." |
| 72 | |
| 73 | exit 1 |
| 74 | } |
| 75 | |
| 76 | Parametersscip-shell shell shell-project 0.0.0 Parameters(). "${@}" |
| 77 | |
| 78 | if [scip-shell system . . `[`. -z "${NAME}" ] |
| 79 | then |
| 80 | Usagescip-shell shell shell-project 0.0.0 Usage(). |
| 81 | fi |
| 82 | |
| 83 | if [scip-shell system . . `[`. ! -e "${MACHINES}/${NAME}" ] |
| 84 | then |
| 85 | echoscip-shell system . . echo. "'${NAME}': no such container" >&2 |
| 86 | exit 1 |
| 87 | fi |
| 88 | |
| 89 | # Pre hooks |
| 90 | for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}" |
| 91 | do |
| 92 | if [scip-shell system . . `[`. -x "${FILE}" ] |
| 93 | then |
| 94 | "${FILE}" |
| 95 | fi |
| 96 | done |
| 97 | |
| 98 | # Run |
| 99 | systemctl status ${PROGRAM}@${NAME}.service --full |
| 100 | |
| 101 | # Post hooks |
| 102 | for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}" |
| 103 | do |
| 104 | if [scip-shell system . . `[`. -x "${FILE}" ] |
| 105 | then |
| 106 | "${FILE}" |
| 107 | fi |
| 108 | done |