0

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?

gabeio
  • 1,282
  • 1
  • 23
  • 37
  • Take a look at http://stackoverflow.com/questions/11004204/how-can-i-get-bottle-to-restart-on-file-change/11053279#11053279 – f p Jun 15 '12 at 15:23
  • This does not help me. I wish to only reload the server when I tell the server to reload not when ever the server file is updated. I have an example of exactly what I want except its written for Cherrypy. – gabeio Jun 15 '12 at 23:50

1 Answers1

1

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.

Rohan
  • 2,226
  • 2
  • 17
  • 14
  • oh geez I totally didn't think about just re-running the script -.- but which of the: `os.system()`, `os.exec()`, `os.popen()` or `os.spawn()` would be best because I don't want it to keep the current process running but I wouldn't mind it keeping the same identifier? – gabeio Jun 25 '12 at 22:35
  • In the shell script you can first "killall" gevent processes. Then just create new ones. Also once the shell script is done, it's process will be destroy automatically. And bottle will also return. you can use os.system() for this. – Rohan Jun 26 '12 at 03:45