代码:
cat > /etc/systemd/system/KeepCPUMemory.service <<EOF
[Unit]
[Service]
CPUQuota=40%
ExecStart=/usr/bin/python3 /tmp/waste.py
[Install]
WantedBy=multi-user.target
EOF
cat > /tmp/waste.py <<EOF
import platform
if platform.machine()=="aarch64":
memory = bytearray(int(2.4*1024*1024*1024)) # 2.4G (10% of 24G)
while True:
pass
EOF
cat > /etc/systemd/system/KeepNetwork.service <<EOF
[Unit]
After=network-online.target
[Service]
ExecStart=/usr/bin/bash /tmp/network.sh
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
cat > /tmp/network.sh <<EOF
while true
do
curl -s -o /dev/null --limit-rate 1M http://cachefly.cachefly.net/100mb.test
done
EOF
systemctl daemon-reload
systemctl enable KeepCPUMemory --now
systemctl enable KeepNetwork --now
以上是Arm(4核24G) 的模版,如果是Amd(2核1G) CPUQuota=20%
执行文件存放在/tmp目录。机器重启就失效
或者删掉脚本就可以停了