Search code examples
pythoncherrypygeventbottle

Bottle equivalent of engine.restart()


I am trying to transfer from Cherrypy to Bottle & Gevent(server).
After I run:

application=bottle.default_app() #bottle
WSGIServer(('', port), application, spawn=None).serve_forever() #gevent

I want to restart the server just as if the reloader reloaded the server (but only when I tell the server to).
So I want to access a page with credential request and only after correct authentication will it restart.

Here is my functional example in Cherrypy:

@expose
def reloadMe(self, u=None, p=None):
    if u=="username" and p=="password":
        engine.restart()
    raise HTTPRedirect('/')

More simply I am asking how do I reload this script so that my edits to the source file are implemented but only when I retrieve a "restart" page.
I literally only need the Bottlepy equivalent of

engine.restart() #cherrypy

Does no one know how to do this?


Solution

  • You can write a small shell script to restart gevent wsgi server.

    then using this code, you can call the script.

    @get('/restartmyserver')
    def handler():
        http_auth_data = bottle.request.auth() # returns a tuple (username,password) only basic auth.
        if http_auth_data[0] == user and http_auth_data[1] == password:
            os.system("your_shell_script_to_restart_gevent_wsgi")
        bottle.redirect('/')
    

    let me know if you need more info.