Answer the question
In order to leave comments, you need to log in
How to properly run telegram bot on ssh server?
I wrote a telegram bot in python and uploaded it to VPS. I connect to VPS like this - ssh [email protected]
. I run my script python3 main.py
and it works. But as soon as I close the terminal with ssh connection the script stops working. How can I make the script run continuously, without stopping, regardless of whether I am connected to the server or not? What solution is suitable so that I can run several scripts on the server at once?
Server on ubuntu.
Answer the question
In order to leave comments, you need to log in
Write a service to run the bot:
cat > /etc/systemd/system/foobar.service << EOF
[Service]
WorkingDirectory=/home/user/foobar
User=user
ExecStart=/usr/bin/python3 main.py
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable foobar
systemctl start foobar
systemctl status foobar
When you close the terminal on your computer, the process that was launched in it ends.
Therefore, you need to run the bot in the background. Lots of ways...let it be screen
Keyboard shortcut CTRL A then D
You can close the terminal screen -r mybot
- to open it the next time you log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question