rbm.conf: Handle SIGINT case

This commit is contained in:
Jeremy Rand 2021-02-18 21:58:33 +00:00
parent a72f41b5a3
commit 0c1c248443
No known key found for this signature in database
GPG Key ID: FD7550C2EB800711

View File

@ -504,6 +504,18 @@ runc:
remote_start: | remote_start: |
#!/bin/sh #!/bin/sh
set -e set -e
# Handle SIGINT case
if [ -d '[% c("rbm_tmp_dir") %]'/../interrupted_dirs/'[% c("var/build_id") %]' ]
then
# We previously did this build but it was manually interrupted.
# Restore the container's saved state instead of making a new container.
mkdir -p '[% c("var/container/dir") %]'
rmdir '[% c("var/container/dir") %]'
mv '[% c("rbm_tmp_dir") %]'/../interrupted_dirs/'[% c("var/build_id") %]' '[% c("var/container/dir") %]'
exit
fi
if [ $(ls -1 '[% c("remote_srcdir", { error_if_undef => 1 }) %]/container-image_'* | wc -l) -ne 1 ] if [ $(ls -1 '[% c("remote_srcdir", { error_if_undef => 1 }) %]/container-image_'* | wc -l) -ne 1 ]
then then
echo "Can't find container image in input files" >&2 echo "Can't find container image in input files" >&2
@ -580,6 +592,19 @@ runc:
remote_finish: | remote_finish: |
#!/bin/sh #!/bin/sh
set -e set -e
# Handle SIGINT case
if [ -e '[% c("rbm_tmp_dir") %]'/../interrupted ]
then
# This build was manually interrupted via tools/container-interrupt.sh.
# Save the container's state instead of deleting, so we can resume
# the build later.
mkdir -p '[% c("rbm_tmp_dir") %]'/../interrupted_dirs
mv '[% c("var/container/dir") %]' '[% c("rbm_tmp_dir") %]'/../interrupted_dirs/'[% c("var/build_id") %]'
rm '[% c("rbm_tmp_dir") %]'/../interrupted
exit
fi
sudo rm -Rf '[% c("var/container/dir", { error_if_undef => 1 }) %]'/rootfs '[% c("var/container/dir", { error_if_undef => 1 }) %]'/config.json sudo rm -Rf '[% c("var/container/dir", { error_if_undef => 1 }) %]'/rootfs '[% c("var/container/dir", { error_if_undef => 1 }) %]'/config.json
rmdir '[% c("var/container/dir") %]' rmdir '[% c("var/container/dir") %]'