diff --git a/Dockerfile b/Dockerfile index 113c6599db1..98d5a4cd410 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,8 @@ LABEL maintainer="Steven Allen " RUN apt-get update && apt-get install -y \ libssl-dev \ ca-certificates \ - fuse + fuse \ + bash-static ENV SRC_DIR /go-ipfs @@ -72,6 +73,9 @@ COPY --from=0 /lib/*-linux-gnu*/libdl.so.2 /lib/ COPY --from=0 /usr/lib/*-linux-gnu*/libssl.so* /usr/lib/ COPY --from=0 /usr/lib/*-linux-gnu*/libcrypto.so* /usr/lib/ +# Bash shell for ERR signals +COPY --from=0 /bin/bash-static /bin/bash + # Swarm TCP; should be exposed to the public EXPOSE 4001 # Swarm UDP; should be exposed to the public diff --git a/bin/container_daemon b/bin/container_daemon index 8fe429036a7..93411339fe4 100755 --- a/bin/container_daemon +++ b/bin/container_daemon @@ -1,8 +1,22 @@ -#!/bin/sh +#!/bin/bash set -e user=ipfs repo="$IPFS_PATH" +init_scripts() { + trap 'kill $$' ERR # Kill parent if init fail + local scripts_path=$1 + + if [ -d ${scripts_path} ]; then + for script in ${scripts_path}/*.sh; do + echo "==== Running $script" + # Prevent failure if no +x is set on file + cat $script | sh -e + done + fi + +} + if [ `id -u` -eq 0 ]; then echo "Changing user to $user" # ensure folder is writable @@ -51,6 +65,12 @@ else # Unset the swarm key file variable unset IPFS_SWARM_KEY_FILE + # Pre-hook init with scripts + init_scripts /docker-prehook.d + + # Post-hook init scripts + { sleep 10; init_scripts /docker-posthook.d ; } & + fi exec ipfs "$@"