diff --git a/_deploy/celery b/_deploy/celery new file mode 100644 index 0000000..18f2787 --- /dev/null +++ b/_deploy/celery @@ -0,0 +1,28 @@ +# Name of nodes to start +# here we have a single node +CELERYD_NODES="w1" +# or we could have three nodes: +#CELERYD_NODES="w1 w2 w3" + +# Absolute or relative path to the 'celery' command: +CELERY_BIN="/var/www/phzhik-poizonstore/env/bin/celery" + +# App instance to use +CELERY_APP="poizonstore" + +# How to call manage.py +CELERYD_MULTI="multi" + +# Extra command-line arguments to the worker +CELERYD_OPTS="" + +# - %n will be replaced with the first part of the nodename. +# - %I will be replaced with the current child process index +# and is important when using the prefork pool to avoid race conditions. +CELERYD_PID_FILE="/var/run/celery/%n.pid" +CELERYD_LOG_FILE="/var/log/celery/%n%I.log" +CELERYD_LOG_LEVEL="INFO" + +# you may wish to add these options for Celery Beat +CELERYBEAT_PID_FILE="/var/run/celery/beat.pid" +CELERYBEAT_LOG_FILE="/var/log/celery/beat.log" \ No newline at end of file diff --git a/_deploy/celery.service b/_deploy/celery.service new file mode 100644 index 0000000..fd4e5d2 --- /dev/null +++ b/_deploy/celery.service @@ -0,0 +1,24 @@ +[Unit] +Description=Celery Service +After=network.target +Requires=redis.service + +[Service] +Type=forking +User=celery +Group=celery +EnvironmentFile=/etc/default/celery +WorkingDirectory=/var/www/phzhik-poizonstore +ExecStart=/bin/sh -c '${CELERY_BIN} -A $CELERY_APP multi start $CELERYD_NODES \ + --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} --logfile=${CELERYD_LOG_FILE} \ + --loglevel="${CELERYD_LOG_LEVEL}"' +ExecReload=/bin/sh -c '${CELERY_BIN} -A $CELERY_APP multi restart $CELERYD_NODES \ + --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} \ + --loglevel="${CELERYD_LOG_LEVEL}" $CELERYD_OPTS' +Restart=always + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/_deploy/celerybeat.service b/_deploy/celerybeat.service new file mode 100644 index 0000000..7c3ef7c --- /dev/null +++ b/_deploy/celerybeat.service @@ -0,0 +1,17 @@ +[Unit] +Description=Celery Beat Service +After=network.target + +[Service] +Type=simple +User=celery +Group=celery +EnvironmentFile=/etc/default/celery +WorkingDirectory=/var/www/phzhik-poizonstore +ExecStart=/bin/sh -c '${CELERY_BIN} -A ${CELERY_APP} beat \ + --pidfile=${CELERYBEAT_PID_FILE} \ + --logfile=${CELERYBEAT_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL}' +Restart=always + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/_deploy/nginx.conf b/_deploy/nginx.conf index ebeda69..619e469 100644 --- a/_deploy/nginx.conf +++ b/_deploy/nginx.conf @@ -40,4 +40,8 @@ server { include /etc/nginx/uwsgi_params; include /etc/nginx/proxy_params; } + + location /flower/ { + proxy_pass http://localhost:5555/flower/; + } } \ No newline at end of file diff --git a/_deploy/run_celery_flower.sh b/_deploy/run_celery_flower.sh new file mode 100755 index 0000000..0f26307 --- /dev/null +++ b/_deploy/run_celery_flower.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +WORK_DIR="/var/www/phzhik-poizonstore/env/bin" +PROJECT_NAME="poizonstore" + +# Wait for worker to start +until timeout 10s $WORK_DIR/celery -A $PROJECT_NAME inspect ping; do + >&2 echo "Celery workers not available" +done + +# Run flower for Celery management +echo 'Starting Celery flower' +$WORK_DIR/celery -A $PROJECT_NAME flower --port=5555 --url_prefix=/flower --basic-auth=admin:meowmeow diff --git a/_deploy/uwsgi.ini b/_deploy/uwsgi.ini index c0192e9..9c62739 100644 --- a/_deploy/uwsgi.ini +++ b/_deploy/uwsgi.ini @@ -25,7 +25,5 @@ chmod-socket = 664 # clear environment on exit vacuum = true -smart-attach-daemon = /tmp/celery-main.pid /var/www/phzhik-poizonstore/run_celery.sh - env = LANG=C.UTF-8 enable-threads = true \ No newline at end of file diff --git a/cdek/__init__.py b/cdek/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/run_celery.sh b/run_celery.sh deleted file mode 100755 index 548cf07..0000000 --- a/run_celery.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -WORK_DIR="/var/www/phzhik-poizonstore/env/bin" -PROJECT_NAME="poizonstore" - -# Run Celery worker -echo 'Starting Celery worker' -$WORK_DIR/celery -A $PROJECT_NAME worker -l INFO --pidfile=/tmp/celery.pid & - -# Wait for worker to start -until timeout 10s $WORK_DIR/celery -A $PROJECT_NAME inspect ping; do - >&2 echo "Celery workers not available" -done - -# Run flower for Celery management -echo 'Starting Celery flower' -$WORK_DIR/celery -A $PROJECT_NAME flower --pidfile=/tmp/celery-flower.pid & - -# Run celery beat for periodic tasks -echo 'Starting Celery beat' -$WORK_DIR/celery -A $PROJECT_NAME beat -l INFO --pidfile=/tmp/celery-beat.pid & diff --git a/stop_celery.sh b/stop_celery.sh deleted file mode 100755 index c5d08bf..0000000 --- a/stop_celery.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -killall celery \ No newline at end of file