#!/usr/bin/env bash
set -euo pipefail

dropin_dir="/etc/systemd/system/actions.runner.platform-modules-mod.platform-devbox.service.d"
dropin="$dropin_dir/resource-control.conf"

if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then
  echo "install-actions-runner-resource-control: run with sudo" >&2
  exit 1
fi

mkdir -p "$dropin_dir"
cat > "$dropin" <<'EOF'
[Service]
Environment="PATH=/home/user/.claude/bin:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Environment="BUILD_PER_JOB_CPU=200"
Environment="BUILD_NODE_HEAP=4096"
CPUWeight=40
IOWeight=40
MemoryHigh=24G
MemoryMax=32G
TasksMax=512
EOF

systemctl daemon-reload
systemctl restart actions.runner.platform-modules-mod.platform-devbox.service
systemctl cat actions.runner.platform-modules-mod.platform-devbox.service
