wakepy icon indicating copy to clipboard operation
wakepy copied to clipboard

Keep a remote server awake after closing SSH connection?

Open fohrloop opened this issue 1 year ago • 2 comments

Sometimes it might be useful to be able to ssh into a server, start a python process and disconnect from the server knowing that the process will continue running.

Todo:

  • what does this require?
  • Why a server without desktop environment stops executing a task?
  • is the solution such that could be included in wakepy?

Notes:

  • https://unix.stackexchange.com/questions/362115/how-to-keep-a-python-script-running-when-i-close-putty
  • https://askubuntu.com/questions/8653/how-to-keep-processes-running-after-ending-ssh-session

fohrloop avatar Jun 07 '24 22:06 fohrloop

I did a quick look on this topic. I'm not an expert on this but it seems that the reason why a script typically stops when someone exits SSH is a SIGHUP signal which gets send to all processes when terminal window with SSH connection is closed. The typical solutions involve using nohup, screen or tmux. This is not about keeping CPU awake, but about keeping a process from not getting stopped by a HUP signal. Therefore, I kind of think this might be out of scope of wakepy. If nohup yourscript.py & just works, why would wakepy need to implement a solution? If there was a solution, should that be some separate mode, like ignore.hup ?

In order to really consider adding a ignore.hup mode, should:

  • List at least one real use case, and explain why wakepy would be needed instead of nohup, screen or tmux?
  • Is this technically possible? Would it be as simple as:
import logging
import signal

logger = logging.getLogger(__name__)

def handler(signum, frame):
  logger.warning(f"Received {signum} signal. Doing nothing.")

signal.signal(signal.SIGHUP, handler)

fohrloop avatar Jun 08 '24 14:06 fohrloop

Related: https://github.com/fohrloop/wakepy/issues/203

Also could be possible to make wakepy ignore SIGHUP, by default but that's probably a bit too intrusive. Another possibility would be to add some nohup=False parameter to keep.running() and keep.presenting().

fohrloop avatar Jun 08 '24 15:06 fohrloop