Answer the question
In order to leave comments, you need to log in
How to gracefully terminate a python3 script running as a service?
There is a Telegram bot written in python.
Made a service based on it. (OS - Ubuntu)
How to make a correct description of the shutdown of this service?
Service description file:
Description=Service for Telegram bot main. From user telebot
[Service]
Type=simple
WorkingDirectory=/home/telebot/bot_prod/
User=telebot
Group=telebot
ExecStart=/home/telebot/bot_prod/bot.py
ExecStop=exit()
#!/usr/bin/python3
import telebot
import config
import datetime
import pytz
import json
import traceback
import User
import Utils
import time
Utils.sendLogMessage("Робот запущен", "INFO", "START", True) # Выводим сообщение о начале работы бота
# Инициализируем бота:
P_TIMEZONE = pytz.timezone(config.TIMEZONE)
TIMEZONE_COMMON_NAME = config.TIMEZONE_COMMON_NAME
bot = telebot.TeleBot(config.TOKEN) # указываем токен конкретного бота
##
# Блок разбора конкретных команд бота
##
# Команда START
@bot.message_handler(commands=['start'])
def start_command(message):
bot.send_message(message.chat.id, 'Авторизация не пройдена, функционал ограничен.')
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question