From c6ec9b53d97366d235be4a1e92a50ec94e0ecea4 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Fri, 20 Oct 2023 09:44:04 +0200 Subject: [PATCH] Add and enable openrc/systemd service via yip files (#505) --- packages/alpine/collection.yaml | 2 +- packages/alpine/files/initramfs-init | 10 +- .../kairos-overlay-files/collection.yaml | 2 +- .../systemd/network/20-dhcp-legacy.network | 0 .../etc}/systemd/network/20-dhcp.network | 0 .../systemd/system/systemd-firstboot.service | 1 + ..._services.yaml => 09_openrc_services.yaml} | 65 ++++++++- .../files/system/oem/09_services.yaml | 33 ----- .../files/system/oem/09_systemd_services.yaml | 129 ++++++++++++++++++ .../files/usr/bin/cos-setup-reconcile | 0 .../init-svc/openrc/cos-setup/build.yaml | 6 - .../init-svc/openrc/cos-setup/definition.yaml | 4 - .../cos-setup/files/etc/init.d/cos-setup-boot | 10 -- .../files/etc/init.d/cos-setup-network | 11 -- .../files/etc/init.d/cos-setup-reconcile | 15 -- packages/system/init-svc/systemd/build.yaml | 6 - .../system/init-svc/systemd/definition.yaml | 3 - .../systemd/services/cos-setup-boot.service | 11 -- .../systemd/services/cos-setup-fs.service | 14 -- .../services/cos-setup-network.service | 11 -- .../services/cos-setup-reconcile.service | 15 -- .../services/cos-setup-reconcile.timer | 10 -- 22 files changed, 200 insertions(+), 158 deletions(-) rename packages/{system/init-svc => static/kairos-overlay-files/files/etc}/systemd/network/20-dhcp-legacy.network (100%) rename packages/{system/init-svc => static/kairos-overlay-files/files/etc}/systemd/network/20-dhcp.network (100%) create mode 120000 packages/static/kairos-overlay-files/files/etc/systemd/system/systemd-firstboot.service rename packages/static/kairos-overlay-files/files/system/oem/{13_openrc_services.yaml => 09_openrc_services.yaml} (55%) delete mode 100644 packages/static/kairos-overlay-files/files/system/oem/09_services.yaml create mode 100644 packages/static/kairos-overlay-files/files/system/oem/09_systemd_services.yaml rename packages/{system/init-svc/openrc/cos-setup => static/kairos-overlay-files}/files/usr/bin/cos-setup-reconcile (100%) delete mode 100644 packages/system/init-svc/openrc/cos-setup/build.yaml delete mode 100644 packages/system/init-svc/openrc/cos-setup/definition.yaml delete mode 100755 packages/system/init-svc/openrc/cos-setup/files/etc/init.d/cos-setup-boot delete mode 100755 packages/system/init-svc/openrc/cos-setup/files/etc/init.d/cos-setup-network delete mode 100755 packages/system/init-svc/openrc/cos-setup/files/etc/init.d/cos-setup-reconcile delete mode 100644 packages/system/init-svc/systemd/build.yaml delete mode 100644 packages/system/init-svc/systemd/definition.yaml delete mode 100644 packages/system/init-svc/systemd/services/cos-setup-boot.service delete mode 100644 packages/system/init-svc/systemd/services/cos-setup-fs.service delete mode 100644 packages/system/init-svc/systemd/services/cos-setup-network.service delete mode 100644 packages/system/init-svc/systemd/services/cos-setup-reconcile.service delete mode 100644 packages/system/init-svc/systemd/services/cos-setup-reconcile.timer diff --git a/packages/alpine/collection.yaml b/packages/alpine/collection.yaml index 759af9ed0..357e1a0c9 100644 --- a/packages/alpine/collection.yaml +++ b/packages/alpine/collection.yaml @@ -1,7 +1,7 @@ packages: - name: "alpine" category: "initrd" - version: "3.8.1+1" + version: "3.8.1+2" description: "Provides custom initrd scripts for alpine" # This syncs with the alpine version at https://gitlab.alpinelinux.org/alpine/mkinitfs/-/blob/master/initramfs-init.in?ref_type=heads # any changes to the initramfs-init.in file should be looked at and backported if necessary \ No newline at end of file diff --git a/packages/alpine/files/initramfs-init b/packages/alpine/files/initramfs-init index 667a56b32..f7f06430c 100755 --- a/packages/alpine/files/initramfs-init +++ b/packages/alpine/files/initramfs-init @@ -435,11 +435,13 @@ if grep -q cdroot /proc/cmdline || grep -q netboot /proc/cmdline;then mount -t overlay -o lowerdir=/run/rootfsbase,upperdir=/media/root-rw/root,workdir=/media/root-rw/work overlayfs $sysroot eend $? sync + rd_break pre-immucore # immucore to run the initramfs and rootfs stages - ebegin "Run immucore" - immucore - eend $? - # Move current mounts into sysroot mounts + ebegin "Run immucore" + immucore + eend $? + rd_break post-immucore + # Move current mounts into sysroot mounts # shellcheck disable=SC2002 cat "$ROOT"/proc/mounts 2>/dev/null | while read DEV DIR TYPE OPTS ; do # shellcheck disable=SC2166 diff --git a/packages/static/kairos-overlay-files/collection.yaml b/packages/static/kairos-overlay-files/collection.yaml index ea400b81d..ea8dda9ac 100644 --- a/packages/static/kairos-overlay-files/collection.yaml +++ b/packages/static/kairos-overlay-files/collection.yaml @@ -1,4 +1,4 @@ packages: - name: "kairos-overlay-files" category: "static" - version: "1.1.6" + version: "1.1.7" diff --git a/packages/system/init-svc/systemd/network/20-dhcp-legacy.network b/packages/static/kairos-overlay-files/files/etc/systemd/network/20-dhcp-legacy.network similarity index 100% rename from packages/system/init-svc/systemd/network/20-dhcp-legacy.network rename to packages/static/kairos-overlay-files/files/etc/systemd/network/20-dhcp-legacy.network diff --git a/packages/system/init-svc/systemd/network/20-dhcp.network b/packages/static/kairos-overlay-files/files/etc/systemd/network/20-dhcp.network similarity index 100% rename from packages/system/init-svc/systemd/network/20-dhcp.network rename to packages/static/kairos-overlay-files/files/etc/systemd/network/20-dhcp.network diff --git a/packages/static/kairos-overlay-files/files/etc/systemd/system/systemd-firstboot.service b/packages/static/kairos-overlay-files/files/etc/systemd/system/systemd-firstboot.service new file mode 120000 index 000000000..dc1dc0cde --- /dev/null +++ b/packages/static/kairos-overlay-files/files/etc/systemd/system/systemd-firstboot.service @@ -0,0 +1 @@ +/dev/null \ No newline at end of file diff --git a/packages/static/kairos-overlay-files/files/system/oem/13_openrc_services.yaml b/packages/static/kairos-overlay-files/files/system/oem/09_openrc_services.yaml similarity index 55% rename from packages/static/kairos-overlay-files/files/system/oem/13_openrc_services.yaml rename to packages/static/kairos-overlay-files/files/system/oem/09_openrc_services.yaml index 0e4d52f7a..3a5784295 100644 --- a/packages/static/kairos-overlay-files/files/system/oem/13_openrc_services.yaml +++ b/packages/static/kairos-overlay-files/files/system/oem/09_openrc_services.yaml @@ -1,10 +1,61 @@ name: "Create openrc services" stages: initramfs: - - name: "Create files" + - name: "Create OpenRC services" if: | - grep -i alpine "/etc/os-release" + [ -f "/sbin/openrc" ] files: + - path: /etc/init.d/cos-setup-boot + permissions: 0755 + owner: 0 + group: 0 + content: | + #!/sbin/openrc-run + + depend() { + provide cos-setup-boot + } + + start() { + kairos-agent run-stage boot + eend 0 + } + - path: /etc/init.d/cos-setup-network + permissions: 0755 + owner: 0 + group: 0 + content: | + #!/sbin/openrc-run + + depend() { + after net + provide cos-setup-network + } + + start() { + kairos-agent run-stage network + eend 0 + } + - path: /etc/init.d/cos-setup-reconcile + permissions: 0755 + owner: 0 + group: 0 + content: | + #!/sbin/openrc-run + + depend() { + provide cos-setup-reconcile + } + + supervisor=supervise-daemon + name="cos-setup-reconcile" + command="cos-setup-reconcile" + supervise_daemon_args="--stdout /var/log/cos-setup-reconcile.log --stderr /var/log/cos-setup-reconcile.log" + pidfile="/run/cos-setup-reconcile.pid" + respawn_delay=360 + set -o allexport + if [ -f /etc/environment ]; then source /etc/environment; fi + set +o allexport - path: /etc/init.d/kairos-agent content: | #!/sbin/openrc-run @@ -45,7 +96,6 @@ stages: set -o allexport if [ -f /etc/environment ]; then source /etc/environment; fi set +o allexport - permissions: 0755 owner: 0 group: 0 @@ -66,3 +116,12 @@ stages: permissions: 0755 owner: 0 group: 0 + - name: "Enable OpenRC services" + if: | + [ -f "/sbin/openrc" ] + commands: + - mkdir -p /etc/runlevels/default + - ln -sf ../../init.d/cos-setup-boot /etc/runlevels/default/cos-setup-boot + - ln -sf ../../init.d/cos-setup-network /etc/runlevels/default/cos-setup-network + - ln -sf ../../init.d/cos-setup-reconcile /etc/runlevels/default/cos-setup-reconcile + - ln -sf ../../init.d/kairos-agent /etc/runlevels/default/kairos-agent diff --git a/packages/static/kairos-overlay-files/files/system/oem/09_services.yaml b/packages/static/kairos-overlay-files/files/system/oem/09_services.yaml deleted file mode 100644 index a6a0507a4..000000000 --- a/packages/static/kairos-overlay-files/files/system/oem/09_services.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Rootfs Kairos OEM configuration file -# -# This file is part of Kairos and will get reset during upgrades. - -name: "Default config" -stages: - boot: - - name: "Default sysctl settings" - sysctl: - net.core.rmem_max: 2500000 - vm.max_map_count: 262144 - initramfs: - - name: "Default systemd config" - if: '[ -e "/sbin/systemctl" ] || [ -e "/usr/bin/systemctl" ] || [ -e "/usr/sbin/systemctl" ] || [ -e "/usr/bin/systemctl" ]' - systemctl: - enable: - - multi-user.target - - getty@tty1 - - iscsid - - systemd-timesyncd - - nohang - - nohang-desktop - - fail2ban - - logrotate.timer - - sshd - mask: - - purge-kernels - commands: - - systemctl set-default multi-user.target - - name: "Generate host keys" - # Make sure the host always has available keys - commands: - - ssh-keygen -A diff --git a/packages/static/kairos-overlay-files/files/system/oem/09_systemd_services.yaml b/packages/static/kairos-overlay-files/files/system/oem/09_systemd_services.yaml new file mode 100644 index 000000000..e15ba6fb8 --- /dev/null +++ b/packages/static/kairos-overlay-files/files/system/oem/09_systemd_services.yaml @@ -0,0 +1,129 @@ +# Rootfs Kairos OEM configuration file +# +# This file is part of Kairos and will get reset during upgrades. + +name: "Default config" +stages: + boot: + - name: "Default sysctl settings" + sysctl: + net.core.rmem_max: 2500000 + vm.max_map_count: 262144 + initramfs: + - name: "Default systemd config" + if: '[ -e "/sbin/systemctl" ] || [ -e "/usr/bin/systemctl" ] || [ -e "/usr/sbin/systemctl" ] || [ -e "/usr/bin/systemctl" ]' + systemctl: + enable: + - multi-user.target + - getty@tty1 + - iscsid + - systemd-timesyncd + - nohang + - nohang-desktop + - fail2ban + - logrotate.timer + - sshd + mask: + - purge-kernels + commands: + - systemctl set-default multi-user.target + - name: "Generate host keys" + # Make sure the host always has available keys + commands: + - ssh-keygen -A + - name: "Create systemd services" + if: '[ -e "/sbin/systemctl" ] || [ -e "/usr/bin/systemctl" ] || [ -e "/usr/sbin/systemctl" ] || [ -e "/usr/bin/systemctl" ]' + files: + - path: /etc/systemd/system/cos-setup-boot.service + permissions: 0644 + owner: 0 + group: 0 + content: | + [Unit] + Description=cOS system configuration + Before=getty.target + + [Service] + Type=oneshot + RemainAfterExit=yes + ExecStart=/usr/bin/kairos-agent run-stage boot + + [Install] + WantedBy=multi-user.target + - path: /etc/systemd/system/cos-setup-fs.service + permissions: 0644 + owner: 0 + group: 0 + content: | + [Unit] + Description=cOS system after FS setup + DefaultDependencies=no + After=local-fs.target + Wants=local-fs.target + Before=sysinit.target + + [Service] + Type=oneshot + RemainAfterExit=yes + ExecStart=/usr/bin/kairos-agent run-stage fs + + [Install] + WantedBy=sysinit.target + - path: /etc/systemd/system/cos-setup-network.service + permissions: 0644 + owner: 0 + group: 0 + content: | + [Unit] + Description=cOS setup after network + After=network-online.target + + [Service] + Type=oneshot + RemainAfterExit=yes + ExecStart=/usr/bin/kairos-agent run-stage network + + [Install] + WantedBy=multi-user.target + - path: /etc/systemd/system/cos-setup-reconcile.service + permissions: 0644 + owner: 0 + group: 0 + content: | + [Unit] + Description=cOS setup reconciler + + [Service] + Nice=19 + IOSchedulingClass=2 + IOSchedulingPriority=7 + Type=oneshot + ExecStart=/bin/bash -c "systemd-inhibit /usr/bin/kairos-agent run-stage reconcile" + TimeoutStopSec=180 + KillMode=process + KillSignal=SIGINT + + [Install] + WantedBy=multi-user.target + - path: /etc/systemd/system/cos-setup-reconcile.timer + permissions: 0644 + owner: 0 + group: 0 + content: | + [Unit] + Description=cOS setup reconciler + + [Timer] + OnBootSec=5min + OnUnitActiveSec=60min + Unit=cos-setup-reconcile.service + + [Install] + WantedBy=multi-user.target + - name: "Enable systemd services" + if: '[ -e "/sbin/systemctl" ] || [ -e "/usr/bin/systemctl" ] || [ -e "/usr/sbin/systemctl" ] || [ -e "/usr/bin/systemctl" ]' + commands: + - ln -sf /etc/systemd/system/cos-setup-reconcile.timer /etc/systemd/system/multi-user.target.wants/cos-setup-reconcile.timer + - ln -sf /etc/systemd/system/cos-setup-fs.service /etc/systemd/system/sysinit.target.wants/cos-setup-fs.service + - ln -sf /etc/systemd/system/cos-setup-boot.service /etc/systemd/system/multi-user.target.wants/cos-setup-boot.service + - ln -sf /etc/systemd/system/cos-setup-network.service /etc/systemd/system/multi-user.target.wants/cos-setup-network.service \ No newline at end of file diff --git a/packages/system/init-svc/openrc/cos-setup/files/usr/bin/cos-setup-reconcile b/packages/static/kairos-overlay-files/files/usr/bin/cos-setup-reconcile similarity index 100% rename from packages/system/init-svc/openrc/cos-setup/files/usr/bin/cos-setup-reconcile rename to packages/static/kairos-overlay-files/files/usr/bin/cos-setup-reconcile diff --git a/packages/system/init-svc/openrc/cos-setup/build.yaml b/packages/system/init-svc/openrc/cos-setup/build.yaml deleted file mode 100644 index 7467399d8..000000000 --- a/packages/system/init-svc/openrc/cos-setup/build.yaml +++ /dev/null @@ -1,6 +0,0 @@ -image: "alpine" -package_dir: "/package" -steps: -- mkdir /package -- cp -rfv files/* /package -- chmod +x /package/usr/bin/cos-setup-reconcile diff --git a/packages/system/init-svc/openrc/cos-setup/definition.yaml b/packages/system/init-svc/openrc/cos-setup/definition.yaml deleted file mode 100644 index 54b55a377..000000000 --- a/packages/system/init-svc/openrc/cos-setup/definition.yaml +++ /dev/null @@ -1,4 +0,0 @@ -name: openrc -category: init-svc -version: 0.3.0 -description: "Experimental package for openrc support" diff --git a/packages/system/init-svc/openrc/cos-setup/files/etc/init.d/cos-setup-boot b/packages/system/init-svc/openrc/cos-setup/files/etc/init.d/cos-setup-boot deleted file mode 100755 index 8893617c6..000000000 --- a/packages/system/init-svc/openrc/cos-setup/files/etc/init.d/cos-setup-boot +++ /dev/null @@ -1,10 +0,0 @@ -#!/sbin/openrc-run - -depend() { - provide cos-setup-boot -} - -start() { - kairos-agent run-stage boot - eend 0 -} \ No newline at end of file diff --git a/packages/system/init-svc/openrc/cos-setup/files/etc/init.d/cos-setup-network b/packages/system/init-svc/openrc/cos-setup/files/etc/init.d/cos-setup-network deleted file mode 100755 index c3817a5b3..000000000 --- a/packages/system/init-svc/openrc/cos-setup/files/etc/init.d/cos-setup-network +++ /dev/null @@ -1,11 +0,0 @@ -#!/sbin/openrc-run - -depend() { - after net - provide cos-setup-network -} - -start() { - kairos-agent run-stage network - eend 0 -} \ No newline at end of file diff --git a/packages/system/init-svc/openrc/cos-setup/files/etc/init.d/cos-setup-reconcile b/packages/system/init-svc/openrc/cos-setup/files/etc/init.d/cos-setup-reconcile deleted file mode 100755 index ba515b0b9..000000000 --- a/packages/system/init-svc/openrc/cos-setup/files/etc/init.d/cos-setup-reconcile +++ /dev/null @@ -1,15 +0,0 @@ -#!/sbin/openrc-run - -depend() { - provide cos-setup-reconcile -} - -supervisor=supervise-daemon -name="cos-setup-reconcile" -command="cos-setup-reconcile" -supervise_daemon_args="--stdout /var/log/cos-setup-reconcile.log --stderr /var/log/cos-setup-reconcile.log" -pidfile="/run/cos-setup-reconcile.pid" -respawn_delay=5 -set -o allexport -if [ -f /etc/environment ]; then source /etc/environment; fi -set +o allexport \ No newline at end of file diff --git a/packages/system/init-svc/systemd/build.yaml b/packages/system/init-svc/systemd/build.yaml deleted file mode 100644 index 78eae2a2e..000000000 --- a/packages/system/init-svc/systemd/build.yaml +++ /dev/null @@ -1,6 +0,0 @@ -image: "alpine" -steps: -- mkdir -p /etc/systemd/system -- mkdir -p /etc/systemd/network -- cp -rfv services/* /etc/systemd/system -- cp -rfv network/* /etc/systemd/network diff --git a/packages/system/init-svc/systemd/definition.yaml b/packages/system/init-svc/systemd/definition.yaml deleted file mode 100644 index a65bafb29..000000000 --- a/packages/system/init-svc/systemd/definition.yaml +++ /dev/null @@ -1,3 +0,0 @@ -name: systemd -category: init-svc -version: 0.9.0 diff --git a/packages/system/init-svc/systemd/services/cos-setup-boot.service b/packages/system/init-svc/systemd/services/cos-setup-boot.service deleted file mode 100644 index 839f1e66e..000000000 --- a/packages/system/init-svc/systemd/services/cos-setup-boot.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=cOS system configuration -Before=getty.target - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/usr/bin/kairos-agent run-stage boot - -[Install] -WantedBy=multi-user.target diff --git a/packages/system/init-svc/systemd/services/cos-setup-fs.service b/packages/system/init-svc/systemd/services/cos-setup-fs.service deleted file mode 100644 index 629e00a56..000000000 --- a/packages/system/init-svc/systemd/services/cos-setup-fs.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=cOS system after FS setup -DefaultDependencies=no -After=local-fs.target -Wants=local-fs.target -Before=sysinit.target - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/usr/bin/kairos-agent run-stage fs - -[Install] -WantedBy=sysinit.target diff --git a/packages/system/init-svc/systemd/services/cos-setup-network.service b/packages/system/init-svc/systemd/services/cos-setup-network.service deleted file mode 100644 index 13e1b14ac..000000000 --- a/packages/system/init-svc/systemd/services/cos-setup-network.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=cOS setup after network -After=network-online.target - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/usr/bin/kairos-agent run-stage network - -[Install] -WantedBy=multi-user.target diff --git a/packages/system/init-svc/systemd/services/cos-setup-reconcile.service b/packages/system/init-svc/systemd/services/cos-setup-reconcile.service deleted file mode 100644 index f7f83722e..000000000 --- a/packages/system/init-svc/systemd/services/cos-setup-reconcile.service +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=cOS setup reconciler - -[Service] -Nice=19 -IOSchedulingClass=2 -IOSchedulingPriority=7 -Type=oneshot -ExecStart=/bin/bash -c "systemd-inhibit /usr/bin/kairos-agent run-stage reconcile" -TimeoutStopSec=180 -KillMode=process -KillSignal=SIGINT - -[Install] -WantedBy=multi-user.target diff --git a/packages/system/init-svc/systemd/services/cos-setup-reconcile.timer b/packages/system/init-svc/systemd/services/cos-setup-reconcile.timer deleted file mode 100644 index 79fe4ced5..000000000 --- a/packages/system/init-svc/systemd/services/cos-setup-reconcile.timer +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=cOS setup reconciler - -[Timer] -OnBootSec=5min -OnUnitActiveSec=60min -Unit=cos-setup-reconcile.service - -[Install] -WantedBy=multi-user.target