mirror of
				https://github.com/linuxkit/linuxkit.git
				synced 2025-11-04 09:25:58 +00:00 
			
		
		
		
	fix process startup, now runs docker correctly
Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
This commit is contained in:
		@@ -38,6 +38,7 @@ RUN \
 | 
			
		||||
  rc-update add 9pinit default && \
 | 
			
		||||
  rc-update add 9pudc default && \
 | 
			
		||||
  rc-update add mdnstool default && \
 | 
			
		||||
  rc-update add automount boot && \
 | 
			
		||||
  ln -s /bin/busybox /init
 | 
			
		||||
 | 
			
		||||
# docker mac specific, should be packages
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,10 @@ all:	initrd.img
 | 
			
		||||
 | 
			
		||||
ETCFILES=etc/issue etc/motd etc/inittab etc/network/interfaces
 | 
			
		||||
ETCFILES+=etc/hostname- etc/resolv.conf- etc/hosts-
 | 
			
		||||
ETCFILES+=etc/init.d/chronyd etc/init.d/9pinit etc/init.d/9pudc etc/init.d/mdnstool
 | 
			
		||||
ETCFILES+=etc/init.d/chronyd
 | 
			
		||||
ETCFILES+=etc/init.d/9pinit etc/init.d/9pudc etc/init.d/mdnstool
 | 
			
		||||
ETCFILES+=etc/init.d/automount
 | 
			
		||||
ETCFILES+=etc/conf.d/docker
 | 
			
		||||
 | 
			
		||||
initrd.img: Dockerfile mkinitrd.sh repositories $(ETCFILES)
 | 
			
		||||
	rm -f initrd.img
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								alpine/etc/conf.d/docker
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								alpine/etc/conf.d/docker
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
# /etc/conf.d/docker
 | 
			
		||||
 | 
			
		||||
export DOCKER_RAMDISK="true"
 | 
			
		||||
@@ -13,11 +13,12 @@ start()
 | 
			
		||||
 | 
			
		||||
	[ -n "${PIDFILE}" ] || PIDFILE=/var/run/9pudc.pid
 | 
			
		||||
 | 
			
		||||
	start-stop-daemon --start --quiet \
 | 
			
		||||
		--exec /sbin/9pudc \
 | 
			
		||||
		--pidfile "${PIDFILE}" \
 | 
			
		||||
		-- -path /Socket -sock /var/run/docker.sock -detach
 | 
			
		||||
	eend $? "Failed to start 9pudc"
 | 
			
		||||
#	start-stop-daemon --start --quiet \
 | 
			
		||||
#		--exec /sbin/9pudc \
 | 
			
		||||
#		--pidfile "${PIDFILE}" \
 | 
			
		||||
#		-- -path /Socket -sock /var/run/docker.sock
 | 
			
		||||
#	eend $? "Failed to start 9pudc"
 | 
			
		||||
	/sbin/9pudc -path /Socket -sock /var/run/docker.sock -detach &
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
stop()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										134
									
								
								alpine/etc/init.d/automount
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										134
									
								
								alpine/etc/init.d/automount
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,134 @@
 | 
			
		||||
#!/sbin/openrc-run
 | 
			
		||||
 | 
			
		||||
# script taken from boot2docker TODO customise for Moby
 | 
			
		||||
 | 
			
		||||
start()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
ebegin "Mounting external drives"
 | 
			
		||||
 | 
			
		||||
LABEL=boot2docker-data
 | 
			
		||||
MAGIC="boot2docker, please format-me"
 | 
			
		||||
 | 
			
		||||
# If there is a partition with `boot2docker-data` as its label, use it and be
 | 
			
		||||
# very happy. Thus, you can come along if you feel like a room without a roof.
 | 
			
		||||
BOOT2DOCKER_DATA=`blkid -o device -l -t LABEL=$LABEL`
 | 
			
		||||
echo $BOOT2DOCKER_DATA
 | 
			
		||||
if [ ! -n "$BOOT2DOCKER_DATA" ]; then
 | 
			
		||||
    echo "Is the disk unpartitioned?, test for the 'boot2docker format-me' string"
 | 
			
		||||
    
 | 
			
		||||
    # Is the disk unpartitioned?, test for the 'boot2docker format-me' string
 | 
			
		||||
    UNPARTITIONED_HD=`fdisk -l | grep "doesn't contain a valid partition table" | head -n 1 | sed 's/Disk \(.*\) doesn.*/\1/'`
 | 
			
		||||
 | 
			
		||||
    if [ -n "$UNPARTITIONED_HD" ]; then
 | 
			
		||||
        # Test for our magic string (it means that the disk was made by ./boot2docker init)
 | 
			
		||||
        HEADER=`dd if=$UNPARTITIONED_HD bs=1 count=${#MAGIC} 2>/dev/null`
 | 
			
		||||
 | 
			
		||||
        if [ "$HEADER" = "$MAGIC" ]; then
 | 
			
		||||
            # save the preload userdata.tar file
 | 
			
		||||
            dd if=$UNPARTITIONED_HD of=/userdata.tar bs=1 count=4096 2>/dev/null
 | 
			
		||||
            # Create the partition, format it and then mount it
 | 
			
		||||
            echo "NEW boot2docker managed disk image ($UNPARTITIONED_HD): formatting it for use"
 | 
			
		||||
            echo "NEW boot2docker managed disk image ($UNPARTITIONED_HD): formatting it for use" > /home/docker/log.log
 | 
			
		||||
 | 
			
		||||
            # Add a swap partition (so Docker doesn't complain about it missing)
 | 
			
		||||
            (echo n; echo p; echo 2; echo ; echo +1000M ; echo w) | fdisk $UNPARTITIONED_HD
 | 
			
		||||
            # Let kernel re-read partition table
 | 
			
		||||
            partprobe
 | 
			
		||||
            (echo t; echo 82; echo w) | fdisk $UNPARTITIONED_HD
 | 
			
		||||
            # Let kernel re-read partition table
 | 
			
		||||
            partprobe
 | 
			
		||||
            mkswap "${UNPARTITIONED_HD}2"
 | 
			
		||||
            # Add the data partition
 | 
			
		||||
            (echo n; echo p; echo 1; echo ; echo ; echo w) | fdisk $UNPARTITIONED_HD
 | 
			
		||||
            # Let kernel re-read partition table
 | 
			
		||||
            partprobe
 | 
			
		||||
            BOOT2DOCKER_DATA=`echo "${UNPARTITIONED_HD}1"`
 | 
			
		||||
            mkfs.ext4 -L $LABEL $BOOT2DOCKER_DATA
 | 
			
		||||
            swapon "${UNPARTITIONED_HD}2"
 | 
			
		||||
        fi
 | 
			
		||||
 | 
			
		||||
        DISK_VENDOR=$(cat /sys/class/block/$(basename $UNPARTITIONED_HD /dev/)/device/vendor /sys/class/block/$(basename $UNPARTITIONED_HD /dev/)/device/model | tr -d "\n")
 | 
			
		||||
        # Test if disk is "VMware, VMware Virtual S" and empty.
 | 
			
		||||
        if [ "$DISK_VENDOR" = "VMware, VMware Virtual S" ] || [ "$DISK_VENDOR" = "VMware  Virtual disk    " ]; then
 | 
			
		||||
            # Check whether the disk has any known partitions on it
 | 
			
		||||
            blkid -o device $UNPARTITIONED_HD
 | 
			
		||||
            if [ $? == 2 ]; then
 | 
			
		||||
                # As there are no partitions, let's make sure the disk is empty for real
 | 
			
		||||
                dd if=$UNPARTITIONED_HD of=device_test_file bs=1k count=256 > /dev/null 2>&1
 | 
			
		||||
                NON_NUL=$(<device_test_file tr -d '\0\n' | wc -c)
 | 
			
		||||
                if [ $NON_NUL == 0 ]; then                    
 | 
			
		||||
                    # Create the partition, format it and then mount it
 | 
			
		||||
                    echo "NEW VMware boot2docker managed disk image ($UNPARTITIONED_HD): formatting it for use"
 | 
			
		||||
                    echo "NEW VMware boot2docker managed disk image ($UNPARTITIONED_HD): formatting it for use" > /home/docker/log.log
 | 
			
		||||
 | 
			
		||||
                    # Add a swap partition (so Docker doesn't complain about it missing)
 | 
			
		||||
                    (echo n; echo p; echo 2; echo ; echo +1000M ; echo w) | fdisk $UNPARTITIONED_HD
 | 
			
		||||
                    (echo t; echo 82) | fdisk $UNPARTITIONED_HD
 | 
			
		||||
                    mkswap "${UNPARTITIONED_HD}2"
 | 
			
		||||
                    # Add the data partition
 | 
			
		||||
                    (echo n; echo p; echo 1; echo ; echo ; echo w) | fdisk $UNPARTITIONED_HD
 | 
			
		||||
                    BOOT2DOCKER_DATA=`echo "${UNPARTITIONED_HD}1"`
 | 
			
		||||
                    mkfs.ext4 -L $LABEL $BOOT2DOCKER_DATA
 | 
			
		||||
                    swapon "${UNPARTITIONED_HD}2"
 | 
			
		||||
                else
 | 
			
		||||
                    echo "Disk unpartitioned but something is there... not doing anything"
 | 
			
		||||
                fi
 | 
			
		||||
            else
 | 
			
		||||
                echo "Partition table found on disk, not doing anything"
 | 
			
		||||
            fi
 | 
			
		||||
        fi
 | 
			
		||||
    else
 | 
			
		||||
        # Pick the first ext4 as a fallback
 | 
			
		||||
        # TODO: mount all Linux partitions and look for a /var/lib/docker...
 | 
			
		||||
        BOOT2DOCKER_DATA=`blkid | grep -e 'TYPE="btrfs"'  -e 'TYPE="ext4"' | head -n 1 | sed 's/:.*//'`
 | 
			
		||||
    fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
echo $BOOT2DOCKER_DATA
 | 
			
		||||
 | 
			
		||||
if [ -n "$BOOT2DOCKER_DATA" ]; then
 | 
			
		||||
    PARTNAME=`echo "$BOOT2DOCKER_DATA" | sed 's/.*\///'`
 | 
			
		||||
    echo "mount p:$PARTNAME ..."
 | 
			
		||||
    mkdir -p /mnt/$PARTNAME
 | 
			
		||||
    if ! mount $BOOT2DOCKER_DATA /mnt/$PARTNAME 2>/dev/null; then
 | 
			
		||||
        # for some reason, mount doesn't like to modprobe btrfs
 | 
			
		||||
        BOOT2DOCKER_FSTYPE=`blkid -o export $BOOT2DOCKER_DATA | grep TYPE= | cut -d= -f2`
 | 
			
		||||
        modprobe $BOOT2DOCKER_FSTYPE || true
 | 
			
		||||
        umount -f /mnt/$PARTNAME || true
 | 
			
		||||
        mount $BOOT2DOCKER_DATA /mnt/$PARTNAME
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    # Just in case, the links will fail if not
 | 
			
		||||
    umount -f /var/lib/docker || true
 | 
			
		||||
    rm -rf /var/lib/docker /var/lib/boot2docker
 | 
			
		||||
    if [ -d /mnt/$PARTNAME/vm ]; then
 | 
			
		||||
        # The old behavior - use the entire disk for boot2docker data
 | 
			
		||||
        ln -s /mnt/$PARTNAME /var/lib/docker
 | 
			
		||||
 | 
			
		||||
        # Give us a link to the new cusomisation location
 | 
			
		||||
        ln -s /var/lib/docker/vm /var/lib/boot2docker
 | 
			
		||||
    else
 | 
			
		||||
        # Detected a disk with a normal linux install (/var/lib/docker + more))
 | 
			
		||||
        mkdir -p /var/lib
 | 
			
		||||
 | 
			
		||||
        mkdir -p /mnt/$PARTNAME/var/lib/docker
 | 
			
		||||
        ln -s /mnt/$PARTNAME/var/lib/docker /var/lib/docker
 | 
			
		||||
 | 
			
		||||
        mkdir -p /mnt/$PARTNAME/var/lib/boot2docker
 | 
			
		||||
        ln -s /mnt/$PARTNAME/var/lib/boot2docker /var/lib/boot2docker
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    # Make sure /tmp is on the disk too
 | 
			
		||||
    rm -rf /mnt/$PARTNAME/tmp || true
 | 
			
		||||
    mv /tmp /mnt/$PARTNAME/tmp
 | 
			
		||||
    ln -fs /mnt/$PARTNAME/tmp /tmp
 | 
			
		||||
 | 
			
		||||
    if [ -e "/userdata.tar" ]; then
 | 
			
		||||
        mv /userdata.tar /var/lib/boot2docker/
 | 
			
		||||
    fi
 | 
			
		||||
    
 | 
			
		||||
    ls -l /mnt/$PARTNAME
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -14,11 +14,12 @@ start()
 | 
			
		||||
 | 
			
		||||
	[ -n "${PIDFILE}" ] || PIDFILE=/var/run/mdnstool.pid
 | 
			
		||||
 | 
			
		||||
	start-stop-daemon --start --quiet \
 | 
			
		||||
		--exec /sbin/mdnstool \
 | 
			
		||||
		--pidfile "${PIDFILE}" \
 | 
			
		||||
		-- if eth0 -detach
 | 
			
		||||
	eend $? "Failed to start mDNS server"
 | 
			
		||||
#	start-stop-daemon --start --quiet \
 | 
			
		||||
#		--exec /sbin/mdnstool \
 | 
			
		||||
#		--pidfile "${PIDFILE}" \
 | 
			
		||||
#		-- if eth0
 | 
			
		||||
#	eend $? "Failed to start mDNS server"
 | 
			
		||||
	/sbin/mdnstool if eth0 -detach &
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
stop()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user