Skip to content

Commit

Permalink
Update qm /etc/agent/agent.conf that when the qm.service is started
Browse files Browse the repository at this point in the history
This pull request will cause the /usr/lib/qm/rootfs/etc/hirte/agent.conf
to be created on every qm.service start.  This way if the admin changes
the /etc/hirte/agent.conf on the host, the equivalent inside of the qm
will match with the exception that the nodename is prefixed with qm.

If the nodename in the hosts /etc/hirte/agent.conf is changed to foobar,
then the qm's /etc/hirte/agent.conf will have the same settings except
the node name will be qm.foobar.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed May 17, 2023
1 parent 6df72e5 commit 3b6a2f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions qm.container
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ MemorySwapMax=0
OOMScoreAdjust=500
Restart=always
Slice=QM.slice
ExecPreStart=/usr/share/qm/setup hirte-agent

[Container]
AddCapability=all
Expand Down
38 changes: 23 additions & 15 deletions setup
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ replaceIDs() {
grep -q "^$2:" $1 || echo $2:$3 >> $1
}

AGENTCONF=/etc/hirte/agent.conf
INSTALLDIR="$1"
[ ! -z "${INSTALLDIR}" ] || INSTALLDIR=/usr/share/qm

Expand All @@ -26,23 +27,22 @@ systemctl stop qm.service 2>/dev/null || true

hirteSetup() {
rootfs=$1
if test ! -f ${rootfs}/etc/hirte/agent.conf; then
if test -f /etc/hirte/agent.conf; then
sed -e 's,^NodeName=,NodeName=qm.,g' /etc/hirte/agent.conf > ${rootfs}/etc/hirte/agent.conf
if test ! -f ${rootfs}${AGENTCONF}; then
if test -f ${AGENTCONF}; then
sed -e 's,^NodeName=,NodeName=qm.,g' ${AGENTCONF} > ${rootfs}${AGENTCONF}
fi
fi
hostname=$(hostname)
if test -f ${rootfs}/etc/hirte/agent.conf; then
if test -f ${rootfs}${AGENTCONF}; then
sed -e "s,^NodeName=qm.$,NodeName=qm.${hostname},g" \
-e "s,^NodeName=$,NodeName=qm.${hostname},g" \
-i ${rootfs}/etc/hirte/agent.conf
-i ${rootfs}${AGENTCONF}
else
cat > ${rootfs}/etc/hirte/agent.conf <<EOF
cat > ${rootfs}${AGENTCONF} <<EOF
[hirte-agent]
NodeName=qm.${hostname}
EOF
fi
unshare --mount-proc -R /usr/lib/qm/rootfs -m systemctl enable hirte-agent.service
}

storage() {
Expand Down Expand Up @@ -73,15 +73,23 @@ install() {
replaceIDs ${rootfs}/etc/subuid containers ${qmContainerIDs}
replaceIDs ${rootfs}/etc/subgid containers ${qmContainerIDs}
hirteSetup ${rootfs}
unshare --mount-proc -R /usr/lib/qm/rootfs -m systemctl enable hirte-agent.service
storage ${rootfs}
restorecon -R ${rootfs}
}

install ${ROOTFS}
replaceIDs /etc/subuid qmcontainers ${qmContainerIDs}
replaceIDs /etc/subgid qmcontainers ${qmContainerIDs}
replaceIDs /etc/subuid containers ${containerIDs}
replaceIDs /etc/subgid containers ${containerIDs}

systemctl daemon-reload
systemctl start qm.service
case "$1" in
hirte-agent)
rm -f ${ROOTFS}${AGENTCONF}
hirteSetup ${ROOTFS}
;;
*)
install ${ROOTFS}
replaceIDs /etc/subuid qmcontainers ${qmContainerIDs}
replaceIDs /etc/subgid qmcontainers ${qmContainerIDs}
replaceIDs /etc/subuid containers ${containerIDs}
replaceIDs /etc/subgid containers ${containerIDs}
systemctl daemon-reload
systemctl start qm.service
;;
esac

0 comments on commit 3b6a2f6

Please sign in to comment.