Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I work in a SaaS application built with Django (Python) and runs with Apache/mod_wsgi.

The registration site creates an apache virtual host config, wsgi and settings files. And finally restarts the apache server.

This means that every time a new user registers an account apache restarts and this affect the performance of the app for the current clients.

A possible option is to create a separate apache instance for new clients how ever this will increase too much the RAM needed for all clients.

What recommendations do you have about this?

share|improve this question
    
Sounds dangerous. A bad registration could bring the website down. –  Matt Nov 22 '10 at 23:51
add comment

2 Answers

up vote 2 down vote accepted

The side effect of several instances is that they all can't run on the same port either.

Maybe your script can do a "apachectl configtest" to ensure the configuration is valid first (helping prevent it not starting due to error in config).

And then run apachectl graceful.

apachectl graceful: Gracefully restarts the Apache daemon by sending it a SIGUSR1. If the daemon is not running, it is started. This differs from a normal restart in that currently open connections are not aborted. A side effect is that old log files will not be closed immediately. This means that if used in a log rotation script, a substantial delay may be necessary to ensure that the old log files are closed before processing them. This command automatically checks the configuration files via configtest before initiating the restart to make sure Apache doesn't die.

apachectl configtest: Run a configuration file syntax test. It parses the configuration files and either reports Syntax Ok or detailed information about the particular syntax error.

share|improve this answer
    
I never thought about a dangerous registration, I like the key tip about check first, and then a graceful restart. Thanks –  quarry32 Nov 24 '10 at 0:45
add comment

This is probably overkill, but I have a cunning plan. :-)

Set up an iptables rule such as:

iptables -t nat -i PREROUTING -m tcp -p tcp --dport 80 -j DNAT --to-destination :81

Have Apache running on port 81. Incoming connections for port 80 would get redirected to port 81.

Now, when you get a new configuration, save it to a separate location and have it listen on port 82. Now you can try starting a second instance of Apache. If it fails to start, you know you have a configuration problem and can continue running with the old configuration until it is resolved.

If it does start, replace the iptables rule above with one pointing at port 82. Existing connections will continue to go to the old port until they are complete. Give them some grace period before shutting down the old instance. In this way you start a completely new instance and shut down the old one, but without interrupting users. Then you can do the same with the next configuration going back to port 81.

apachectl graceful is probably what you want, but if it doesn't work out for you this may be another option.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.