Experiment with synit-pid1 as pid 1, with syndicate-server orchestrating

This commit is contained in:
Tony Garnock-Jones 2021-09-26 11:12:45 +02:00
parent 9441c737c1
commit bf0fa58e1f
19 changed files with 147 additions and 59 deletions

View File

@ -1,2 +1,7 @@
vmlinuz-virt
disk.img
etc_syndicate.tar.gz
initramfs-syndicate-system
newroot/
syndicate-server
synit-pid1
vmlinuz-virt

View File

@ -1,12 +1,22 @@
all: run
.PHONY: syndicate-server synit-pid1
.PHONY: all run clean veryclean veryveryclean
clean:
rm -f initramfs-syndicate-system
rm -f etc_syndicate.tar.gz
veryclean: clean
rm -f disk.img
rm -f syndicate-server synit-pid1
veryveryclean: veryclean
sudo rm -rf newroot
ALPINE_VERSION=v3.14
SYNDICATE_RS=~/src/syndicate-rs
SYNIT_PID1=$(CURDIR)/../../synit-pid1
# vmlinuz-lts:
# wget http://dl-cdn.alpinelinux.org/alpine/$(ALPINE_VERSION)/releases/aarch64/netboot/vmlinuz-lts
@ -16,9 +26,20 @@ ALPINE_VERSION=v3.14
disk.img:
qemu-img create -f qcow2 $@ 8G
initramfs-syndicate-system: pack-image.sh init.sh package-list
initramfs-syndicate-system: pack-image.sh init.sh package-list syndicate-server synit-pid1 etc_syndicate.tar.gz
sudo PACKAGES="$$(cat package-list)" ./pack-image.sh
etc_syndicate.tar.gz: etc_syndicate/*
tar -zcvf $@ etc_syndicate/*
syndicate-server:
$(MAKE) -C $(SYNDICATE_RS) aarch64-binary-release
rsync -av $(SYNDICATE_RS)/target/aarch64-unknown-linux-musl/release/syndicate-server .
synit-pid1:
$(MAKE) -C $(SYNIT_PID1) aarch64-binary-release
rsync -av $(SYNIT_PID1)/target/aarch64-unknown-linux-musl/release/synit-pid1 .
# See https://superuser.com/questions/1397991/running-alpine-linux-on-qemu-arm-guests
run: initramfs-syndicate-system disk.img
qemu-system-aarch64 \

View File

@ -0,0 +1,2 @@
<require-service <config-watcher "/run/etc/syndicate">>
<require-service <config-watcher "/usr/local/etc/syndicate">>

View File

@ -0,0 +1,2 @@
<require-service <daemon getty-console>>
<daemon getty-console "getty 115200 /dev/ttyAMA0">

View File

@ -0,0 +1,11 @@
<depends-on <milestone core> <service-running <milestone network>>>
<depends-on <milestone network> <service-running <daemon interfaces>>>
<service-milestone <daemon interfaces> boot>
<daemon interfaces "ifconfig lo 127.0.0.1 up">
<daemon interfaces "ifconfig eth0 up">
<depends-on <milestone network> <service-running <daemon udhcpc>>>
<service-milestone <daemon udhcpc> boot>
<depends-on <daemon udhcpc> <service-running <daemon interfaces>>>
<daemon udhcpc "udhcpc -i eth0 -fR">

View File

@ -0,0 +1,3 @@
<require-service <daemon core-packages>>
<depends-on <daemon core-packages> <service-running <milestone network>>>
<daemon core-packages "apk add $(cat /package-list)">

View File

@ -0,0 +1,10 @@
<require-service <daemon sshd>>
<depends-on <daemon sshd> <service-running <daemon ssh-host-keys>>>
<depends-on <daemon sshd> <service-running <daemon <install openssh>>>>
<daemon sshd "/usr/sbin/sshd -D">
<depends-on <daemon ssh-host-keys> <service-running <daemon <install openssh>>>>
<daemon ssh-host-keys "ssh-keygen -A">
<daemon <install openssh> "apk add openssh">

View File

@ -33,14 +33,7 @@ then
modprobe virtio_blk
echo "Loading btrfs."
modprobe btrfs &
echo "Configuring network."
ifconfig lo 127.0.0.1 up
ifconfig eth0 up
udhcpc -i eth0 &
wait
modprobe btrfs
echo "Attempting to mount ${ROOTDEV} on ${NEWROOT} ..."
if mount ${ROOTDEV} ${NEWROOT}
@ -48,13 +41,25 @@ then
echo "Mount successful."
else
echo "Mount unsuccessful. Building new root."
mkfs.btrfs ${ROOTDEV}
mount ${ROOTDEV} ${NEWROOT}
(
mkfs.btrfs ${ROOTDEV}
mount ${ROOTDEV} ${NEWROOT}
) &
echo "Configuring network."
(
ifconfig lo 127.0.0.1 up
ifconfig eth0 up
udhcpc -i eth0
) &
wait
apk --repositories-file /etc/apk/repositories -U --allow-untrusted \
--root ${NEWROOT} --initdb add $(cat /package-list)
fi
for f in /etc/apk/repositories /init /package-list /usr/bin/syndicate-server
for f in /etc/apk/repositories /init /package-list /sbin/syndicate-server /sbin/synit-pid1
do
echo "Updating $f."
cp -a $f ${NEWROOT}$f
@ -67,6 +72,12 @@ then
mount -o move $mp ${NEWROOT}$mp
done
echo "Setting up syndicate configuration."
rm -rf ${NEWROOT}/etc/syndicate
(cd ${NEWROOT} && tar -zxvf /etc_syndicate.tar.gz && mv etc_syndicate ${NEWROOT}/etc/syndicate)
mkdir -p ${NEWROOT}/run/etc/syndicate
mkdir -p ${NEWROOT}/usr/local/etc/syndicate
echo "Killing leftovers."
kill -15 -1
sleep 0.2
@ -76,19 +87,11 @@ then
exec switch_root -c ${CONSOLE} ${NEWROOT} /init
else
echo "Initializing with real rootfs."
echo "Re-configuring network."
ifconfig lo 127.0.0.1 up
ifconfig eth0 up
udhcpc -i eth0
echo "Ensuring installation of /package-list."
apk add $(cat /package-list)
fi
sync
echo "Dropping to shell."
# # setsid creates a "session", which allows job control to work
# exec setsid sh -c "exec sh -i <${CONSOLE} >${CONSOLE} 2>&1"
# setsid creates a "session", which allows job control to work
exec setsid sh -c "exec sh -i <${CONSOLE} >${CONSOLE} 2>&1"
RUST_LOG=trace exec /sbin/synit-pid1

View File

@ -11,8 +11,8 @@ set -xe
INITRAMFS=${INITRAMFS:-initramfs-syndicate-system}
NATIVE_COMMANDS=${NATIVE_COMMANDS:-no}
DOCKER_ARCH=${DOCKER_ARCH:-aarch64}
ALPINE_VERSION=${ALPINE_VERSION:-v3.14}
DOCKER_PLATFORM=${DOCKER_PLATFORM:-linux/arm64}
ALPINE_VERSION=${ALPINE_VERSION:-3.14}
VERSION=${VERSION:-0.1.0}
MOUNTPOINT=${MOUNTPOINT:-`pwd`/newroot}
@ -33,6 +33,8 @@ die_if_empty () {
die_if_empty PACKAGES "$PACKAGES"
die_if_empty VERSION "$VERSION"
docker pull --platform ${DOCKER_PLATFORM} alpine:${ALPINE_VERSION}
invoke_command () {
# Shell quoting is a nightmare. Beware spaces.
#
@ -44,7 +46,8 @@ invoke_command () {
echo "$@" > $tmpscript
docker run -it --rm -v `pwd`:`pwd` \
${DOCKER_PROXY_ARGS} \
multiarch/alpine:${DOCKER_ARCH}-${ALPINE_VERSION} \
--platform ${DOCKER_PLATFORM} \
alpine:${ALPINE_VERSION} \
/bin/sh -c "cd `pwd`; sh $tmpscript"
rm -f $tmpscript
fi
@ -63,8 +66,8 @@ trap cleanup 0
cat < /dev/null > ${TMP_REPO_FILE}
echo "`pwd`/apks/target/packages" >> ${TMP_REPO_FILE}
echo "https://dl-cdn.alpinelinux.org/alpine/${ALPINE_VERSION}/main" >> ${TMP_REPO_FILE}
echo "https://dl-cdn.alpinelinux.org/alpine/${ALPINE_VERSION}/community" >> ${TMP_REPO_FILE}
echo "https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION}/main" >> ${TMP_REPO_FILE}
echo "https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION}/community" >> ${TMP_REPO_FILE}
# Create root file system.
#
@ -90,11 +93,13 @@ BUILT_TIMESTAMP=$(date +%s)
COMMIT=$(git rev-parse HEAD)
EOF
cp -a syndicate-server ${MOUNTPOINT}/usr/bin/.
cp -a syndicate-server ${MOUNTPOINT}/sbin/.
cp -a synit-pid1 ${MOUNTPOINT}/sbin/.
cp -a etc_syndicate.tar.gz ${MOUNTPOINT}/.
cat > ${MOUNTPOINT}/etc/apk/repositories <<EOF
https://dl-cdn.alpinelinux.org/alpine/${ALPINE_VERSION}/main
https://dl-cdn.alpinelinux.org/alpine/${ALPINE_VERSION}/community
https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION}/main
https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION}/community
EOF
cp package-list ${MOUNTPOINT}/package-list

11
notes/boot-tasks.md Normal file
View File

@ -0,0 +1,11 @@
- set hostname
- fsck -A
- mount of the /proc-like things
- mount -a
- dhcp
- modprobes
- getty
- ssh-keygen
- sshd
- check for updates

View File

@ -114,3 +114,12 @@ source of inspiration, but I want to know more..."
> 15:03:25 < okeuday> tonyg: OTP behaviors were attributed to Lennart
> Öhman (working at Sjöland & Thyselius Telecom AB) in the past, but
> there are likely more details involved
Restart policies and lifecycles: daemontools-encore and nosh both use
stopped, starting, started, running, failed, and stopping.
(https://unix.stackexchange.com/questions/271413/is-there-a-retry-count-setting-for-svscan)
Daemontools just always restarts `./run` (after pausing 1 second). s6
is similar, but runs `./finish` if it exists, before restarting.

4
notes/statefulness.md Normal file
View File

@ -0,0 +1,4 @@
---
---
https://grahamc.com/blog/erase-your-darlings

View File

@ -1,8 +0,0 @@
all: schema-bundle.bin
clean:
rm -f schema-bundle.bin
schema-bundle.bin: schemas/*.prs
preserves-schemac schemas/*.prs > $@.tmp
mv $@.tmp $@

View File

@ -1 +1,2 @@
localdev/
target/

17
synit-pid1/Cargo.lock generated
View File

@ -590,9 +590,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "preserves"
version = "0.20.0"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca71b439b659a3fa05449daa8ac227389ae9c519a288f63d3e584a6ca6106c2f"
checksum = "cb9b4e6da51a363e60d03c2e5a2c6fd2cc501f52415c72779fd2238f28c95fc1"
dependencies = [
"base64",
"dtoa",
@ -604,9 +604,9 @@ dependencies = [
[[package]]
name = "preserves-schema"
version = "0.8.0"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b4241a53a227d239226114962024c04568504c75953d1ff74be6b8dacc4af7"
checksum = "b7fa4b81122d3bf688629f1b9c97af5061b6a1410eb805f69a836bdd1095b8ed"
dependencies = [
"convert_case",
"glob",
@ -841,14 +841,13 @@ dependencies = [
[[package]]
name = "syndicate"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a07595147fa698bc920d9e13a88c33dd7b0cb701560d44ac94b41b7faaee6aa"
version = "0.12.0"
dependencies = [
"bytes",
"futures",
"getrandom",
"hmac",
"lazy_static",
"preserves",
"preserves-schema",
"sha2",
@ -861,9 +860,7 @@ dependencies = [
[[package]]
name = "syndicate-macros"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6d9fc2bfa1af6581b041e91d4c3d65ee6e6f0a0f9d78c7c38e930d66296e459"
version = "0.7.0"
dependencies = [
"proc-macro2",
"quote",

View File

@ -9,13 +9,19 @@ homepage = "https://syndicate-lang.org/synit/"
repository = "https://git.syndicate-lang.org/syndicate-lang/syndicate-system"
license = "Apache-2.0"
# [patch.crates-io]
# syndicate = { path = "/home/tonyg/src/syndicate-rs/syndicate" }
# syndicate-macros = { path = "/home/tonyg/src/syndicate-rs/syndicate-macros" }
[patch.crates-io]
#
# Use a bind mount for localdev:
#
# mkdir localdev
# sudo mount --bind /home/tonyg/src localdev
#
syndicate = { path = "localdev/syndicate-rs/syndicate" }
syndicate-macros = { path = "localdev/syndicate-rs/syndicate-macros" }
[dependencies]
syndicate = "0.10.0"
syndicate-macros = "0.5.0"
syndicate = "0.12.0"
syndicate-macros = "0.7.0"
clap = "3.0.0-beta.2"
clap_generate = "3.0.0-beta.2"

7
synit-pid1/Makefile Normal file
View File

@ -0,0 +1,7 @@
all:
cargo build --all-targets
aarch64-binary: aarch64-binary-release
aarch64-binary-release:
cross build --target=aarch64-unknown-linux-musl --release --all-targets

View File

@ -0,0 +1 @@
nightly

View File

@ -100,10 +100,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let server = process::Command::new(&config.server_path)
.arg("--inferior")
.arg("--port")
.arg("1")
.arg("--socket")
.arg("/run/ds")
.arg("--config")
.arg("/etc/syndicate")
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
// .stderr(std::process::Stdio::null())