Reputation: 433
right now I'm trying - for the first time - to deploy a Django-Application on a Apache2 with mod_wsgi and it's still not working the way I wish it would. Anyway, I'm arguing with my Admin who says I don't have to restart the server after making changes to my python code, only if there are changes to the .conf-files. The tutorials online are also not that useful for this specific problem! Some say "A", some say "B" and some don't mention this topic at all.
<VirtualHost *:80>
ServerName webapp.company.local
ServerAlias cmp-workbench.company.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/cmp-workbench
#for django
Alias /static /var/www/cmp-workbench/static
<Directory /var/www/cmp-workbench/static>
Require all granted
</Directory>
<Directory /var/www/cmp-workbench/cmp_workbench>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess cmp-workbench python-path=/var/www/cmp-workbench python-home=/var/www
/cmp-workbench/cmp_workbench
WSGIProcessGroup cmp-workbench
WSGIScriptAlias / /var/www/cmp-workbench/cmp_workbench/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error_cmp-workbench.log
CustomLog ${APACHE_LOG_DIR}/access_cmp-workbench.log combined
</VirtualHost>
import os
import time
import traceback
import signal
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/var/www/cmp-workbench-stage/cmp_workbench_stage')
sys.path.append('/var/www/cmp-workbench-
stage/cmp_workbench_stage/env/lib/python3.7/site-packages')
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
'cmp_workbench_stage.settings')
try:
application = get_wsgi_application()
except Exception:
# Error loading applications
if 'mod_wsgi' in sys.modules:
traceback.print_exc()
os.kill(os.getpid(), signal.SIGINT)
time.sleep(2.5)
Can someone who already deployed this way answer to my problem? Thanks and a great weekend!
Upvotes: 0
Views: 1658
Reputation: 4254
in the most cases, you won't need to restart apache
each time you make changes to python files. your sysadmin was definitely right. apache
as web server is meant to serve and handle http requests (among other things) and not dealing with the execution of scripts (python, php ..)
as suggested by this answer, and after you make some changes in your python files, simply running touch wsgi.py
command will do the trick to force the daemon to reload since the timestamps of the file (wsgi.py
) is updated.
refer to https://man7.org/linux/man-pages/man1/touch.1.html
Update the access and modification times of each FILE to the current time.
Upvotes: 2