26 lines
795 B
JavaScript
26 lines
795 B
JavaScript
const { spawn } = require('child_process');
|
|
const http = require('http');
|
|
|
|
function startServer() {
|
|
const child = spawn('node', ['server.js'], {
|
|
cwd: '/home/z/my-project/.next/standalone',
|
|
env: { ...process.env, PORT: '3000', NODE_ENV: 'production' },
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
});
|
|
child.stdout.on('data', d => process.stdout.write(d));
|
|
child.stderr.on('data', d => process.stderr.write(d));
|
|
child.on('exit', () => { console.log('Server exited, restarting...'); setTimeout(startServer, 2000); });
|
|
return child;
|
|
}
|
|
|
|
startServer();
|
|
|
|
// Keepalive ping every 8s
|
|
setInterval(() => {
|
|
const req = http.get('http://localhost:3000/', () => {});
|
|
req.on('error', () => {});
|
|
req.setTimeout(3000, () => req.destroy());
|
|
}, 8000);
|
|
|
|
console.log('Keepalive process started');
|