Forums

Command equivalent for "Reload web app" < "Web" < "Dashboard" | Apache logs

hi, wondering what the command line equivalent is to the GUI action: press "Reload web app" button < "Web" tab < "Dashboard" ??

It would be nice to give that command that simply from the bash console instead of visiting the PAW dashboard. Thanks very much.

P.S. -- bonus question... are the logs automatically rotated or truncated for - /var/log/apache2/access.log - /var/log/apache2/error.log or is that the user's responsibility at PAW?

Hi rsvp, logs aren't rotated automatically. That sounds like a bug to me!

There is no command line equivalent that we have developed. Reload web app button hits a view that requires authorization and then assumes privileged execution. Not something that can currently be run in the chroot. So as long as you had the right session-id cookie loaded you could hit it with an http request from a script. Or you could bookmark the url and just hit that from the browser. Maybe we need to make that a bit simpler.

The url that you need to hit to reload your web app is: https://www.pythonanywhere.com/user/<username>/webapps/reload

hansel,

Is there any reason not to use mechanize to log in to the webpage and reload the webapp?

If not, then the following code seems to work.

#! /usr/bin/env python

import mechanize
import getpass
import time
import os

def reload(username=None, password=None):
    if username is None:
        username = raw_input('Username: ')
    if password is None:
        password = getpass.getpass('Password: ')

    br = mechanize.Browser()
    br.set_handle_robots(False)
    br.open('https://www.pythonanywhere.com/login/')
    time.sleep(1)

    br.select_form(nr=0)
    br['username'] = username
    br['password'] = password
    br.submit()
    time.sleep(1)

    resp = br.open('https://www.pythonanywhere.com/user/%s/webapps/reload' % (username, ))
    print resp.read()
    time.sleep(1)

    br.open('https://www.pythonanywhere.com/logout')

if __name__ == '__main__':
    reload(os.environ['USER'])

That would be totally fine of course,

We've actually just made a little bookmarklet as well:

Reload webapp}else{alert('Could not reload web app (are you logged in?)')}})();")

But that requires that you are logged in. An easier URL to hit now is "https://www.pythonanywhere.com/reload_web_app". It reloads the web app of the currently logged in user.

Hi friends. It's a bit of strange, but when I used: 1. "https://www.pythonanywhere.com/user/nurdus/webapps/reload" - I received answer 404 2. "https://www.pythonanywhere.com/reload_web_app" - I received answer 500 What did I do wrong?

Ah, we should have updated this thread. Unfortunately when we added support for multiple web applications a while back, this bookmarklet stopped working. We'll add support for a new one soon.

Thanks, I'll be waiting.

You can "touch" the .py file located in /var/www/ and the web app reloads.

touching the file at /var/www/you-domain-wsgi.py will reload your web app workers, so that will pick up on any code changes you've made, but be warned that it doesn't do the other stuff which the button does, in particular, it won't pick up any new static files directory mappings you've made.

@harry: You say "other stuff" then mention static mappings...is there anything else in "other stuff"?

More particularly is there anything else in "other stuff" that would matter to end users?

The reload button rewrites the configuration file for the uWSGI worker and recreates the socket files. This is mainly relevant if you have upgraded your account recently or you have added static file mappings.

Thx for clarification...☺

So is there an updated bookmarklet now? Thanks.

I'm a newbie, Can anyone please share a link on - How to "touch" the .py file in /var/www ?

touch is a bash command, so in a bash console you run this:

touch /var/www/moithil_pythonanywhere_com_wsgi.py

...to reload the app at moithil.pythonanywhere.com, making the obvious changes if your web app is running on a custom domain.

Ok this is doing well, next i want to know is: How can i automatically reload my application once in a day, or schedule reloading my application on certain time of a day?

Use a Scheduled task.

Hi! I'd like to revamp @tjwarren's code a bit since pythonanywhere changed their URL for reload

https://gist.github.com/a-y-s/ca639c0d8cc3380fca69

Thanks! Actually, we're about to change the API again (undocumented unofficial API) so that it insists on a POST request. Reloading custom domains should also work (even now) if you post the domain name in all lower case. I've forked your gist and updated it with that, but haven't been able to test it -- and it doesn't look like there's any way to submit a pull request for gists... So I'll just leave this link here https://gist.github.com/gpjt/52ef24dea8201e065a9e

Thanks :D I made the same corrections on my gist. Also, Is the API publicly accesable? I'd love to look through it :D

To be honest it's not really an API, more the set of URLs we use to drive the site from our web pages. We try to keep it as simple and clean as possible for our own sanity's sake, but it can change without notice. We're planning to add a more formal API in the long term, but it's a little way away.

@tjwarren's script has now become uotdated. I wrote a new script to reload a webapp from a bash console.

https://github.com/a-y-s/high-cyril/

Hi guys,

Just an update on the ways to reload your webapp-

There are currently two ways:

  1. go to your webapps tab and hit the reload webapp button
  2. if you prefer a more programmatic approach, you can go to the accounts page and sign up for API access (there is documentation there for various endpoints including reloading your webapp)

When you go to your account and enable the API, the example that they give you there is exactly what you need to update your webapp through script; so all I did was to copy that code and paste in a file that I run to update the webpage.

:)

:)

hi what did you think about this,

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import os
import sys
print(sys.argv)
username='ensias'
password='ilikepython'
# os.system("clear")


options=webdriver.ChromeOptions()
driver = webdriver.Chrome(chrome_options=options)

driver.get('https://www.pythonanywhere.com/login/')
driver.find_elements_by_id("id_auth-username")[0].send_keys( username)
driver.find_elements_by_id("id_auth-password")[0].send_keys( password)

driver.find_elements_by_id("id_next")[0].click()
driver.get('https://www.pythonanywhere.com/user/ensias/webapps')

driver.find_elements_by_class_name("btn-success")[0].click()

[edit by admin: formatting]

I hope that's not your real password!

That code will probably work right now, but it might stop if we change the user interface in the future. It's much safer to use the API, which won't change without at least some kind of warning.