diff --git a/createdisk.sh b/createdisk.sh index 95601077..44901782 100755 --- a/createdisk.sh +++ b/createdisk.sh @@ -130,6 +130,26 @@ if [ "${ARCH}" == "aarch64" ] && [ ${BUNDLE_TYPE} != "okd" ]; then ${SSH} core@${VM_IP} -- "sudo rpm-ostree install https://kojipkgs.fedoraproject.org//packages/qemu/8.2.6/3.fc40/aarch64/qemu-user-static-x86-8.2.6-3.fc40.aarch64.rpm" fi +# Install crc related systemd services +${SSH} core@${VM_IP} -- 'mkdir -p /home/core/systemd-units && mkdir -p /home/core/systemd-scripts' +${SCP} systemd/crc-*.service core@${VM_IP}:/home/core/systemd-units/ +${SCP} systemd/crc-*.sh core@${VM_IP}:/home/core/systemd-scripts/ +${SSH} core@${VM_IP} -- 'sudo cp /home/core/systemd-units/* /etc/systemd/system/ && sudo cp /home/core/systemd-scripts/* /usr/local/bin/' +${SSH} core@${VM_IP} -- 'ls /home/core/systemd-scripts/ | xargs -t -I % sudo chmod +x /usr/local/bin/%' +${SSH} core@${VM_IP} -- 'sudo restorecon -rv /usr/local/bin' +${SSH} core@${VM_IP} -- 'ls /home/core/systemd-units/ | xargs sudo systemctl enable' +${SSH} core@${VM_IP} -- 'rm -rf /home/core/systemd-units/* /home/core/systemd-scripts/*' + +if [ ${BUNDLE_TYPE} != "microshift" ]; then + ${SCP} systemd/ocp-*.service core@${VM_IP}:/home/core/systemd-units/ + ${SCP} systemd/ocp-*.sh core@${VM_IP}:/home/core/systemd-scripts/ + ${SSH} core@${VM_IP} -- 'sudo cp /home/core/systemd-units/* /etc/systemd/system/ && sudo cp /home/core/systemd-scripts/* /usr/local/bin' + ${SSH} core@${VM_IP} -- 'ls /home/core/systemd-scripts/ | xargs -t -I % sudo chmod +x /usr/local/bin/%' + ${SSH} core@${VM_IP} -- 'sudo restorecon -rv /usr/local/bin' + ${SSH} core@${VM_IP} -- 'ls /home/core/systemd-units/ | xargs sudo systemctl enable' + ${SSH} core@${VM_IP} -- 'rm -rf /home/core/systemd-units/* /home/core/systemd-scripts/*' +fi + cleanup_vm_image ${VM_NAME} ${VM_IP} # Delete all the pods and lease from the etcd db so that when this bundle is use for the cluster provision, everything comes up in clean state. diff --git a/systemd/crc-dnsmasq.service b/systemd/crc-dnsmasq.service new file mode 100644 index 00000000..6bbfb350 --- /dev/null +++ b/systemd/crc-dnsmasq.service @@ -0,0 +1,12 @@ +[Unit] +Description=CRC Unit for configuring dnsmasq +Requires=ovs-configuration.service +After=ovs-configuration.service + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/crc-dnsmasq.sh +StandardOutput=journal + +[Install] +WantedBy=multi-user.target diff --git a/systemd/crc-dnsmasq.sh b/systemd/crc-dnsmasq.sh new file mode 100644 index 00000000..0ee598ae --- /dev/null +++ b/systemd/crc-dnsmasq.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -x + +# exit early if user-mode networking +ping -c1 gateway > /dev/null 2>&1 +[ $? -eq 0 ] && exit 0 + +hostName=$(hostname) +ip=$(ip -4 addr show br-ex | grep -oP '(?<=inet\s)192+(\.\d+){3}') +iip=$(hostname -i) + +cat << EOF > /etc/dnsmasq.d/crc-dnsmasq.conf +listen-address=$ip +expand-hosts +log-queries +local=/crc.testing/ +domain=crc.testing +address=/apps-crc.testing/$ip +address=/api.crc.testing/$ip +address=/api-int.crc.testing/$ip +address=/$hostName.crc.testing/$iip +EOF + +sleep 2 + +systemctl enable dnsmasq.service +systemctl start dnsmasq.service diff --git a/systemd/crc-routes-controller.service b/systemd/crc-routes-controller.service new file mode 100644 index 00000000..c5d687a9 --- /dev/null +++ b/systemd/crc-routes-controller.service @@ -0,0 +1,12 @@ +[Unit] +Description=CRC Unit starting routes controller +After=kubelet.service +Requires=kubelet.service + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/crc-routes-controller.sh +StandardOutput=journal + +[Install] +WantedBy=multi-user.target diff --git a/systemd/crc-routes-controller.sh b/systemd/crc-routes-controller.sh new file mode 100644 index 00000000..ff0ea6d3 --- /dev/null +++ b/systemd/crc-routes-controller.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -x + +# exit early if system-mode networking +ping -c1 gateway > /dev/null 2>&1 +[ $? -eq 2 ] && exit 0 + +export KUBECONFIG=/opt/kubeconfig +oc apply -f /opt/crc/routes-controller.yaml + + diff --git a/systemd/ocp-clusterid.service b/systemd/ocp-clusterid.service new file mode 100644 index 00000000..18fb04e0 --- /dev/null +++ b/systemd/ocp-clusterid.service @@ -0,0 +1,12 @@ +[Unit] +Description=CRC Unit setting random cluster ID +After=kubelet.service +Requires=kubelet.service + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/ocp-clusterid.sh +StandardOutput=journal + +[Install] +WantedBy=multi-user.target diff --git a/systemd/ocp-clusterid.sh b/systemd/ocp-clusterid.sh new file mode 100644 index 00000000..072312bc --- /dev/null +++ b/systemd/ocp-clusterid.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -x + +export KUBECONFIG="/opt/kubeconfig" +uuid=$(uuidgen) + +retry=0 +max_retry=20 +until `oc get clusterversion > /dev/null 2>&1` +do + [ $retry == $max_retry ] && exit 1 + sleep 5 + ((retry++)) +done + +oc patch clusterversion version -p "{\"spec\":{\"clusterID\":\"${uuid}\"}}" --type merge diff --git a/systemd/ocp-growfs.service b/systemd/ocp-growfs.service new file mode 100644 index 00000000..5d33babe --- /dev/null +++ b/systemd/ocp-growfs.service @@ -0,0 +1,10 @@ +[Unit] +Description=CRC Unit to grow the root filesystem + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/ocp-growfs.sh +StandardOutput=journal + +[Install] +WantedBy=multi-user.target diff --git a/systemd/ocp-growfs.sh b/systemd/ocp-growfs.sh new file mode 100644 index 00000000..4c657bb2 --- /dev/null +++ b/systemd/ocp-growfs.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -x + +root_partition=$(/usr/sbin/blkid -t TYPE=xfs -o device) +/usr/bin/growpart "${root_partition#?}" "${root_partition#/dev/???}" + +rootFS="/sysroot" +mount -o remount,rw "${rootFS}" +xfs_growfs "${rootFS}" +#mount -o remount,ro "${rootFS}"