Commit f8e42140 authored by Martin Peres's avatar Martin Peres
Browse files

initscript: add the possibility to run cleanup containers

There may be some tasks that we would like to execute after containers
got executed, no matter if they succeeded or not.
parent 54a235cc
......@@ -53,6 +53,10 @@ Here is a list of options:
containers exit with the error code 0. Examples:
* b2c.container=docker://registry.hub.docker.com/library/hello-world
* b2c.container="-ti docker://registry.hub.docker.com/library/alpine:latest /bin/sh"
* b2c.post_container: Command line of a container to be executed *after* all
the `b2c.containers`, no matter how the previous container exited. This
parameter can be repeated multiple times. See `b2c.container` for the command
line format.
* b2c.cache_device: Use a cache to store the image layers, thus saving on network usage:
* none (default): Do not use any cache, guaranteeing a fresh environment every time
* auto: Re-use a previously-setup drive, or pick a suitable one, and partition it! (**WILL ERASE YOUR DATA**)
......
......@@ -47,6 +47,7 @@ function setup_env {
ARG_MODULES=""
ARG_CONTAINER=""
ARG_POST_CONTAINER=""
ARG_CACHE_DEVICE="none"
function parse_cmdline {
cmdline=$(busybox cat /proc/cmdline)
......@@ -71,6 +72,9 @@ function parse_cmdline {
b2c.container=*)
ARG_CONTAINER="$ARG_CONTAINER$value\n"
;;
b2c.post_container=*)
ARG_POST_CONTAINER="$ARG_POST_CONTAINER$value\n"
;;
esac
done
IFS=$OLDIFS
......@@ -289,6 +293,18 @@ function start_containers {
return 0
}
function start_post_containers {
log "Running the post containers"
OLDIFS=$IFS IFS=$'\n'
for container_params in $(echo -e "$@"); do
start_container "$container_params" || /bin/true
done
IFS=$OLDIFS
return 0
}
# Do not print all the early commands
set +x
......@@ -312,9 +328,10 @@ connect
# Mount the cache partition
mount_cache_partition
# Start the container
# Start the containers
setup_container_runtime
start_containers "$ARG_CONTAINER"
start_post_containers "$ARG_POST_CONTAINER"
# Emergency shell
log "Done executing the containers, dropping to an emergency shell"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment