1

I'm currently running a simple Node.JS server with express.js on my RaspberryPi with Debian installed on it. Everything works fine, but every morning I wake up to see my server isn't running anymore (the server process I started with node main.js).

My first guess was, that the Pi has some kind of sleep mode, which it enters after a couple of hours without traffic/etc, and which shuts down the server, but I also run a dydns-client, which is still up every morning.

Is there a way to track a process after I started it to check tomorrow morning, what killed my process or why it ended?

The server itself looks pretty simple and I don't think there is some kind of auto-shutdown I missed. Here is the code I used.

var express = require('express');
var path    = require('path');

var server  = express();
server.use(express.static(path.join(__dirname, 'public')));

server.listen(1337);
console.log("Server listening (PORT: " + 1337 + ") ...");

Any idea what to do, to keep the server running/find out what is the stopping reason?

0

You can make use of some process management tools like pm2 or forever.

If you are using pm2, you can do pm2 start main.js. It will monitor and restart the process if it gets killed. You can find the error reason in pm2 logs located inside ~/.pm2

You can run pm2 startup to generate the init script that allows pm2 to run on boot.

pm2 save saves the current process list so that they can be run on system reboot.

| improve this answer | |
  • Thanks for the answer forever seems quite interesting, but I actually received this post, which solved my problem (starting via SSH). – LastSecondsToLive May 13 '16 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.