0

So currently I'm trying to host a little bot I made in Python. It's meant to be running 24/7 so I tried Google cloud platform. I have a Ubuntu dist installed on a small scale VM server and I can run the bot perfectly. However when I exit out of my ssh session the python stops running. I've tried searching for solutions but I've found nothing.

So, how do I keep running python 24/7 on my Ubuntu VM?

  • 1
    Start with [tmux](https://en.wikipedia.org/wiki/Tmux), [screen](https://en.wikipedia.org/wiki/GNU_Screen) and all those tools. – sascha Jun 01 '18 at 21:58
  • 1
    Possible duplicate of [Linux: Prevent a background process from being stopped after closing SSH client](https://stackoverflow.com/questions/285015/linux-prevent-a-background-process-from-being-stopped-after-closing-ssh-client) – Max von Hippel Jun 01 '18 at 21:59

1 Answers1

1

The typical solution for this would be either tmux or screen. I prefer tmux, so I'll give instructions for that.

Start by installing tmux

sudo apt-get install tmux

Then start a session:

tmux new -s mybot

Then start your bot with whatever command you would normally use. Detach from the screen with Ctrl-a Ctr-d. You can now exit your ssh session and the bot will still be running.

To reattach to the session (to shut down the bot or whatever), just run:

tmux attach -t mybot
James
  • 2,843
  • 1
  • 14
  • 24