Конфиги aiogram2 - A-V-tor/Bot-secretar GitHub Wiki
Админка
adminpanel.service
# /lib/systemd/system/adminpanel.service
[Unit]
Description=Gunicorn instance to serve myproject
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/root/Bot-secretar
Environment="PATH=/root/Bot-secretar/.venv/bin"
ExecStart=/root/Bot-secretar/.venv/bin/gunicorn --workers 1 --bind unix:myproject.sock -m 007 app:app
[Install]
WantedBy=multi-user.target
Телеграм часть
bot.service
# /lib/systemd/system/bot.service
[Unit]
Description=Timeweb Bot Service
After=network.target
[Service]
Type=idle
Restart=always
RestartSec=3
User=root
WorkingDirectory=/root/Bot-secretar
ExecStart=/root/Bot-secretar/.venv/bin/python /root/Bot-secretar/app_bot.py
[Install]
WantedBy=multi-user.target
Nginx конфиг
# /etc/nginx/sites-available/myproject
server {
listen 80;
server_name your ip
location / {
include proxy_params;
proxy_pass http://unix:/root/Bot-secretar/myproject.sock;
}
}
Celery
Общая конфигурация
# file /etc/default/celeryd
# The names of the workers. This example create one worker
CELERYD_NODES="worker1"
# The name of the Celery App, should be the same as the python file
# where the Celery tasks are defined
CELERY_APP="project.telegram.tasks:app"
# Log and PID directories
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"
# Log level
CELERYD_LOG_LEVEL=INFO
# Path to celery binary, that is in your virtual environment
CELERY_BIN=/root/Bot-secretar/.venv/bin/celery
# Options for Celery Beat
CELERYBEAT_PID_FILE="/var/run/celery/beat.pid"
CELERYBEAT_LOG_FILE="/var/log/celery/beat.log"
Воркер
# file /etc/systemd/system/celeryd.service
[Unit]
Description=Celery Service
After=network.target
[Service]
Type=forking
User=root
Group=root
EnvironmentFile=/etc/default/celeryd
WorkingDirectory=/root/Bot-secretar
ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} \
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} \
--pidfile=${CELERYD_PID_FILE}'
ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} \
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
[Install]
WantedBy=multi-user.target
Переодические задания
# file /etc/systemd/system/celerybeat.service
[Unit]
Description=Celery Service
After=network.target
[Service]
Type=simple
User=root
Group=root
EnvironmentFile=/etc/default/celeryd
WorkingDirectory=/root/Bot-secretar
ExecStart=/bin/sh -c '${CELERY_BIN} \
-A ${CELERY_APP} beat --pidfile=${CELERYBEAT_PID_FILE} \
--logfile=${CELERYBEAT_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL}'
[Install]
WantedBy=multi-user.target
Логи
mkdir /var/log/celery /var/run/celery
chown root:root /var/log/celery /var/run/celery
cat /var/log/celery/beat.log
cat /var/log/celery/worker1.log
Redis
# /lib/systemd/system/redis-server.service
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-20-04-ru # redis Linux
https://gist.github.com/tomysmile/1b8a321e7c58499ef9f9441b2faa0aa8 # redis MAC OS
Гайд настройки