Debian Codegraph @

libexec/container/restart

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 # Copyright (C) 2014-2026 Daniel Baumann <[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 HOOKS="/etc/${SOFTWARE}/hooks"
28 MACHINES="/var/lib/machinesscip-shell filesystem . . `/var/lib/machines`."
29
30 Parametersscip-shell shell shell-project 0.0.0 Parameters(). ()
31 {
32 OPTIONS_ALL=""
33
34 GETOPT_LONGOPTIONS="name:,force,interactive,verbose,"
35 GETOPT_OPTIONS="n:,f,i,v,"
36
37 PARAMETERS="$(getoptscip-shell system . . getopt. --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})"
38
39 if [scip-shell system . . `[`. "${?}" != "0" ]
40 then
41 echoscip-shell system . . echo. "'${COMMAND}': getopt exit" >&2
42 exit 1
43 fi
44
45 eval set -- "${PARAMETERS}"
46
47 while truescip-shell system . . true.
48 do
49 case "${1}" in
50 -n|--name)
51 NAME="${2}"
52 shift 2
53 ;;
54
55 -f|--force)
56 FORCE="true"
57 shift 1
58
59 OPTIONS_ALL="${OPTIONS_ALL} --force"
60 ;;
61
62 -i|--interactive)
63 INTERACTIVE="true"
64 shift 1
65
66 OPTIONS_ALL="${OPTIONS_ALL} --interactive"
67 ;;
68
69 -v|--verbose)
70 VERBOSE="true"
71 shift 1
72
73 OPTIONS_ALL="${OPTIONS_ALL} --verbose"
74 ;;
75
76 --)
77 shift 1
78 break
79 ;;
80
81 *)
82 echoscip-shell system . . echo. "'${COMMAND}': getopt error" >&2
83 exit 1
84 ;;
85 esac
86 done
87 }
88
89 Usagescip-shell shell shell-project 0.0.0 Usage(). ()
90 {
91 echoscip-shell system . . echo. "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [-f|--force] [-i|--interactive] [-v|--verbose]" >&2
92 echoscip-shell system . . echo.
93 echoscip-shell system . . echo. "See ${COMMAND}(1), ${PROGRAM}(1) and ${PROJECT}(7) for more information."
94
95 exit 1
96 }
97
98 Parametersscip-shell shell shell-project 0.0.0 Parameters(). "${@}"
99
100 if [scip-shell system . . `[`. -z "${NAME}" ]
101 then
102 Usagescip-shell shell shell-project 0.0.0 Usage().
103 fi
104
105 case "${NAME}" in
106 ALL)
107 NAMES="$(${PROGRAM} list --format shell --started)"
108
109 for NAME in ${NAMES}
110 do
111 ${PROGRAM} restart --name ${NAME} ${OPTIONS_ALL} || truescip-shell system . . true.
112 done
113
114 exit 0
115 ;;
116 esac
117
118 if [scip-shell system . . `[`. ! -e "${MACHINES}/${NAME}" ]
119 then
120 echoscip-shell system . . echo. "'${NAME}': no such container" >&2
121 exit 1
122 fi
123
124 if [scip-shell system . . `[`. "${FORCE}" != "true" ] || [scip-shell system . . `[`. "${INTERACTIVE}" = "true" ]
125 then
126 echoscip-shell system . . echo. -n "'${NAME}': restart container '${NAME}' [y|N]? "
127 read STOP
128
129 STOP="$(echoscip-shell system . . echo. ${STOP} | trscip-shell system . . tr. '[A-Z]' '[a-z]')"
130
131 case "${STOP}" in
132 y|yes)
133 ;;
134
135 *)
136 exit 1
137 ;;
138 esac
139 fi
140
141 # Pre hooks
142 for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
143 do
144 if [scip-shell system . . `[`. -x "${FILE}" ]
145 then
146 "${FILE}"
147 fi
148 done
149
150 # Run
151 case "${VERBOSE}" in
152 true)
153 echoscip-shell system . . echo. -n "Restarting container ${NAME}..."
154 ;;
155 esac
156
157 machinectl reboot ${NAME}
158
159 case "${VERBOSE}" in
160 true)
161 echoscip-shell system . . echo. " done."
162 ;;
163 esac
164
165 # Post hooks
166 for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
167 do
168 if [scip-shell system . . `[`. -x "${FILE}" ]
169 then
170 "${FILE}"
171 fi
172 done