How to auto-restart cPanel Python app upon code changes?
Forum
  1. Forums
  2. CloudLinux and Control Panels
  3. CloudLinux and cPanel
  1. Chris
  2. Wednesday, 16 September 2020
  3.  Subscribe via email
Hello,

I have installed a Python application using cPanel's "Setup Python App" feature on a CloudLinux server.

I'd like to have the app automatically reload whenever I make changes to the .py files in the application root folder. Of course, clicking the RESTART button always updates the .py files, but it would be better if I could skip this step and have it done automatically.

It seems that the app may in fact restart automatically on its own after some time period... maybe every hour? I say this because sometimes the .py files are reloaded even though I never restarted the application.

I have tried various solutions with no success.

For instance, I have added three new variables to the "Environment variables" section of the Python application editor:
Name: FLASK_APP Value: app.py
Name: FLASK_DEBUG Value: true
Name: FLASK_ENV Value: development

But, they have no effect. I also tried adding these environmental variables into the bin/activate file (eg: export FLASK_ENV="development" ) .

I did a search and only found this:

How to restart Passenger WSGI (Python) from command line?


Is what I want to accomplish possible?
Rate this post:
  1. 16.09.2020 11:09:54
  2. # 1
Kate Grechishkina Accepted Answer
Posts: 41
Joined: 13.04.2019
0
Votes
Undo
Hello Chris,
Thank you for your question. There is no ready solution that would allow you to achieve what you want out of the box. I am not aware of any way you could make Passenger reload its workers when a code change is detected. It would involve one more component that would have been doing the actual detection.
However, there is a way to make Passenger reload workers much faster based on its configuration:

<IfModule mod_passenger.c>
PassengerMinInstances 0
PassengerPoolIdleTime 10
</IfModule>



So, if you create a file /etc/apache2/conf.d/passenger_custom.conf -> add the code above there -> restart httpd, it should make your changes pop up in production much faster.
  1. 16.09.2020 18:09:15
  2. # 2
Chris Accepted Answer
Posts: 2
Joined: 16.09.2020
0
Votes
Undo
Hello Kate,

Unfortunately I am not allowed to modify the Passenger configuration because I am on a shared server.
  1. 17.09.2020 12:09:56
  2. # 3
Sergey Khristich Accepted Answer
Posts: 430
Joined: 20.05.2019
0
Votes
Undo
Hello Chris,
In this case, PassengerMinInstances can protect in .htaccess and it should work. Unfortunately, the second option is only available in server config
Thank you for contacting us.
Marketing Manager
  1. 21.09.2020 06:09:13
  2. # 4
Chris Accepted Answer
Posts: 2
Joined: 16.09.2020
0
Votes
Undo
Hi Sergey,

Can you please tell me exactly what to put inside the .htaccess file and where this file should be located?

I tried appending Kate's code block to the .htaccess file located inside my Application URL folder that cPanel generated (ie, the PassengerBaseURI directory). But now I receive an Error 500 Internal Server Error.

Thanks
  1. 21.09.2020 09:09:25
  2. # 5
Kate Grechishkina Accepted Answer
Posts: 41
Joined: 13.04.2019
0
Votes
Undo
Hello Chris,
Unless you have root access, you will not be able to use this solution because PassengerPoolIdleTime can ONLY be added to server config, it can't go inside .htaccess.
  • Page :
  • 1


There are no replies made for this post yet.
Be one of the first to reply to this post!
Guest
Submit Your Response
Upload files or images for this discussion by clicking on the upload button below. Supports gif,jpg,png,zip,rar,pdf
• Insert • Remove Upload Files (Maximum File Size: 2 MB)
Captcha
To protect the site from bots and unauthorized scripts, we require that you enter the captcha codes below before posting your question.