Debian Codegraph @

libexec/container/status

raw symbols SCIP
1 #!/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="$(basename ${0})"
26
27 CONFIG="/etc/${SOFTWARE}/config"
28 HOOKS="/etc/${SOFTWARE}/hooks"
29 MACHINES="/var/lib/machines"
30
31 Parameters ()
32 {
33 GETOPT_LONGOPTIONS="name:,"
34 GETOPT_OPTIONS="n:,"
35
36 PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})"
37
38 if [ "${?}" != "0" ]
39 then
40 echo "'${COMMAND}': getopt exit" >&2
41 exit 1
42 fi
43
44 eval set -- "${PARAMETERS}"
45
46 while 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 echo "'${COMMAND}': getopt error" >&2
61 exit 1
62 ;;
63 esac
64 done
65 }
66
67 Usage ()
68 {
69 echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME" >&2
70 echo
71 echo "See ${COMMAND}(1), ${PROGRAM}(1) and ${PROJECT}(7) for more information."
72
73 exit 1
74 }
75
76 Parameters "${@}"
77
78 if [ -z "${NAME}" ]
79 then
80 Usage
81 fi
82
83 if [ ! -e "${MACHINES}/${NAME}" ]
84 then
85 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 [ -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 [ -x "${FILE}" ]
105 then
106 "${FILE}"
107 fi
108 done