I'm trying to get a node.js application to run as a daemon in the background. I installed pm2 with the -g option and I can start and have it run in the background. As soon as I disconnect with 'exit' the process stops. I have done the same thing on my raspberry pi and it keeps running. As you can see from the sequence below like the pm2 daemon exits when I disconnect.
Here is the command sequence:
root@edison-toll:~# cd pingerjs
root@edison-toll:~/pingerjs# pm2 start main.js --name "pingerjs"
[PM2] Process main.js launched
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────────┬─────────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
├──────────┼────┼──────┼─────┼────────┼───────────┼────────┼────────────┼─────────────┤
│ pingerjs│ 0 │fork│ 860 │online│ 0 │ 0s │ 4.789 MB │unactivated│
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────────┴─────────────┘
Use `pm2 desc[ribe] <id>` to get more details
root@edison-toll:~/pingerjs# pm2 describe pingerjs
Describing process with pid 0 - name pingerjs
┌───────────────────┬─────────────────────────────────────────┐
│ status │online │
│ name │ pingerjs │
│ id │ 0 │
│ path │ /home/root/pingerjs/main.js │
│ args │ │
│ exec cwd │ /home/root/pingerjs │
│ error log path │ /home/root/.pm2/logs/pingerjs-err-0.log │
│ out log path │ /home/root/.pm2/logs/pingerjs-out-0.log │
│ pid path │ /home/root/.pm2/pids/pingerjs-0.pid │
│ mode │ fork_mode │
│ node v8 arguments │ │
│ watch & reload │✘ │
│ interpreter │ node │
│ restarts │ 0 │
│ unstable restarts │ 0 │
│ uptime │ 14s │
│ created at │ 2014-10-11T14:41:25.614Z │
└───────────────────┴─────────────────────────────────────────┘
root@edison-toll:~/pingerjs# exit
logout
Connection to edison-toll.local closed.
rods-mbp:/ rodtoll$ ssh root@edison-toll.local
root@edison-toll.local's password:
root@edison-toll:~# cd pingerjs
root@edison-toll:~/pingerjs# pm2 list
Starting PM2 daemon...
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────┴──────────┘
Use `pm2 desc[ribe] <id>` to get more details
root@edison-toll:~/pingerjs#
root@edison-toll:~/pingerjs#
root@edison-toll:~/pingerjs# node -v
v0.10.28
root@edison-toll:~/pingerjs#