Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a script that starts a server on a remote VM. All works great until I close the shell where I executed the script. When the shell closes, so does the server. After some looking around I found the following:

  1. & will send the job to the background when executed with the symbol
  2. disown -h will disconnect the job from the shell and allow it to run regardless of the shell.

The command I used is:

./startServer.sh nasb_wxscat160_catalog-4.1.6 1.0.8 > catalog-log.txt & disown -h

When I closed the shell and checked using ps -ef | grep java to see if the job is still working I did see it in the list. However when I tried to connect to the server it was unresponsive.

On deeper inspection, the log file was filled just until I closed the shell and using the ps -m flag I say the process jobs were not working.

Has any one encountered some thing of this sort?

share|improve this question

migrated from stackoverflow.com Dec 10 '12 at 9:44

This question came from our site for professional and enthusiast programmers.

    
See: linux.die.net/man/1/nohup –  Paul R Dec 10 '12 at 7:45
    
@PaulR thank you. but can you explain the connection between the shell closing and the out to file? –  raven Dec 10 '12 at 8:12

2 Answers 2

For one-off jobs which do not daemonize themselves, I usually run them in a screen session. The disadvantage is that you have to start screen before starting the job. My process is usually something like this:

% screen -D -R   # start a new screen session, with reattachment options
% command_to_run_job
ctrl-A ctrl-D

That will run the job in the foreground, then detach from the screen session. Then you can log out, and later reconnect to it with another "screen -D -R"

share|improve this answer
    
thank you. i am new to all of this so can you explain what is a screen session? –  raven Dec 10 '12 at 8:07
    
screen is a virtual tty software that allows you to detach a terminal. –  Natim Dec 10 '12 at 10:11
    
Natim is right. Screen is a window manager for terminals. It's really useful if you're working on remote terminals. I suggest reading the man page (with the command "man screen"). –  velotron Dec 11 '12 at 0:48

The other thing you could do is to use supervisord or circus to run your program and make sure it will restart automatically if it stops.

http://circus.readthedocs.org

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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