Forums

Automatic reload via scheduling script

As of right now, my scheduling script simply checks that my repositories are up-to-date. One of them is the application hosted here. I know there is the bookmarklet for reloading the site with greater ease, but is there a way to automate it via the scheduling script?

If you want to reload your web app you just need to touch the file /var/www/wsgi.py. You can do this in bash

touch /var/www/wsgi.py

Or in Python

import os
os.utime('/var/www/wsgi.py')

This works because the server process that handles your web application is watching that file and restarts itself whenever it is modified.

Awesome! Thanks!

Doesn't work for me, i pasted the python code in my application

import os
os.utime('/var/www/myapp_wsgi.py')

and then when i try to access the hosted application, it crashes with pythonAnywhere's message.

You pasted it into your application? Why? It's supposed to be used to restart your web app, it really doesn't belong in your web app.

Ok i fixed it, instead i made a file reload.sh with

touch /var/www/wsgi.py

in the script and made it to run using schedule feature. Is this going to work?

Assuming that your file is actually called wsgi.py, then yes, that will reload the webapp when it runs. Otherwise you need to replace that with moithil_pythonanywhere_com_wsgi.py

Here's a script to reload a webapp from shell

high-cyril