OpenClaw人人养虾:后台执行

张开发
2026/4/10 11:42:04 15 分钟阅读

分享文章

OpenClaw人人养虾:后台执行
生产环境中Gateway 通常需要以守护进程Daemon模式在后台运行并在系统启动时自动启动、崩溃后自动重启。内置 Daemon 模式# 以守护进程模式启动 openclaw gateway --daemon # 查看状态 openclaw status # 停止 openclaw gateway stop开发 vs 生产开发时使用前台模式直接openclaw gateway方便查看日志。生产环境使用下述进程管理器确保可靠运行。systemdLinux 推荐创建服务文件# /etc/systemd/system/openclaw.service [Unit] DescriptionOpenClaw Gateway Documentationhttps://docs.openclaw.dev Afternetwork-online.target Wantsnetwork-online.target [Service] Typesimple Useropenclaw Groupopenclaw WorkingDirectory/home/openclaw EnvironmentOPENCLAW_GATEWAY_TOKENyour-token-here EnvironmentOPENCLAW_GATEWAY_HOST0.0.0.0 ExecStart/usr/local/bin/openclaw gateway Restartalways RestartSec5 StandardOutputjournal StandardErrorjournal # 安全加固 NoNewPrivilegestrue ProtectSystemstrict ProtectHomeread-only ReadWritePaths/home/openclaw/.openclaw [Install] WantedBymulti-user.target管理服务# 重新加载服务配置 sudo systemctl daemon-reload # 启用开机自启 sudo systemctl enable openclaw # 启动 sudo systemctl start openclaw # 查看状态 sudo systemctl status openclaw # 查看日志 sudo journalctl -u openclaw -f # 停止 sudo systemctl stop openclaw # 重启 sudo systemctl restart openclawsystemd 安全服务文件中的NoNewPrivileges、ProtectSystem、ProtectHome提供额外的系统级安全隔离。launchdmacOS 推荐创建 plist 文件?xml version1.0 encodingUTF-8? !DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd plist version1.0 dict keyLabel/key stringdev.openclaw.gateway/string keyProgramArguments/key array string/usr/local/bin/openclaw/string stringgateway/string /array keyEnvironmentVariables/key dict keyOPENCLAW_GATEWAY_TOKEN/key stringyour-token-here/string /dict keyRunAtLoad/key true/ keyKeepAlive/key true/ keyStandardOutPath/key string/tmp/openclaw.stdout.log/string keyStandardErrorPath/key string/tmp/openclaw.stderr.log/string /dict /plist管理服务# 安装 plist cp dev.openclaw.gateway.plist ~/Library/LaunchAgents/ # 加载并启动 launchctl load ~/Library/LaunchAgents/dev.openclaw.gateway.plist # 查看状态 launchctl list | grep openclaw # 停止并卸载 launchctl unload ~/Library/LaunchAgents/dev.openclaw.gateway.plistpm2跨平台 Node.js 进程管理器安装 pm2npm install -g pm2配置和启动# 直接启动 pm2 start openclaw -- gateway # 或使用配置文件 pm2 start ecosystem.config.js// ecosystem.config.js module.exports { apps: [{ name: openclaw-gateway, script: openclaw, args: gateway, env: { OPENCLAW_GATEWAY_TOKEN: your-token-here, OPENCLAW_GATEWAY_HOST: 0.0.0.0 }, restart_delay: 5000, max_restarts: 10, autorestart: true }] };管理# 查看状态 pm2 status # 查看日志 pm2 logs openclaw-gateway # 停止 pm2 stop openclaw-gateway # 重启 pm2 restart openclaw-gateway # 设置开机自启 pm2 startup pm2 saveDocker 容器使用 Dockerdocker run -d \ --name openclaw-gateway \ -p 18789:18789 \ -e OPENCLAW_GATEWAY_TOKENyour-token \ -e OPENCLAW_GATEWAY_HOST0.0.0.0 \ -v openclaw-data:/root/.openclaw \ --restart unless-stopped \ openclaw/gateway:latest使用 Docker Compose# docker-compose.yml version: 3.8 services: openclaw: image: openclaw/gateway:latest container_name: openclaw-gateway ports: - 18789:18789 environment: - OPENCLAW_GATEWAY_TOKEN${GATEWAY_TOKEN} - OPENCLAW_GATEWAY_HOST0.0.0.0 volumes: - openclaw-data:/root/.openclaw restart: unless-stopped healthcheck: test: [CMD, curl, -f, http://localhost:18789/health] interval: 30s timeout: 10s retries: 3 volumes: openclaw-data:# 启动 docker compose up -d # 查看日志 docker compose logs -f openclaw # 停止 docker compose down方案对比方案平台自动重启开机自启日志管理systemdLinux✅✅journaldlaunchdmacOS✅✅文件pm2跨平台✅✅内置Docker跨平台✅✅docker logs内置 daemon跨平台❌❌文件选择建议Linux 服务器→ systemdmacOS→ launchd跨平台/简单→ pm2容器化部署→ Docker《DeepSeek高效数据分析从数据清洗到行业案例》聚焦DeepSeek在数据分析领域的高效应用是系统讲解其从数据处理到可视化全流程的实用指南。作者结合多年职场实战经验不仅深入拆解DeepSeek数据分析的核心功能——涵盖数据采集、清洗、预处理、探索分析、建模回归、聚类、时间序列等及模型评估更通过金融量化数据分析、电商平台数据分析等真实行业案例搭配报告撰写技巧提供独到见解与落地建议。助力职场人在激烈竞争中凭借先进技能突破瓶颈实现职业进阶开启发展新篇。

更多文章