Skip to content

Instantly share code, notes, and snippets.

@pratos
Last active March 15, 2021 07:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pratos/9103c9858775102f3b2011e857f9f769 to your computer and use it in GitHub Desktop.
Save pratos/9103c9858775102f3b2011e857f9f769 to your computer and use it in GitHub Desktop.
Avoid disconnection to Digital Ocean Server and keeping a python script running
cd
cd /etc/ssh
sudo nano sshd_config

Search for keepalive (Use Ctrl+W to search) Add the below

ClientAliveInterval 30
TCPKeepAlive yes
ClientAliveCountMax 99999

Restart the service

service ssh restart

Will ask for login if not 'root' user Enter the credentials and done, below is the output you get:::

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'ssh.service'.
Authenticating as: xxx
Password:
==== AUTHENTICATION COMPLETE ===

To keep the python script running even after logging off Source: http://askubuntu.com/questions/8653/how-to-keep-processes-running-after-ending-ssh-session ssh into the remote machine start tmux

$ tmux

Start the process you want inside the started tmux session. Leave/detach the tmux session by typing Ctrl+B and then D You can now safely log off from the remote machine, your process will keep running inside tmux. When you come back again and want to check the status of your process you can use:

$ tmux attach 

If you want to have multiple sessions running side-by-side, you should name each session using Ctrl-B and $. Rename the session and press "Enter". You can get a list of the currently running sessions using:

$ tmux list-sessions

To attach to a specific session

$ tmux attach -t <session-name/no>

Can run two separate servers in a single tmux session, running Frontend server and Model API server both on one Digital Ocean machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment