fix: Linux Gateway 服务管理 (#7,#8,#10) + 非root部署 (#9) + 官网锚点滚动修复

This commit is contained in:
晴天
2026-03-06 20:28:13 +08:00
parent 881b49c9ef
commit 7d387a4f94
8 changed files with 275 additions and 66 deletions

View File

@@ -7,11 +7,32 @@ echo " 在 Linux 上通过浏览器管理 OpenClaw"
echo "=========================================="
echo ""
INSTALL_DIR="/opt/clawpanel"
PANEL_PORT=1420
REPO_URL="https://github.com/qingchencloud/clawpanel.git"
NPM_REGISTRY="https://registry.npmmirror.com"
# 检测权限模式
if [ "$(id -u)" = "0" ]; then
IS_ROOT=true
INSTALL_DIR="/opt/clawpanel"
SYSTEMD_DIR="/etc/systemd/system"
echo "🔑 以 root 身份运行,安装到 $INSTALL_DIR"
else
IS_ROOT=false
INSTALL_DIR="$HOME/.local/share/clawpanel"
SYSTEMD_DIR="$HOME/.config/systemd/user"
echo "👤 以普通用户身份运行,安装到 $INSTALL_DIR"
fi
# 带权限执行(安装系统包时需要)
run_pkg_cmd() {
if [ "$IS_ROOT" = true ]; then
"$@"
else
sudo "$@"
fi
}
# 检测系统
detect_os() {
if [ -f /etc/os-release ]; then
@@ -41,18 +62,18 @@ install_node() {
echo "📦 安装 Node.js 22 LTS..."
case "$OS" in
ubuntu|debian|linuxmint|pop)
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
curl -fsSL https://deb.nodesource.com/setup_22.x | run_pkg_cmd bash -
run_pkg_cmd apt-get install -y nodejs
;;
centos|rhel|fedora|rocky|alma)
curl -fsSL https://rpm.nodesource.com/setup_22.x | sudo bash -
sudo yum install -y nodejs
curl -fsSL https://rpm.nodesource.com/setup_22.x | run_pkg_cmd bash -
run_pkg_cmd yum install -y nodejs
;;
alpine)
sudo apk add nodejs npm git
run_pkg_cmd apk add nodejs npm git
;;
arch|manjaro)
sudo pacman -Sy --noconfirm nodejs npm git
run_pkg_cmd pacman -Sy --noconfirm nodejs npm git
;;
*)
echo "❌ 不支持自动安装 Node.js请手动安装后重试"
@@ -73,16 +94,16 @@ install_git() {
echo "📦 安装 Git..."
case "$OS" in
ubuntu|debian|linuxmint|pop)
sudo apt-get update && sudo apt-get install -y git
run_pkg_cmd apt-get update && run_pkg_cmd apt-get install -y git
;;
centos|rhel|fedora|rocky|alma)
sudo yum install -y git
run_pkg_cmd yum install -y git
;;
alpine)
sudo apk add git
run_pkg_cmd apk add git
;;
arch|manjaro)
sudo pacman -Sy --noconfirm git
run_pkg_cmd pacman -Sy --noconfirm git
;;
esac
echo "✅ Git 安装完成"
@@ -114,8 +135,7 @@ install_clawpanel() {
npm install
else
echo "📦 克隆 ClawPanel..."
sudo mkdir -p "$INSTALL_DIR"
sudo chown -R $(whoami) "$INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
git clone "$REPO_URL" "$INSTALL_DIR"
cd "$INSTALL_DIR"
npm install
@@ -132,7 +152,10 @@ setup_systemd() {
fi
echo "🔧 创建 systemd 服务..."
sudo tee /etc/systemd/system/clawpanel.service > /dev/null << EOF
mkdir -p "$SYSTEMD_DIR"
if [ "$IS_ROOT" = true ]; then
cat > "$SYSTEMD_DIR/clawpanel.service" << EOF
[Unit]
Description=ClawPanel Web - OpenClaw Management Panel
After=network.target
@@ -150,10 +173,33 @@ Environment=HOME=$HOME
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable clawpanel
systemctl start clawpanel
else
cat > "$SYSTEMD_DIR/clawpanel.service" << EOF
[Unit]
Description=ClawPanel Web - OpenClaw Management Panel
After=network.target
sudo systemctl daemon-reload
sudo systemctl enable clawpanel
sudo systemctl start clawpanel
[Service]
Type=simple
WorkingDirectory=$INSTALL_DIR
ExecStart=$(which npx) vite --port $PANEL_PORT --host 0.0.0.0
Restart=on-failure
RestartSec=5
Environment=NODE_ENV=production
Environment=HOME=$HOME
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable clawpanel
systemctl --user start clawpanel
# 允许用户服务在未登录时继续运行
loginctl enable-linger "$(whoami)" 2>/dev/null || true
fi
echo "✅ systemd 服务已创建并启动"
}
@@ -175,6 +221,13 @@ main() {
setup_systemd
local ip=$(get_local_ip)
if [ "$IS_ROOT" = true ]; then
local ctl_cmd="systemctl"
else
local ctl_cmd="systemctl --user"
fi
echo ""
echo "=========================================="
echo " ✅ ClawPanel Web 版部署完成!"
@@ -185,9 +238,13 @@ main() {
echo " 📋 配置目录: $HOME/.openclaw/"
echo ""
echo " 常用命令:"
echo " systemctl status clawpanel # 查看状态"
echo " systemctl restart clawpanel # 重启面板"
echo " journalctl -u clawpanel -f # 查看日志"
echo " $ctl_cmd status clawpanel # 查看状态"
echo " $ctl_cmd restart clawpanel # 重启面板"
if [ "$IS_ROOT" = true ]; then
echo " journalctl -u clawpanel -f # 查看日志"
else
echo " journalctl --user -u clawpanel -f # 查看日志"
fi
echo ""
echo " 用浏览器打开上面的地址,即可管理 OpenClaw。"
echo "=========================================="