1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515
16+ usage () {
17+ cat << EOF
18+ Usage: $( basename " $0 " ) [-a APP_ROOT] [-h]
19+
20+ Install the init image for container system.
21+
22+ Options:
23+ -a APP_ROOT Install the init image under the APP_ROOT path
24+ -h Show this help message
25+
26+ EOF
27+ exit 0
28+ }
29+
30+ # Parse command line options
31+ APP_ROOT=" "
32+ while getopts " a:h" opt; do
33+ case $opt in
34+ a)
35+ APP_ROOT=" $OPTARG "
36+ ;;
37+ h)
38+ usage
39+ ;;
40+ \? )
41+ echo " Invalid option: -$OPTARG " >&2
42+ usage
43+ ;;
44+ :)
45+ echo " Option -$OPTARG requires an argument." >&2
46+ usage
47+ ;;
48+ esac
49+ done
50+
1651SWIFT=" /usr/bin/swift"
1752IMAGE_NAME=" vminit:latest"
18- DEST_DIR=" ${1:- $(git rev-parse --show-toplevel)/ bin} "
19- mkdir -p " ${DEST_DIR} "
2053
2154CONTAINERIZATION_VERSION=" $( ${SWIFT} package show-dependencies --format json | jq -r ' .dependencies[] | select(.identity == "containerization") | .version' ) "
2255if [ " ${CONTAINERIZATION_VERSION} " == " unspecified" ] ; then
@@ -28,8 +61,15 @@ if [ "${CONTAINERIZATION_VERSION}" == "unspecified" ] ; then
2861 echo " Creating InitImage"
2962 make -C ${CONTAINERIZATION_PATH} init
3063 ${CONTAINERIZATION_PATH} /bin/cctl images save -o /tmp/init.tar ${IMAGE_NAME}
64+
3165 # Sleep because commands after stop and start are racy.
32- bin/container system stop && sleep 3 && bin/container system start && sleep 3
66+ bin/container system stop && sleep 3
67+ if [ -n " $APP_ROOT " ]; then
68+ bin/container system start --app-root " $APP_ROOT "
69+ else
70+ bin/container system start
71+ fi
72+ sleep 3
3373 bin/container i load -i /tmp/init.tar
3474 rm /tmp/init.tar
3575fi
0 commit comments