Grubinst_gui.exe Can`t Run Background Program
I connect to the linux server via putty SSH. I tried to run it as a background process like this:
Programs run in task manager but invisible on. If the program can't fully open. The program is designed to run in the background and not.
However, after 2.5 hrs the terminal becomes inactive and the process dies. Is there anyway I can keep the process alive even with the terminal disconnected?
Edit 1
Actually, I tried nohup
, but as soon as I close the Putty SSH terminal or unplug my internet, the server process stops right away.
Is there anything I have to do in Putty?
Edit 2 (on Feb, 2012)
There is a node.js
module, forever. It will run node.js server as daemon service.
14 Answers
Simple solution (if you are not interested in coming back to the process, just want it to keep running):
Powerful solution (allows you to reconnect to the process if it is interactive):
You can then detach by pressing Ctrl+a+d and then attach back by running screen -r
Also consider the newer alternative to screen, tmux.
nohup node server.js > /dev/null 2>&1 &
nohup
means: Do not terminate this process even when the stty is cutoff.> /dev/null
means: stdout goes to /dev/null (which is a dummydevice that does not record any output).2>&1
means: stderr also goes to the stdout (which is already redirected to/dev/null
). You may replace &1 with a file path to keep a log of errors, e.g.:2>/tmp/myLog
&
at the end means: run this command as a background task.
You really should try to use screen
. It is a bit more complicated than just doing nohup long_running &
, but understanding screen once you never come back again.
Start your screen session at first:
Run anything you want:
Press ctrl+A and then d. Done. Your session keeps going on in background.
You can list all sessions by screen -ls
, and attach to some by screen -r 20673.pts-0.srv
command, where 0673.pts-0.srv is an entry list.
This is an old question, but is high ranked on Google. I almost can't believe on the highest voted answers, because running a node.js process inside a screen session, with the &
or even with the nohup
flag -- all of them -- are just workarounds.
Specially the screen/tmux solution, which should really be considered an amateur solution. Screen and Tmux are not meant to keep processes running, but for multiplexing terminal sessions. It's fine, when you are running a script on your server and want to disconnect. But for a node.js server your don't want your process to be attached to a terminal session. This is too fragile. To keep things running you need to daemonize the process!
There are plenty of good tools to do that.
PM2: http://pm2.keymetrics.io/
One big advantage I see in favor of PM2 is that it can generate the system startup script to make the process persist between restarts:
Where platform
can be ubuntu centos redhat gentoo systemd darwin amazon
.
forever.js: https://github.com/foreverjs/forever
Init scripts:
I'm not go into detail about how to write a init script, because I'm not an expert in this subject and it'd be too long for this answer, but basically they are simple shell scripts, triggered by OS events. You can read more about this here
Docker:
Just run your server in a Docker container with -d
option and, voilá, you have a daemonized node.js server!
Here is a sample Dockerfile (from node.js official guide):
Then build your image and run your container:
Hope this helps somebody landing on this page. Always use the proper tool for the job. It'll save you a lot of headaches and over hours!
nohup
will allow the program to continue even after the terminal dies. I have actually had situations where nohup
prevents the SSH session from terminating correctly, so you should redirect input as well:
Depending on how nohup
is configured, you may also need to redirect standard output and standard error to files.
I have this function in my shell rc file, based on @Yoichi's answer:
You can use it this way:
Nohup and screen offer great light solutions to running Node.js in the background. Node.js process manager (PM2) is a handy tool for deployment. Install it with npm globally on your system:
npm install pm2 -g
to run a Node.js app as a daemon:
pm2 start app.js
You can optionally link it to Keymetrics.io a monitoring SAAS made by Unitech.
It will remove command from active task list and send the command to background
To run command as a system service on debian with sysv init:
Copy skeleton script and adapt it for your needs, probably all you have to do is to set some variables. Your script will inherit fine defaults from /lib/init/init-d-script
, if something does not fits your needs - override it in your script. If something goes wrong you can see details in source /lib/init/init-d-script
. Mandatory vars are DAEMON
and NAME
. Script will use start-stop-daemon
to run your command, in START_ARGS
you can define additional parameters of start-stop-daemon
to use.
Color Run Background
That is how I run some python stuff for my wikimedia wiki:
Besides setting vars I had to override do_stop_cmd
because of python substitutes the executable, so service did not stop properly.
Apart from cool solutions above I'd mention also about supervisord and monit tools which allow to start process, monitor its presence and start it if it died. With 'monit' you can also run some active checks like check if process responds for http request
For Ubuntu i use this:
(exec PROG_SH &> /dev/null &)
regards
protected by Community♦Jul 25 '15 at 1:47
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?