github.com/jiasir/deis@v1.12.2/builder/rootfs/bin/entry (about)

     1  #!/usr/bin/env bash
     2  set -eo pipefail
     3  
     4  if [[ -f /etc/environment_proxy ]]; then
     5  	source /etc/environment_proxy
     6  fi
     7  
     8  # START jpetazzo/dind wrapper
     9  
    10  # DinD: a wrapper script which allows docker to be run inside a docker container.
    11  # Original version by Jerome Petazzoni <jerome@docker.com>
    12  # See the blog post: https://blog.docker.com/2013/09/docker-can-now-run-within-docker/
    13  #
    14  # This script should be executed inside a docker container in privilieged mode
    15  # ('docker run --privileged', introduced in docker 0.6).
    16  
    17  # Usage: dind CMD [ARG...]
    18  
    19  # apparmor sucks and Docker needs to know that it's in a container (c) @tianon
    20  export container=docker
    21  
    22  # as of docker 1.8, cgroups will be mounted in the container
    23  if ! mountpoint -q /sys/fs/cgroup; then
    24  
    25  	# First, make sure that cgroups are mounted correctly.
    26  	CGROUP=/cgroup
    27  
    28  	mkdir -p "$CGROUP"
    29  
    30  	if ! mountpoint -q "$CGROUP"; then
    31  		mount -n -t tmpfs -o uid=0,gid=0,mode=0755 cgroup $CGROUP || {
    32  			echo >&2 'Could not make a tmpfs mount. Did you use --privileged?'
    33  			exit 1
    34  		}
    35  	fi
    36  
    37  	# Mount the cgroup hierarchies exactly as they are in the parent system.
    38  	for HIER in $(cut -d: -f2 /proc/1/cgroup); do
    39  
    40  		# The following sections address a bug which manifests itself
    41  		# by a cryptic "lxc-start: no ns_cgroup option specified" when
    42  		# trying to start containers within a container.
    43  		# The bug seems to appear when the cgroup hierarchies are not
    44  		# mounted on the exact same directories in the host, and in the
    45  		# container.
    46  
    47  		SUBSYSTEMS="${HIER%name=*}"
    48  
    49  		# If cgroup hierarchy is named(mounted with "-o name=foo") we
    50  		# need to mount it in $CGROUP/foo to create exect same
    51  		# directoryes as on host. Else we need to mount it as is e.g.
    52  		# "subsys1,subsys2" if it has two subsystems
    53  
    54  		# Named, control-less cgroups are mounted with "-o name=foo"
    55  		# (and appear as such under /proc/<pid>/cgroup) but are usually
    56  		# mounted on a directory named "foo" (without the "name=" prefix).
    57  		# Systemd and OpenRC (and possibly others) both create such a
    58  		# cgroup. So just mount them on directory $CGROUP/foo.
    59  
    60  		OHIER=$HIER
    61  		HIER="${HIER#*name=}"
    62  
    63  		mkdir -p "$CGROUP/$HIER"
    64  
    65  		if ! mountpoint -q "$CGROUP/$HIER"; then
    66  			mount -n -t cgroup -o "$OHIER" cgroup "$CGROUP/$HIER"
    67  		fi
    68  
    69  		# Likewise, on at least one system, it has been reported that
    70  		# systemd would mount the CPU and CPU accounting controllers
    71  		# (respectively "cpu" and "cpuacct") with "-o cpuacct,cpu"
    72  		# but on a directory called "cpu,cpuacct" (note the inversion
    73  		# in the order of the groups). This tries to work around it.
    74  
    75  		if [ "$HIER" = 'cpuacct,cpu' ]; then
    76  			ln -s "$HIER" "$CGROUP/cpu,cpuacct"
    77  		fi
    78  
    79  		# If hierarchy has multiple subsystems, in /proc/<pid>/cgroup
    80  		# we will see ":subsys1,subsys2,subsys3,name=foo:" substring,
    81  		# we need to mount it to "$CGROUP/foo" and if there were no
    82  		# name to "$CGROUP/subsys1,subsys2,subsys3", so we must create
    83  		# symlinks for docker daemon to find these subsystems:
    84  		# ln -s $CGROUP/foo $CGROUP/subsys1
    85  		# ln -s $CGROUP/subsys1,subsys2,subsys3 $CGROUP/subsys1
    86  
    87  		if [ "$SUBSYSTEMS" != "${SUBSYSTEMS//,/ }" ]; then
    88  			SUBSYSTEMS="${SUBSYSTEMS//,/ }"
    89  			for SUBSYS in $SUBSYSTEMS
    90  			do
    91  				ln -s "$CGROUP/$HIER" "$CGROUP/$SUBSYS"
    92  			done
    93  		fi
    94  	done
    95  fi
    96  
    97  if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security; then
    98  	mount -t securityfs none /sys/kernel/security || {
    99  		echo >&2 'Could not mount /sys/kernel/security.'
   100  		echo >&2 'AppArmor detection and --privileged mode might break.'
   101  	}
   102  fi
   103  
   104  # Note: as I write those lines, the LXC userland tools cannot setup
   105  # a "sub-container" properly if the "devices" cgroup is not in its
   106  # own hierarchy. Let's detect this and issue a warning.
   107  if ! grep -q :devices: /proc/1/cgroup; then
   108  	echo >&2 'WARNING: the "devices" cgroup should be in its own hierarchy.'
   109  fi
   110  if ! grep -qw devices /proc/1/cgroup; then
   111  	echo >&2 'WARNING: it looks like the "devices" cgroup is not mounted.'
   112  fi
   113  
   114  # Mount /tmp (conditionally)
   115  if ! mountpoint -q /tmp; then
   116  	mount -t tmpfs none /tmp
   117  fi
   118  
   119  if [ $# -gt 0 ]; then
   120  	exec "$@"
   121  fi
   122  
   123  echo >&2 'ERROR: No command specified.'
   124  echo >&2 'You probably want to run hack/make.sh, or maybe a shell?'
   125  # END jpetazzo/dind wrapper