feat: add structured logging, process watchdog, and systemd hardening
- Add lib/logger.js: timestamped structured logging with 5MB x 5 file rotation - Add lib/watchdog.js: generic child process supervisor with rate-limited restarts - Enhance client.js: WS ping/pong liveness detection, uncaughtException/unhandledRejection handlers, systemd sd-notify integration - Refactor frpc.js: FrpcManager now delegates to Watchdog instead of manual spawn/exit - Enhance install.sh: environment file, log directory, systemd resource limits, security hardening, WatchdogSec=60 - Replace all console.log/warn/error with structured logger across modules Made-with: Cursor
This commit is contained in:
16
bin/clawd.js
16
bin/clawd.js
@@ -2,10 +2,20 @@
|
||||
'use strict';
|
||||
|
||||
const { ClawClient } = require('../lib/client');
|
||||
const log = require('../lib/logger');
|
||||
|
||||
const client = new ClawClient();
|
||||
client.start();
|
||||
|
||||
// 优雅退出
|
||||
process.on('SIGINT', () => { client.stop(); process.exit(0); });
|
||||
process.on('SIGTERM', () => { client.stop(); process.exit(0); });
|
||||
let stopping = false;
|
||||
|
||||
function shutdown(signal) {
|
||||
if (stopping) return;
|
||||
stopping = true;
|
||||
log.info('clawd', `收到 ${signal},正在停止...`);
|
||||
client.stop();
|
||||
setTimeout(() => process.exit(0), 500);
|
||||
}
|
||||
|
||||
process.on('SIGINT', () => shutdown('SIGINT'));
|
||||
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
||||
|
||||
Reference in New Issue
Block a user