개요
OpenClaw Gateway는 백그라운드 서비스로 지속적으로 실행되어야 합니다. 터미널에서 직접 실행하면 터미널을 닫을 때 서비스가 중지됩니다. 이 글에서는 다양한 백그라운드 프로세스 관리 방법을 소개합니다.
OpenClaw 내장 명령 사용
OpenClaw은 간단한 백그라운드 시작 명령을 제공합니다:
# 백그라운드 시작
openclaw start --daemon
# 실행 상태 확인
openclaw status
# 서비스 중지
openclaw stop
# 서비스 재시작
openclaw restart
PM2를 사용한 관리
PM2는 Node.js 생태계에서 가장 인기 있는 프로세스 관리자로, 기능이 풍부하고 사용이 간편합니다.
PM2 설치
npm install -g pm2
OpenClaw 시작
pm2 start openclaw -- start
설정 파일을 사용한 시작 (권장):
// ecosystem.config.js
module.exports = {
apps: [{
name: 'openclaw',
script: 'openclaw',
args: 'start',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '500M',
env: {
NODE_ENV: 'production'
},
error_file: '~/.openclaw/logs/pm2-error.log',
out_file: '~/.openclaw/logs/pm2-out.log',
log_date_format: 'YYYY-MM-DD HH:mm:ss'
}]
};
pm2 start ecosystem.config.js
PM2 주요 명령어
# 프로세스 목록 조회
pm2 list
# 로그 조회
pm2 logs openclaw
# 리소스 사용량 모니터링
pm2 monit
# 재시작
pm2 restart openclaw
# 리로드 (무중단)
pm2 reload openclaw
# 중지
pm2 stop openclaw
# 프로세스 삭제
pm2 delete openclaw
부팅 시 자동 시작 설정
pm2 startup
pm2 save
PM2가 해당 시스템에 맞는 자동 시작 스크립트를 자동으로 생성합니다.
systemd를 사용한 관리
Linux 시스템에 적합하며, 시스템 수준에 더 가까운 관리 방식입니다.
Service 파일 생성
sudo nano /etc/systemd/system/openclaw.service
[Unit]
Description=OpenClaw AI Assistant Gateway
After=network.target
Wants=network-online.target
[Service]
Type=simple
User=openclaw
Group=openclaw
WorkingDirectory=/home/openclaw
ExecStart=/usr/local/bin/openclaw start
ExecStop=/usr/local/bin/openclaw stop
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
SyslogIdentifier=openclaw
# 보안 설정
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=read-only
ReadWritePaths=/home/openclaw/.openclaw
# 리소스 제한
MemoryMax=512M
CPUQuota=80%
[Install]
WantedBy=multi-user.target
systemd 주요 명령어
# service 파일 리로드
sudo systemctl daemon-reload
# 시작
sudo systemctl start openclaw
# 중지
sudo systemctl stop openclaw
# 재시작
sudo systemctl restart openclaw
# 상태 확인
sudo systemctl status openclaw
# 부팅 시 자동 시작 설정
sudo systemctl enable openclaw
# 로그 조회
journalctl -u openclaw -f
journalctl -u openclaw --since "1 hour ago"
Docker를 사용한 관리
Docker는 자체 재시작 정책이 있어 별도의 프로세스 관리자가 필요 없습니다:
docker run -d \
--name openclaw \
--restart unless-stopped \
-v ~/.openclaw:/root/.openclaw \
openclaw/openclaw:latest start
Docker Compose:
services:
openclaw:
image: openclaw/openclaw:latest
restart: unless-stopped
volumes:
- openclaw-data:/root/.openclaw
command: start
macOS에서 launchd 사용
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.openclaw.gateway</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/openclaw</string>
<string>start</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/Users/you/.openclaw/logs/launchd-out.log</string>
<key>StandardErrorPath</key>
<string>/Users/you/.openclaw/logs/launchd-err.log</string>
</dict>
</plist>
cp com.openclaw.gateway.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/com.openclaw.gateway.plist
프로세스 모니터링
어떤 프로세스 관리 방식을 사용하든 모니터링 설정을 권장합니다:
{
"gateway": {
"monitoring": {
"enabled": true,
"metrics": {
"endpoint": "/metrics",
"format": "prometheus"
}
}
}
}
로그 로테이션
로그 파일이 과도하게 커지는 것을 방지합니다:
# /etc/logrotate.d/openclaw
/home/openclaw/.openclaw/logs/*.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
copytruncate
}
정리
적합한 프로세스 관리 방법 선택은 환경에 따라 달라집니다. Docker 배포에서는 Docker 자체 재시작 정책을 우선 사용하고, 베어메탈 Linux에서는 systemd를, Node.js 환경에서는 PM2를, macOS에서는 launchd를 사용하세요. 핵심 목표는 OpenClaw이 충돌 후 자동 복구되고 부팅 시 자동으로 시작되도록 하는 것입니다.