fix: add KillMode=process so remote-control survives restarts

systemd's default KillMode=control-group kills all processes in the
cgroup on service restart, including the detached claude remote-control
process. KillMode=process only kills the main Node.js process, letting
detached children survive. restoreRemoteControl() already handles
reattaching on startup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Gabi Simons
2026-03-16 13:12:07 +02:00
parent 12ff2589fa
commit 260812702c
2 changed files with 12 additions and 0 deletions

View File

@@ -62,6 +62,7 @@ ExecStart=${nodePath} ${projectRoot}/dist/index.js
WorkingDirectory=${projectRoot} WorkingDirectory=${projectRoot}
Restart=always Restart=always
RestartSec=5 RestartSec=5
KillMode=process
Environment=HOME=${homeDir} Environment=HOME=${homeDir}
Environment=PATH=/usr/local/bin:/usr/bin:/bin:${homeDir}/.local/bin Environment=PATH=/usr/local/bin:/usr/bin:/bin:${homeDir}/.local/bin
StandardOutput=append:${projectRoot}/logs/nanoclaw.log StandardOutput=append:${projectRoot}/logs/nanoclaw.log
@@ -142,6 +143,16 @@ describe('systemd unit generation', () => {
expect(unit).toContain('RestartSec=5'); expect(unit).toContain('RestartSec=5');
}); });
it('uses KillMode=process to preserve detached children', () => {
const unit = generateSystemdUnit(
'/usr/bin/node',
'/home/user/nanoclaw',
'/home/user',
false,
);
expect(unit).toContain('KillMode=process');
});
it('sets correct ExecStart', () => { it('sets correct ExecStart', () => {
const unit = generateSystemdUnit( const unit = generateSystemdUnit(
'/usr/bin/node', '/usr/bin/node',

View File

@@ -243,6 +243,7 @@ ExecStart=${nodePath} ${projectRoot}/dist/index.js
WorkingDirectory=${projectRoot} WorkingDirectory=${projectRoot}
Restart=always Restart=always
RestartSec=5 RestartSec=5
KillMode=process
Environment=HOME=${homeDir} Environment=HOME=${homeDir}
Environment=PATH=/usr/local/bin:/usr/bin:/bin:${homeDir}/.local/bin Environment=PATH=/usr/local/bin:/usr/bin:/bin:${homeDir}/.local/bin
StandardOutput=append:${projectRoot}/logs/nanoclaw.log StandardOutput=append:${projectRoot}/logs/nanoclaw.log