Skip to content

Commit 988c4df

Browse files
committed
add systemd services for configuration after start
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
1 parent 914f90f commit 988c4df

9 files changed

+134
-0
lines changed

createdisk.sh

+20
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,26 @@ if [ "${ARCH}" == "aarch64" ] && [ ${BUNDLE_TYPE} != "okd" ]; then
130130
${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"
131131
fi
132132

133+
# Install crc related systemd services
134+
${SSH} core@${VM_IP} -- 'mkdir -p /home/core/systemd-units && mkdir -p /home/core/systemd-scripts'
135+
${SCP} systemd/crc-*.service core@${VM_IP}:/home/core/systemd-units/
136+
${SCP} systemd/crc-*.sh core@${VM_IP}:/home/core/systemd-scripts/
137+
${SSH} core@${VM_IP} -- 'sudo cp /home/core/systemd-units/* /etc/systemd/system/ && sudo cp /home/core/systemd-scripts/* /usr/local/bin/'
138+
${SSH} core@${VM_IP} -- 'ls /home/core/systemd-scripts/ | xargs sudo chmod +x /usr/local/bin/'
139+
${SSH} core@${VM_IP} -- 'sudo restorecon -rv /usr/local/bin'
140+
${SSH} core@${VM_IP} -- 'ls /home/core/systemd-units/ | xargs sudo systemctl enable'
141+
${SSH} core@${VM_IP} -- 'rm -rf /home/core/systemd-units/* /home/core/systemd-scripts/*'
142+
143+
if [ ${BUNDLE_TYPE} != "microshift" ]; then
144+
${SCP} systemd/ocp-*.service core@${VM_IP}:/home/core/systemd-units/
145+
${SCP} systemd/ocp-*.sh core@${VM_IP}:/home/core/systemd-scripts/
146+
${SSH} core@${VM_IP} -- 'sudo cp /home/core/systemd-units/* /etc/systemd/system/ && sudo cp /home/core/systemd-scripts/* /usr/local/bin'
147+
${SSH} core@${VM_IP} -- 'ls /home/core/systemd-scripts/ | xargs sudo chmod +x /usr/local/bin/'
148+
${SSH} core@${VM_IP} -- 'sudo restorecon -rv /usr/local/bin'
149+
${SSH} core@${VM_IP} -- 'ls /home/core/systemd-units/ | xargs sudo systemctl enable'
150+
${SSH} core@${VM_IP} -- 'rm -rf /home/core/systemd-units/* /home/core/systemd-scripts/*'
151+
fi
152+
133153
cleanup_vm_image ${VM_NAME} ${VM_IP}
134154

135155
# 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.

systemd/crc-dnsmasq.service

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=CRC Unit for configuring dnsmasq
3+
Requires=ovs-configuration.service
4+
After=ovs-configuration.service
5+
6+
[Service]
7+
Type=oneshot
8+
ExecStart=/usr/local/bin/crc-dnsmasq.sh
9+
StandardOutput=journal
10+
11+
[Install]
12+
WantedBy=multi-user.target

systemd/crc-dnsmasq.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
# exit early if user-mode networking
6+
ping -c1 gateway > /dev/null 2>&1
7+
[ $? -eq 0 ] && exit 0
8+
9+
hostName=$(hostname)
10+
ip=$(ip -4 addr show br-ex | grep -oP '(?<=inet\s)192+(\.\d+){3}')
11+
iip=$(hostname -i)
12+
13+
cat << EOF > /etc/dnsmasq.d/crc-dnsmasq.conf
14+
listen-address=$ip
15+
expand-hosts
16+
log-queries
17+
local=/crc.testing/
18+
domain=crc.testing
19+
address=/apps-crc.testing/$ip
20+
address=/api.crc.testing/$ip
21+
address=/api-int.crc.testing/$ip
22+
address=/$hostName.crc.testing/$iip
23+
EOF
24+
25+
sleep 2
26+
27+
systemctl enable dnsmasq.service
28+
systemctl start dnsmasq.service

systemd/crc-routes-controller.service

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=CRC Unit starting routes controller
3+
After=kubelet.service
4+
Requires=kubelet.service
5+
6+
[Service]
7+
Type=oneshot
8+
ExecStart=/usr/local/bin/crc-routes-controller.sh
9+
StandardOutput=journal
10+
11+
[Install]
12+
WantedBy=multi-user.target

systemd/crc-routes-controller.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
# exit early if system-mode networking
6+
ping -c1 gateway > /dev/null 2>&1
7+
[ $? -eq 2 ] && exit 0
8+
9+
export KUBECONFIG=/opt/kubeconfig
10+
oc apply -f /opt/crc/routes-controller.yaml
11+
12+

systemd/ocp-clusterid.service

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=CRC Unit setting random cluster ID
3+
After=kubelet.service
4+
Requires=kubelet.service
5+
6+
[Service]
7+
Type=oneshot
8+
ExecStart=/usr/local/bin/ocp-clusterid.sh
9+
StandardOutput=journal
10+
11+
[Install]
12+
WantedBy=multi-user.target

systemd/ocp-clusterid.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
export KUBECONFIG="/opt/kubeconfig"
6+
uuid=$(uuidgen)
7+
8+
retry=0
9+
max_retry=20
10+
until `oc get clusterversion > /dev/null 2>&1`
11+
do
12+
[ $retry == $max_retry ] && exit 1
13+
sleep 5
14+
((retry++))
15+
done
16+
17+
oc patch clusterversion version -p "{\"spec\":{\"clusterID\":\"${uuid}\"}}" --type merge

systemd/ocp-growfs.service

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=CRC Unit to grow the root filesystem
3+
4+
[Service]
5+
Type=oneshot
6+
ExecStart=/usr/local/bin/ocp-growfs.sh
7+
StandardOutput=journal
8+
9+
[Install]
10+
WantedBy=multi-user.target

systemd/ocp-growfs.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
root_partition=$(/usr/sbin/blkid -t TYPE=xfs -o device)
6+
/usr/bin/growpart "${root_partition#?}" "${root_partition#/dev/???}"
7+
8+
rootFS="/sysroot"
9+
mount -o remount,rw "${rootFS}"
10+
xfs_growfs "${rootFS}"
11+
#mount -o remount,ro "${rootFS}"

0 commit comments

Comments
 (0)