Search code examples
pythoncrontornadoiptables

Python Tornado Web Service Cron Restart How?


Fail Code:

root = os.path.dirname(__file__)
static_application = tornado.web.Application([
    (r"/(.*)", tornado.web.StaticFileHandler, 
    {"path": root, "default_filename": "Example.html"})
])

if __name__ == "__main__":
    print "Starting Server..."
    static_application.listen(8080)
    tornado.ioloop.IOLoop.instance().start()

Fail iptables:

Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination         
1    REDIRECT   tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80 redir ports 8080

Fail html:

<!DOCTYPE HTML>
<html>
    <head>
    <link href='StyleFile0.css'     rel='stylesheet' type='text/css' />
    <link href='StyleFile1.css'     rel='stylesheet' type='text/css' />

    <script src='ScriptFile0.js'    type='text/javascript'> </script>
    <script src='ScriptFile1.js'    type='text/javascript'> </script>

Fail Cron:

 0 * * * * cd /home/maindude/CodeHome && timeout -k 59m 59m python Process_TornadoService.py

Fail .js .css browser console "GET" ' s:

ScriptGetFail


So I figured out how to host a basic tornado web service.

I spawn up an Amazon server and throw it on there, everything works great.

Then I want to have the service die and restart every hour.

If I host on port 80 -> I need sudo permissions to start service so cron fails

If I host the service on port 8080 -> I have to use iptables

If I use iptables -> my script dependencies in html seem to be mysteriously unavailable.


What is the right combo of python, tornado, html, cron, iptables to fix this and get a tornado service to die and restart every hour?

EDIT:

Everything above works just fine to achieve this.


Solution

  • Ok - so it turns out -> I was not patient enough...

    The above code, cron, html, javascript, and iptables all work flawlessly to achieve a server restart with tornado on port 8080 on an amazon web server.

    Epic celebration ensues