-1

Every time I turn off Putty after I write: sudo node server.js & (after getting the process started) a few seconds later it shuts down the website.

and than i see that it had deleted the process...

what can be the reason?

ok i need to add some information: it happens only after i fill a form of nodemailer and send it to the server.js, then it kills the process and everything shuts down. the form is the trigger not anything else!

phoenix999
  • 11
  • 4
  • Possible duplicate of [In Linux, how to prevent a background process from being stopped after closing SSH client](https://stackoverflow.com/q/285015/608639), [How to make a program continue to run after log out from ssh?](https://stackoverflow.com/q/954302/608639), [Run a command in a shell and keep running the command when you close the session](https://stackoverflow.com/q/431521/608639), etc. – jww May 06 '19 at 21:48

2 Answers2

3

When the SSH session ends (disconnects) it kills the process.

It sounds like you need forever or nohup or my personal favorite PM2.
Forever: https://github.com/foreverjs/forever
PM2: https://github.com/Unitech/pm2

Randy
  • 4,231
  • 2
  • 24
  • 44
  • I think Randy is onto something will check it out – Drew Jun 26 '15 at 01:36
  • Sounds right. Guy has same symptoms as you with `&`. See the comments. http://stackoverflow.com/questions/21193988/keep-server-running-on-ec2-instance-after-ssh-is-terminated. under Rico's answer – Drew Jun 26 '15 at 01:43
0

It's most likely an issue with your server.js (or mailer) code. I've been running a node program as a background process on ec2 for quite a while...

--------------------------- edit ---------------------------

You would need to use nohup or another longer term service to maintain the program binding after logging off.

I would suggest you look into something like Screen. It is a window manager that allows you to detach a shell, but still keep a process running in it. That would avoid nasty log files and stuff like that, plus it can be easily reaccessed.

14bmkelley
  • 17
  • 5