The right way in stopping mod_wsgi for website update

481 views
Skip to first unread message

Jian Wu

unread,
Jul 28, 2021, 4:42:21 PM7/28/21
to mod...@googlegroups.com
Dear all,

I am a bit confused if my website is actually running on modwsgi. 

When I type in the following commands below in my server, I should expect that my server will stop serving my website. But after running the below command I can still access my website.

sudo /etc/wsgi-port-80/apachectl stop
/etc/wsgi-port-80/apachectl: line 63: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
httpd (no pid file) not running

My understanding is when I installed modwsgi, it actually installed an Apache2 isolated environment in my server. I then assumed that when I stopped apache, I should not longer be able to access my website. 

Is there a way for me to check if my website is actually being served by the Apache2 server with modwsgi and not another Apache2 server that is not associated with modwsgi?


Thanks!

Graham Dumpleton

unread,
Jul 28, 2021, 6:38:23 PM7/28/21
to mod...@googlegroups.com
Your system Apache is probably still running and was never disabled.

What was the mod_wsgi-express setup-server command you can to generate the /etc/wsgi-port-80/ config directory to begin with?

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/62C31893-47BD-4304-A397-5E5B80FF414C%40gmail.com.

Jian Wu

unread,
Jul 29, 2021, 1:18:39 AM7/29/21
to mod...@googlegroups.com
Thanks Graham. This is also my thought. I am using the script below to start my modwsgi

#!/bin/sh

#Configuration on how to start the server
python manage.py runmodwsgi \
--server-root /etc/wsgi-port-80 \
--user www-data --group www-data \
--port 80 --setup-only \
--https-only \
--https-port 443 \
--ssl-certificate-file "/etc/letsencrypt/live/www.dimsum.dk/cert.pem" \
--ssl-certificate-key-file "/etc/letsencrypt/live/www.dimsum.dk/privkey.pem" \
--server-name 'www.dimsum.dk'

#Starting the server
sudo /etc/wsgi-port-80/apachectl stop
sudo /etc/wsgi-port-80/apachectl start


Graham Dumpleton

unread,
Jul 29, 2021, 1:23:06 AM7/29/21
to mod...@googlegroups.com
Depending on platform, what do you get for:

# systemctl status apache2  #Debian/Ubuntu 
# systemctl status httpd  #RHEL/CentOS/Fedora 

Jian Wu

unread,
Jul 29, 2021, 1:25:36 AM7/29/21
to mod...@googlegroups.com
I am using Ubuntu version 20.04 and I get the followings

systemctl status apache2
apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-07-28 21:35:35 UTC; 7h ago
    Process: 1961 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
   Main PID: 751 (apache2)
      Tasks: 73 (limit: 2279)
     Memory: 100.1M
     CGroup: /system.slice/apache2.service
             ├─ 751 /usr/sbin/apache2 -k start
             ├─1976 /usr/sbin/apache2 -k start
             ├─1977 /usr/sbin/apache2 -k start
             └─1978 /usr/sbin/apache2 -k start

Warning: some journal files were not opened due to insufficient permissions.


Graham Dumpleton

unread,
Jul 29, 2021, 1:29:49 AM7/29/21
to mod...@googlegroups.com
So it is still running and would conflict with the mod_express instance.

There can only be one Apache instance listening on 80/443.

If you are not using the system Apache instance now, you would need to stop then disable it.

systemctl stop apache2
systemctl disable apache2

Only then could you start up the mod_wsgi-express instance on 80/443.

If you had looked at the error log in the directory /etc/wsgi-port-80 you should have seen an error about it complaining 80/443 was in use when you had attempted to start of mod_wsgi-express instance.

Jian Wu

unread,
Jul 29, 2021, 1:43:55 AM7/29/21
to mod...@googlegroups.com
Thanks Graham. It makes much more sense now. I have disabled the apache2 so it is the modwsgi instance that runs now. I have just tested and confirmed that I can still stop the apache server using the below command

sudo /etc/wsgi-port-80/apachectl stop

Also, in your experience what is the best practice when I need to update my Django code? I am now doing the followings right now

1) Apply the above command to stop the apache server

2) Do my Django updates

3) Running the below script again to start up the server

#!/bin/sh

#Configuration on how to start the server
python manage.py runmodwsgi \
--server-root /etc/wsgi-port-80 \
--user www-data --group www-data \
--port 80 --setup-only \
--https-only \
--https-port 443 \
--ssl-certificate-file "/etc/letsencrypt/live/www.dimsum.dk/cert.pem" \
--ssl-certificate-key-file "/etc/letsencrypt/live/www.dimsum.dk/privkey.pem" \
--server-name 'www.dimsum.dk'

#Starting the server
sudo /etc/wsgi-port-80/apachectl stop
sudo /etc/wsgi-port-80/apachectl start

The reason why I ask is because earlier before I disabled the Apache2 server I always need to reboot my entire server before I can see the changes I have made in the website which is annoying. 

Graham Dumpleton

unread,
Jul 29, 2021, 1:51:49 AM7/29/21
to mod...@googlegroups.com
In general make sure you read this.


Note that mod_wsgi-express uses daemon mode by default.

The issue in your case is that you are using Django management command which means you are relying on the Django project to start mod_wsgi-express.

The alternative would be to not use the Django management command which does mean though needing to pass extra options to mod_wsgi-express to set up static files etc. See:


If you did that though and had the WSGI script file separate to the Django code so it isn't modified when updating Django, you could leave the server running, update Django code, then touch or update the WSGI script file and mod_wsgi-express daemon process would automatically shutdown and restart without you needing to stop the whole Apache server.

Whether this is a good idea really depends on the complexity of the application, plus if needing to do database migrations you probably need to stop the whole server anyway to be safe.

Jian Wu

unread,
Jul 29, 2021, 1:57:57 AM7/29/21
to mod...@googlegroups.com
Thanks Graham. I will start reading up the doc resources and then get back should there be more questions. Thanks for the always helpful comments and help in pointing us the right direction. 

Reply all
Reply to author
Forward
0 new messages