Skip to content

Commit

Permalink
add systemd services for configuration after start
Browse files Browse the repository at this point in the history
this adds 4 small systemd services that:
- creates crc specific configurations for dnsmasq
- sets a new uuid as cluster id
- creates the pod for routes-controller
- tries to grow the disk and filesystem
  • Loading branch information
anjannath committed Oct 21, 2024
1 parent 914f90f commit 988c4df
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 0 deletions.
20 changes: 20 additions & 0 deletions createdisk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 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.
Expand Down
12 changes: 12 additions & 0 deletions systemd/crc-dnsmasq.service
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions systemd/crc-dnsmasq.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions systemd/crc-routes-controller.service
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions systemd/crc-routes-controller.sh
Original file line number Diff line number Diff line change
@@ -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


12 changes: 12 additions & 0 deletions systemd/ocp-clusterid.service
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions systemd/ocp-clusterid.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions systemd/ocp-growfs.service
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions systemd/ocp-growfs.sh
Original file line number Diff line number Diff line change
@@ -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}"

0 comments on commit 988c4df

Please sign in to comment.