diff --git a/confluent_osdeploy/ubuntu20.04-diskless/initramfs/scripts/init-premount/confluent b/confluent_osdeploy/ubuntu20.04-diskless/initramfs/scripts/init-premount/confluent index 118f2ba7..8623b12d 100644 --- a/confluent_osdeploy/ubuntu20.04-diskless/initramfs/scripts/init-premount/confluent +++ b/confluent_osdeploy/ubuntu20.04-diskless/initramfs/scripts/init-premount/confluent @@ -103,13 +103,38 @@ cd - > /dev/null mkdir -p /etc/ssl/certs cat /tls/*.pem > /etc/ssl/certs/ca-certificates.crt cat /tls/*.pem > /etc/confluent/ca.pem -/opt/confluent/bin/copernicus -t > /etc/confluent/confluent.info +if [ -e /dev/disk/by-label/CNFLNT_MBI ]; then # media based image + mbimntpoint=$(mktemp -d) + mount /dev/disk/by-label/CNFLNT_MBI $mbimntpoint + echo EXTMGRINFO: media||1 > /etc/confluent/confluent.info +else + /opt/confluent/bin/copernicus -t > /etc/confluent/confluent.info +fi TRIES=0 while ! grep ^EXTMGRINFO: /etc/confluent/confluent.info | awk -F'|' '{print $3}' | grep 1 > /dev/null && [ "$TRIES" -lt 30 ]; do TRIES=$((TRIES + 1)) + if [ -e /dev/disk/by-label/CNFLNT_MBI ]; then + mbimntpoint=$(mktemp -d) + mount /dev/disk/by-label/CNFLNT_MBI $mbimntpoint + echo EXTMGRINFO: media||1 > /etc/confluent/confluent.info + break + fi /opt/confluent/bin/copernicus -t > /etc/confluent/confluent.info sleep 1 done +if [ -n "$mbimntpoint" ]; then + sed -i '/^EXTMGRINFO:/d' /etc/confluent/confluent.info + if [ -e $mbimntpoint/confluent/confluent.info ]; then + cp $mbimntpoint/confluent/confluent.info /etc/confluent/ + fi + + if [ -e $mbimntpoint/confluent/confluent.deploycfg ]; then + cp $mbimntpoint/confluent/confluent.deploycfg /etc/confluent/ + fi + if [ -e $mbimntpoint/confluent/confluent.apikey ]; then + cp $mbimntpoint/confluent/confluent.apikey /etc/confluent/ + fi +fi confluent_mgr=$(grep '^EXTMGRINFO:.*1$' /etc/confluent/confluent.info | head -n 1 | awk -F': ' '{print $2}' | awk -F'|' '{print $1}') if [ -z "$confluent_mgr" ]; then confluent_mgr=$(grep ^MANAGER: /etc/confluent/confluent.info|head -n 1 | awk '{print $2}') @@ -120,7 +145,15 @@ else confluent_http_mgr=$confluent_mgr fi confluent_nodename=$(grep ^NODENAME: /etc/confluent/confluent.info |awk '{print $NF}') +if [ -z "$confluent_nodename" ]; then + confluent_nodename=standalone +fi hostname $confluent_nodename +if [ -z "$confluent_mgr" ] && [ -n "$mbimntpoint" ]; then + # Standalone diskless image + cp $mbimntpoint/confluent/scripts/functions /etc/confluent/ + exec /bin/bash $mbimntpoint/confluent/scripts/imageboot.sh $mbimntpoint +fi get_tpm_apikey if [ -z "$confluent_apikey" ]; then get_remote_apikey diff --git a/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/imageboot.sh b/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/imageboot.sh index 897c46e4..1a07d57b 100644 --- a/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/imageboot.sh +++ b/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/imageboot.sh @@ -1,18 +1,28 @@ confluent_urls="" confluent_proto=https -for addr in $(grep ^MANAGER: /etc/confluent/confluent.info|awk '{print $2}'|sed -e s/%/%25/); do - if [[ $addr == *:* ]]; then - confluent_urls="$confluent_urls $confluent_proto://[$addr]/confluent-public/os/$confluent_profile/rootimg.sfs" - else - confluent_urls="$confluent_urls $confluent_proto://$addr/confluent-public/os/$confluent_profile/rootimg.sfs" +if [ -n "$1" ] && [ -d "$1" ]; then + mbimntpoint=$1 + if [ -e "$mbimntpoint/confluent/rootimg.sfs" ]; then + rootimg="$mbimntpoint/confluent/rootimg.sfs" fi -done +fi +if [ -z "$rootimg" ]; then + for addr in $(grep ^MANAGER: /etc/confluent/confluent.info|awk '{print $2}'|sed -e s/%/%25/); do + if [[ $addr == *:* ]]; then + confluent_urls="$confluent_urls $confluent_proto://[$addr]/confluent-public/os/$confluent_profile/rootimg.sfs" + else + confluent_urls="$confluent_urls $confluent_proto://$addr/confluent-public/os/$confluent_profile/rootimg.sfs" + fi + done +fi mkdir -p /mnt/remoteimg /mnt/remote /mnt/overlay TETHERED=1 if grep -q confluent_imagemethod=untethered /proc/cmdline || grep -q confluent_imagemethod=uncompressed /proc/cmdline; then TETHERED=0 mount -t tmpfs untethered /mnt/remoteimg curl https://$confluent_mgr/confluent-public/os/$confluent_profile/rootimg.sfs -o /mnt/remoteimg/rootimg.sfs +elif [ -n "$rootimg" ]; then + ln -s "$rootimg" /mnt/remoteimg/rootimg.sfs else confluent_urls="$confluent_urls https://$confluent_mgr/confluent-public/os/$confluent_profile/rootimg.sfs" /opt/confluent/bin/urlmount $confluent_urls /mnt/remoteimg @@ -135,12 +145,27 @@ chmod 600 /sysroot/etc/ssh/*_key mkdir -p /sysroot/usr/share/ca-certificates/confluent/ cp /tls/*.pem /sysroot/usr/share/ca-certificates/confluent/ chroot /sysroot/ update-ca-certificates -curl -sf https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/onboot.service > /sysroot/etc/systemd/system/onboot.service +if [ -n "$mbimntpoint" ]; then + if [ -e "$mbimntpoint/confluent/scripts/onboot.service" ]; then + cp $mbimntpoint/confluent/scripts/onboot.service /sysroot/etc/systemd/system/onboot.service + fi +else + curl -sf https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/onboot.service > /sysroot/etc/systemd/system/onboot.service +fi mkdir -p /sysroot/opt/confluent/bin -curl -sf https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/onboot.sh > /sysroot/opt/confluent/bin/onboot.sh +if [ -n "$mbimntpoint" ]; then + touch /sysroot/opt/confluent/bin/onboot.sh + if [ -e $mbimntpoint/confluent/scripts/onboot.sh ]; then + cp $mbimntpoint/confluent/scripts/onboot.sh /sysroot/opt/confluent/bin/onboot.sh + fi +else + curl -sf https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/onboot.sh > /sysroot/opt/confluent/bin/onboot.sh +fi chmod +x /sysroot/opt/confluent/bin/onboot.sh cp /opt/confluent/bin/apiclient /sysroot/opt/confluent/bin -ln -s /etc/systemd/system/onboot.service /sysroot/etc/systemd/system/multi-user.target.wants/onboot.service +if [ -e /sysroot/etc/systemd/system/onboot.service ]; then + ln -s /etc/systemd/system/onboot.service /sysroot/etc/systemd/system/multi-user.target.wants/onboot.service +fi cp /etc/confluent/functions /sysroot/etc/confluent/functions mv /lib/modules/$(uname -r) /lib/modules/$(uname -r)-ramfs ln -s /sysroot/lib/modules/$(uname -r) /lib/modules/ @@ -182,9 +207,9 @@ EOF fi if [ -n "$ipv4gateway" -a "$ipv4gateway" != "none" -a "$ipv4gateway" != "null" ]; then cat >> /sysroot/etc/netplan/10-${iface}-confluentcfg.yaml < /dev/null; then run_remote installimage exec reboot -f fi +if [ -n "$mbimntpoint" ]; then + for archive in $mbimntpoint/confluent/addons/*.t*; do + [ -f "$archive" ] || continue + tar -xpf "$archive" -C /sysroot + done + mkdir -p /sysroot/var/opt/confluent/mbi + mount -o bind $mbimntpoint /sysroot/var/opt/confluent/mbi + mkdir -p /sysroot/etc/confluent + echo /dev/disk/by-label/CNFLNT_MBI > /sysroot/etc/confluent/mbidevice +fi exec /opt/confluent/bin/start_root diff --git a/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/onboot.sh b/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/onboot.sh index a2b1eef3..eae2d19f 100644 --- a/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/onboot.sh +++ b/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/onboot.sh @@ -27,6 +27,18 @@ chmod 600 /var/log/confluent/confluent-onboot.log tail -f /var/log/confluent/confluent-onboot.log > /dev/console & logshowpid=$! +if [ -e /etc/confluent/mbidevice ]; then + for script in /var/opt/confluent/mbi/confluent/onboot.d/*; do + [ -x "$script" ] && "$script" + done +fi + +if [ -z "$confluent_mgr" ]; then + echo "Confluent manager not defined" + kill $logshowpid + exit 0 +fi + run_remote_python syncfileclient run_remote_python confignet