summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-28 01:00:54 +0900
committerAdam Malczewski <[email protected]>2026-06-28 01:00:54 +0900
commitb3b6eb41c5a436c95602aeaacb93ef63ec6c285f (patch)
treeae1ac998a550995672d7d3fa6d8378777dc79583
parentd1de9ed854addd9cf626af27b41f93f2b59f04ac (diff)
downloaddispatch-b3b6eb41c5a436c95602aeaacb93ef63ec6c285f.tar.gz
dispatch-b3b6eb41c5a436c95602aeaacb93ef63ec6c285f.zip
feat(bin): apply-memory-limits.sh — apply MemoryMax cgroup limits to live service
Hands the user a one-command script to apply the systemd MemoryMax/MemoryHigh cgroup limits to the live dispatch.service without a full reinstall. Patches in the real user (same as bin/install), daemon-reloads, and restarts.
-rwxr-xr-xbin/apply-memory-limits.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/bin/apply-memory-limits.sh b/bin/apply-memory-limits.sh
new file mode 100755
index 0000000..f5c9cf0
--- /dev/null
+++ b/bin/apply-memory-limits.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+# apply-memory-limits.sh — apply the MemoryMax/MemoryHigh cgroup limits to the
+# LIVE dispatch.service WITHOUT a full reinstall. Safe to run while the server
+# is up (the limits take effect on the next restart).
+#
+# What it does (all privileged lines use sudo):
+# 1. Copies the updated dispatch.service template to /etc/systemd/system/ (sudo)
+# 2. Reloads systemd so it picks up the new unit file (sudo)
+# 3. Restarts dispatch so the cgroup limits are applied (sudo)
+#
+# Why sudo: /etc/systemd/system/ is root-owned; daemon-reload and restart
+# require root. The script carries its own sudo — run it directly (no sudo prefix).
+#
+# Run: ./bin/apply-memory-limits.sh
+
+set -euo pipefail
+
+HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ROOT="$(cd "$HERE/.." && pwd)"
+
+SERVICE_SRC="$ROOT/systemd/dispatch.service"
+SERVICE_DST="/etc/systemd/system/dispatch.service"
+
+if [ ! -f "$SERVICE_SRC" ]; then
+ echo "apply-memory-limits: template not found at $SERVICE_SRC" >&2
+ exit 1
+fi
+
+echo "[apply] copying updated dispatch.service → $SERVICE_DST"
+# Patch in the real user (same as bin/install does)
+REAL_USER="${SUDO_USER:-$USER}"
+REAL_GROUP=$(id -gn "$REAL_USER" 2>/dev/null || echo "$REAL_USER")
+sed "s/^# User\/Group are set by bin/install.*/User=$REAL_USER\nGroup=$REAL_GROUP/" "$SERVICE_SRC" | sudo tee "$SERVICE_DST" > /dev/null
+sudo chmod 644 "$SERVICE_DST"
+
+echo "[apply] daemon-reload…"
+sudo systemctl daemon-reload
+
+echo "[apply] restarting dispatch (cgroup limits take effect)…"
+sudo systemctl restart dispatch
+
+echo "[apply] done!"
+echo " Status: systemctl status dispatch"
+echo " Memory: systemctl show dispatch -p MemoryHigh -p MemoryMax"
+echo " Logs: journalctl -u dispatch -f"