> On 18 Jun 2018, at 2:14 am, Dhiraj Shetty <[email protected]> wrote:
> 
> Dear Group member,
> 
> We have coded a flask server that has embedded all the logic towards our web 
> application.
> 
> We have successfully managed to run a pilot project with a hello world flask 
> web application being externally exposed using Apache and mod_wsgi (within a 
> Docker Swarm). We are now putting together our learning from this pilot for 
> making our original flask web application production ready. We have the 
> apache .conf file and .wsgi file in place and are able to route REST requests 
> to Apache to our web application.

Rather than try and configure Apache yourself, you are better off using 
mod_wsgi-express. It was in part specifically designed to make it easier to use 
mod_wsgi in containers. It greatly simplifies configuration because 
mod_wsgi-express will generate the configuration for you. It also uses a lot of 
defaults that don't exist when manually configurating Apache/mod_wsgi, with the 
defaults giving a much better default experience as far as automatically 
recovery when your application gets stuck etc.

http://blog.dscpl.com.au/2015/04/introducing-modwsgi-express.html 
<http://blog.dscpl.com.au/2015/04/introducing-modwsgi-express.html>
https://www.youtube.com/watch?v=CPz0s1CQsTE 
<https://www.youtube.com/watch?v=CPz0s1CQsTE>

> We are however unable to understand where to place the initialisation code 
> that should be run only once. This involves initialisation of logger and also 
> establishing a connection to our microservices (framework) server. 
> 
> We would like this initialisation code to be run only once. Subsequent REST 
> requests to our flask web application  (through mod-wsgi) should have access 
> to variables initialised in initialisation code. Besides if connection to the 
> microservices server fails (during initialisation) we do not want the apache 
> server to start hosting our web application i.e we only log the reason for 
> failure and stop.

Depends on what sort of initialisation code it is and whether it is just 
configuration, or you need to execute code in each process.

Because your wsgi.py file is loaded once per process, the easiest thing to do 
is add configuration or one off actions in it. If necessary, for configuration 
injected into the container as environment variables, it can read the 
environment variables and use them to set configuration in Python code.

When using mod_wsgi-express configuration is somewhat easier because you can 
point it as a envvars script file to run during setup and which you can set 
further environment variables.

> We are new to Flask and Mod-Wsgi. Any mistakes in our terminology should be 
> forgiven. We would be grateful for any help (in the simplest possible 
> language).
> 
> Regards,
> Dhiraj.
> 
> -- 
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/modwsgi.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to