Announcement

Collapse
No announcement yet.

How to auto-restart cPanel Python app upon code changes?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to auto-restart cPanel Python app upon code changes?

    Hello,

    I have installed a Python application using cPanels "Setup Python App" feature on a CloudLinux server.

    Id 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:

    https://How to restart Passenger WSG... command line?

    Is what I want to accomplish possible?

  • #2
    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:

    Code:
    <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.

    Comment


    • #3
      Hello Kate,

      Unfortunately I am not allowed to modify the Passenger configuration because I am on a shared server.

      Comment


      • #4
        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.

        Comment


        • #5
          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 Kates 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

          Comment


          • #6
            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 cant go inside .htaccess.

            Comment

            Working...
            X