Last active
February 2, 2017 03:14
-
-
Save s4s0l/4b472a6e3c32d0d26e13ae58020d5ec2 to your computer and use it in GitHub Desktop.
Trapping signals in bash 4 docker, detecting -ti interactive option present or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
DAEMONPID=0 | |
trap 'echo SIGTERM; kill ${!}; kill $DAEMONPID; exit 143' SIGTERM | |
trap 'echo SIGKILL; kill ${!}; kill $DAEMONPID; exit 137' SIGKILL | |
trap 'echo SIGINT; kill ${!}; kill $DAEMONPID; exit 130' INT | |
dockerd --host=unix:///var/run/docker.sock --storage-driver=vfs & | |
DAEMONPID="$!" | |
while true; do | |
docker version && break | |
sleep 1 | |
done | |
if [ -z ${RUNASUID+x} ]; then | |
if [ ! -t 1 ]; then | |
su -c "$*" & wait ${!} | |
else | |
su -c "$*" | |
fi | |
else | |
addgroup -g 997 docker | |
chgrp docker /var/run/docker.sock | |
adduser -u ${RUNASUID} -s /bin/bash -G docker -D user user | |
if [ ! -t 1 ]; then | |
su user -c "$*" & wait ${!} | |
else | |
su user -c "$*" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment