portable-services/alpine/simple/build.sh

39 lines
994 B
Bash
Raw Permalink Normal View History

2019-07-26 17:26:59 +02:00
#! /bin/sh
2019-07-09 18:30:30 +02:00
ROOTFS=`mktemp -d rootfs.XXX -t`
TMPDIR=/tmp
2019-07-26 17:26:59 +02:00
TARBALL=alpine-minirootfs-3.10.1-x86_64.tar.gz
URL=http://dl-cdn.alpinelinux.org/alpine/v3.10/releases/x86_64/$TARBALL
2019-07-09 18:30:30 +02:00
2019-07-26 17:26:59 +02:00
# 6. undo
sudo systemctl stop simple-test
sudo portablectl detach $TMPDIR/simple.raw
2019-07-09 18:30:30 +02:00
2019-07-26 17:26:59 +02:00
[ "$URL" ] && wget -c $URL
2019-07-09 18:30:30 +02:00
# 1. create rootfs
tar xf $TARBALL -C $ROOTFS/ \
./etc/os-release ./usr ./lib ./bin ./sbin
# 2. create mount points
2019-07-26 17:26:59 +02:00
chmod 755 $ROOTFS
mkdir -p $ROOTFS/etc/systemd/system $ROOTFS/{proc,sys,dev,run,tmp,var/tmp}
2019-07-09 18:30:30 +02:00
touch $ROOTFS/etc/machine-id $ROOTFS/etc/resolv.conf
# 3. simple service unit
2019-07-26 17:26:59 +02:00
cat <<EOF > $ROOTFS/etc/systemd/system/simple-test.service
2019-07-09 18:30:30 +02:00
[Unit]
Description=Simple portable test service
[Service]
Type=exec
ExecStart=/bin/sh -c 'while /bin/sleep 5; do echo ping; done'
EOF
# 4. create a read-only squashfs rootfs image
mksquashfs $ROOTFS $TMPDIR/simple.raw -all-root -noappend
# 5. attach and start the service
sudo portablectl attach $TMPDIR/simple.raw
sudo systemctl start simple-test