Skip to content

Commit 5c51590

Browse files
committed
fix: move cpu-state drop-in after k3s install and extract to script
Move the systemd drop-in from before k3s install to after, so the k3s-agent.service unit already exists. Extract the inline one-liner to /usr/local/bin/5stack-cpu-state-check.sh for readability. Eliminates redundant mkdir and daemon-reload calls.
1 parent 59a4943 commit 5c51590

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

src/game-server-node/game-server-node.controller.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,6 @@ export class GameServerNodeController {
252252
rm -f /etc/rancher/k3s/config.yaml
253253
rm -f /var/lib/kubelet/cpu_manager_state
254254
255-
mkdir -p /etc/systemd/system/k3s-agent.service.d
256-
257-
cat <<-'DROPIN' >/etc/systemd/system/k3s-agent.service.d/cpu-state-check.conf
258-
[Service]
259-
ExecStartPre=/bin/bash -c 'STATE=/var/lib/kubelet/cpu_manager_state; [ ! -f "$STATE" ] && exit 0; CACHE="$(dirname "$STATE")/cpu_count"; CURRENT=$(nproc); PREVIOUS=$(cat "$CACHE" 2>/dev/null || echo "$CURRENT"); if [ "$CURRENT" != "$PREVIOUS" ]; then echo "CPU count changed from $PREVIOUS to $CURRENT, removing $STATE"; rm -f "$STATE"; fi; echo "$CURRENT" > "$CACHE"'
260-
DROPIN
261-
262-
systemctl daemon-reload
263-
264255
echo "Installing k3s";
265256
curl -sfL https://get.k3s.io | K3S_URL=https://${process.env.TAILSCALE_NODE_IP}:6443 K3S_TOKEN=${process.env.K3S_TOKEN} sh -s - --node-name ${gameServerNodeId} --vpn-auth="name=tailscale,joinKey=${game_server_nodes_by_pk.token}"
266257
@@ -302,6 +293,30 @@ cat <<-EOF >/etc/rancher/k3s/config.yaml
302293
- "kube-reserved=cpu=1"
303294
EOF
304295
296+
cat <<-'SCRIPT' >/usr/local/bin/5stack-cpu-state-check.sh
297+
#!/bin/bash
298+
STATE=/var/lib/kubelet/cpu_manager_state
299+
[ ! -f "$STATE" ] && exit 0
300+
CACHE="$(dirname "$STATE")/cpu_count"
301+
CURRENT=$(nproc)
302+
PREVIOUS=$(cat "$CACHE" 2>/dev/null || echo "$CURRENT")
303+
if [ "$CURRENT" != "$PREVIOUS" ]; then
304+
echo "CPU count changed from $PREVIOUS to $CURRENT, removing $STATE"
305+
rm -f "$STATE"
306+
fi
307+
echo "$CURRENT" > "$CACHE"
308+
SCRIPT
309+
chmod +x /usr/local/bin/5stack-cpu-state-check.sh
310+
311+
mkdir -p /etc/systemd/system/k3s-agent.service.d
312+
313+
cat <<-'DROPIN' >/etc/systemd/system/k3s-agent.service.d/cpu-state-check.conf
314+
[Service]
315+
ExecStartPre=/usr/local/bin/5stack-cpu-state-check.sh
316+
DROPIN
317+
318+
systemctl daemon-reload
319+
305320
rm -f /var/lib/kubelet/cpu_manager_state
306321
307322
systemctl restart k3s-agent

0 commit comments

Comments
 (0)