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

initscript: add a b2c.pipefail parameter



Up until now, chained containers would execute one after the other as
long as they would have the exit code 0. Let's change that to ignoring
the exit code, and allow the user to set b2c.pipefail to restore the
previous behaviour.

This is to mimic what shell scripts are doing, and thus be less of a
surprise to users.
Suggested-by: Charlie Turner's avatarCharlie Turner <cturner@igalia.com>
parent 251c4860
......@@ -51,8 +51,7 @@ Here is the list of available options:
* **b2c.container**: Command line of a container to be executed at boot.
Format: See [podman's image format](https://docs.podman.io/en/latest/markdown/podman-run.1.html#image).
If you set this parameter multiple times, the containers will be executed one
after the other, in the same order as they are specified, as long as the
containers exit with the error code 0. Examples:
after the other, in the same order as they are specified. 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
......@@ -68,6 +67,8 @@ Here is the list of available options:
following values:
* none (default): Do not set the time at boot
* auto: Use `pool.ntp.org` as a peer
* **b2c.pipefail**: Stop executing containers as soon as one returns the
status code 0. This only affects `b2c.container`, not `b2c.post_container`.
* **b2c.shutdown_cmd**: Once the execution of all the containers is over,
execute this command. Default: `poweroff -f`
......
......@@ -69,11 +69,12 @@ function setup_env {
export HOME=/root
}
ARG_MODULES=""
ARG_CONTAINER=""
ARG_POST_CONTAINER=""
ARG_CACHE_DEVICE="none"
ARG_CONTAINER=""
ARG_MODULES=""
ARG_NTP_PEER="none"
ARG_PIPEFAIL="0"
ARG_POST_CONTAINER=""
ARG_SHUTDOWN_CMD="poweroff -f"
function parse_cmdline {
cmdline=$(busybox cat /proc/cmdline)
......@@ -101,6 +102,9 @@ function parse_cmdline {
b2c.post_container=*)
ARG_POST_CONTAINER="$ARG_POST_CONTAINER$value\n"
;;
b2c.pipefail)
ARG_PIPEFAIL="1"
;;
b2c.ntp_peer=*)
ARG_NTP_PEER=$value
;;
......@@ -357,8 +361,12 @@ function start_containers {
B2C_PIPELINE_FAILED_BY="$container_params"
fi
log "The container exited with error code $exit_code, aborting..."
return 0
if [ $ARG_PIPEFAIL -eq 1 ]; then
log "The container exited with error code $exit_code, aborting the pipeline..."
return 0
else
log "The container exited with error code $exit_code, continuing..."
fi
fi
done
IFS=$OLDIFS
......
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