P
P
pinguine2018-06-11 01:11:14
Python
pinguine, 2018-06-11 01:11:14

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.pyand 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

4 answer(s)
P
Pavel Selivanov, 2018-06-11
@selivanov_pavel

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

A
Aleksey Solovyev, 2018-06-11
@alsolovyev

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

V
vreitech, 2018-06-11
@fzfx

try python3 main.py &.

I
Ivan, 2018-06-11
@LiguidCool

screen!
But in general run the demon!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question