跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

guest-memory.sh

43 行 · 1.6 KB历史下载
1# A small compressed swap area absorbs short allocation bursts while the host
2# adjusts the balloon. It consumes RAM only as used and is bounded at 2 GiB.
3# Containers share the host kernel. Their memory and swap limits belong to
4# the container cgroup; never load host modules or create swap devices here.
5if ! systemd-detect-virt --container --quiet; then
6sudo tee /usr/local/bin/cage-memory-start >/dev/null <<'SCRIPT'
7#!/bin/sh
8set -eu
9if [ -f /run/cage-zram-device ]; then
10 device=$(cat /run/cage-zram-device)
11 if grep -q "^$device " /proc/swaps; then exit 0; fi
12fi
13modprobe zram
14number=$(cat /sys/class/zram-control/hot_add)
15device=/dev/zram$number
16cleanup() { echo "$number" > /sys/class/zram-control/hot_remove; }
17trap cleanup EXIT
18size=$(awk '/^MemTotal:/ { n=int($2*1024/4); if(n>2147483648)n=2147483648; printf "%.0f",n }' /proc/meminfo)
19echo "$size" > "/sys/block/zram$number/disksize"
20mkswap "$device" >/dev/null
21swapon -p 100 "$device"
22printf '%s\n' "$device" > /run/cage-zram-device
23trap - EXIT
24SCRIPT
25sudo chmod 0755 /usr/local/bin/cage-memory-start
26sudo tee /etc/systemd/system/cage-memory.service >/dev/null <<'UNIT'
27[Unit]
28Description=Cage compressed memory reserve
29After=systemd-modules-load.service
30Before=cage-browser.service cage-editor.service
31[Service]
32Type=oneshot
33RemainAfterExit=yes
34ExecStart=/usr/local/bin/cage-memory-start
35[Install]
36WantedBy=multi-user.target
37UNIT
38sudo systemctl daemon-reload
39sudo systemctl enable cage-memory.service >/dev/null
40if ! sudo systemctl start cage-memory.service; then
41 printf 'Compressed memory reserve unavailable; automatic host memory management remains enabled.\n' >&2
42fi
43fi