Linux – How to prevent a nohup process from being killed when ssh connection fails

linuxnohupprocessssh

I'm having an odd problem. I have a server process that gets started with nohup, and persists across logout and re-login just fine. However if I leave myself logged in and then get the "broken pipe" message because my laptop went to sleep I come back to find that the process stopped at approximately the time my laptop went to sleep (hard to verify exactly when that was though). This happens even if I have logged out and logged back in since starting the process.

Why does this happen? I had thought nohup meant it would ignore SIGHUP? Is some other signal being sent? I am aware of screen, but is there a way to avoid this without resorting to running things in screen (which was the previous solution we just moved away from)?

The command in the script that starts the process looks like this…

nohup attivio -cmd start -nodump -project="$ATTIVIO_PROJECT" -node $NODENAME $ATTIVIO_ARGS foo.xml 2>&1 > $LOG_DIR/attivio.console.log &

The script was invoked like this:

source bin/start.sh 

Best Answer

The HUP signal is not the only thing that can stop or kill a process when a terminal disconnects. There will be no controlling tty so some program may still fail for that reason. Attempts to output can cause an error. If the program has an active read, it may get an error, too.

These are reasons I do use screen. I see no reason to avoid screen.