1

I have a function in apps.py set to run at Apache boot/restart, however it doesn't and it only works after I pull up the index page.

However, if I use Django's development environment it works perfectly.

APPS.PY

from django.apps import AppConfig

class GpioAppConfig(AppConfig):
  name = 'gpio_app'

  verbose_name = "My Application"
  def ready(self):
    from apscheduler.schedulers.background import BackgroundScheduler
    from gpio_app.models import Status, ApsScheduler
    import gpio_app.scheduler as sched
    import logging

    logging.basicConfig()
    logging.getLogger('apscheduler').setLevel(logging.DEBUG)

    sched.cancel_day_schedule()
    sched.get_schedule()
    sched.daily_sched_update()
    sched.add_status_db()

MOD_WSIG 000-default.conf is as follows:

<VirtualHost *:80>

    ServerName 127.0.0.1
    ServerAlias localhost

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /robots.txt /path/to/mysite.com/static/robots.txt
    Alias /favicon.ico /path/to/mysite.com/static/favicon.ico

    Alias /static /home/pi/poolprojectdir/static
    
    <Directory /home/pi/poolprojectdir/static>
    Require all granted
    </Directory>

    <Directory /home/pi/poolprojectdir/poolproject>
    <Files wsgi.py>
    Require all granted
    </Files>
    </Directory>

    WSGIDaemonProcess poolproject python-     home=/home/pi/poolprojectdir/venv python-path=/home/pi/poolprojectdir
WSGIProcessGroup poolproject
WSGIScriptAlias / /home/pi/poolprojectdir/poolproject/wsgi.py

Any ideas as to how I get apps.py recognised by Apache2?

Radial
  • 342
  • 1
  • 4
  • 14

1 Answers1

0

The problem is with apache loading your wsgi.py lazily - only after the first request arrives.

See this answer on how to fix this.

dakiniishi
  • 26
  • 3