aboutsummaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-03-25 15:03:59 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-03-25 15:03:59 +0200
commit864fc1c2e0597606ec8e2e04ae3150144aa3ed39 (patch)
tree640a3ad90260881937fad6a3ca675522b2fa0879 /bootstrap
parent0ba253ef6926d2f8bf403f9b96ca9120d0022861 (diff)
Add buildos monitor
Diffstat (limited to 'bootstrap')
-rwxr-xr-xbootstrap42
1 files changed, 29 insertions, 13 deletions
diff --git a/bootstrap b/bootstrap
index d2c2be0..16b42b5 100755
--- a/bootstrap
+++ b/bootstrap
@@ -140,7 +140,7 @@ if [ "$stage" -eq "1" ]; then
#
# - systemd-container seems to be required by host systemd-nspawn.
#
- pkgs="locales,klibc-utils,systemd-container"
+ pkgs="locales,klibc-utils,sudo,systemd-container"
pkgs+=",linux-image-amd64,irqbalance,pciutils"
@@ -281,6 +281,12 @@ trap "exit 1" ERR
set -x
+# Create the build user, /build home directory. Make a password-less sudo'er.
+#
+adduser --home /build --gecos "" --disabled-password build
+echo "build ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/build
+chmod 0440 /etc/sudoers.d/build
+
# Clean up package cache.
#
apt-get clean
@@ -301,9 +307,9 @@ EOF
# Note that when started via systemd-nspawn, we get /dev/console, not
# /dev/tty0.
#
- write <<EOF /usr/lib/systemd/system/setup.service
+ write <<EOF /usr/lib/systemd/system/buildos-setup.service
[Unit]
-Description=Setup Service
+Description=Build OS Setup
After=default.target
Conflicts=console-getty.service
@@ -324,8 +330,8 @@ WantedBy=default.target
EOF
sudo mkdir -p "$root/usr/lib/systemd/system/default.target.wants"
- sudo ln -sf "$root/usr/lib/systemd/system/setup.service" \
- "$root/usr/lib/systemd/system/default.target.wants/setup.service"
+ sudo ln -sf "$root/usr/lib/systemd/system/buildos-setup.service" \
+ "$root/usr/lib/systemd/system/default.target.wants/buildos-setup.service"
nspawn --boot
@@ -342,16 +348,15 @@ if [ "$stage" -le "4" ]; then
# Quite a few files/directories are only accessible by root (e.g., /root) so
# we run under sudo.
#
- cd "$root"
-
root_dirs="dev etc mnt root usr var"
root_links="bin sbin lib lib32 lib64"
info "generating buildos-rootfs.cpio.gz..."
+
+ cd "$root"
sudo find $root_dirs $root_links -print0 | \
sudo cpio --null -o -H newc | \
gzip -9 > "$owd/buildos-rootfs.cpio.gz"
-
cd "$owd"
subvol_snapshot -r "$root" "$root-4"
@@ -361,14 +366,25 @@ fi
#
if [ "$stage" -le "5" ]; then
- # @@ TODO: init location
+ # Install init and buildos monitor.
#
- sudo cp -f ./init "$root/"
+ sudo install -m 755 ./init "$root/"
+ sudo install -m 755 ./buildos "$root/usr/sbin/"
+ sudo install -m 755 ./buildos.service "$root/usr/lib/systemd/system/"
+ sudo ln -sf "$root/usr/lib/systemd/system/buildos.service" \
+ "$root/usr/lib/systemd/system/default.target.wants/buildos.service"
info "generating buildos-init.cpio.gz..."
- sudo echo 'init' | \
- sudo cpio -o -H newc | \
+
+ cd "$root"
+ sudo cpio -o -H newc <<EOF | \
gzip -9 > "$owd/buildos-init.cpio.gz"
+init
+usr/sbin/buildos
+usr/lib/systemd/system/buildos.service
+usr/lib/systemd/system/default.target.wants/buildos.service
+EOF
+ cd "$owd"
cat buildos-rootfs.cpio.gz buildos-init.cpio.gz >buildos-initrd
@@ -396,4 +412,4 @@ sudo kvm \
-device "scsi-hd,drive=disk1" \
-drive "if=none,id=disk1,file=/tmp/buildos-disk,format=raw" \
-kernel buildos-image -initrd buildos-initrd \
- -append "buildos.smtp_relay=build2.org buildos.admin_email=admin@build.org"
+ -append "buildos.smtp_relay=build2.org buildos.admin_email=admin@build2.org"