running unix background deamons
First set up a python program (or whatever) to run twisted.
Run it on a high port, like 3000. (Though we have to
make sure any odd port gets through both the campus firewall
and cs's access rules.)
---- /home/mahoney/twisted/web_deamon.py ------
from twisted.web import server, resource
from twisted.internet import reactor
class Simple(resource.Resource):
isLeaf = True
def render_GET(self, request):
return "<html>Hello, world!</html>"
site = server.Site(Simple())
reactor.listenTCP(3000, site)
reactor.run()
---- /home/mahoney/twisted/web_deamon.sh -------
#!/bin/sh
# Invoke this from the command line with
#
# $ at -f /home/mahoney/twisted/web_deamon.sh now
#
# See also atrm, atq, batch
#
cd /home/mahoney/twisted/
python web_deamon.py
-------------------------------------------------
From the command line, make sure *.sh is executable.
$ cd cd /home/mahoney/twisted/
$ chmod +x web_deamon.sh
Confirm that the script works.
$ ./web_deamon.sh
... and test it with a web browser.
If it does, you can launch it so that it is not
attached to your login process with the "at" command.
$ at -f /home/mahoney/twisted/web_deamon.sh now
Then you can just log out.
After logging back in,
$ atq # show "at" jobs
$ atrm # delete (and stop) "at" jobs
Then you can test the web server on another computer
through SSH Port Tunneling. Use the following command
to tunnel port 3000 on the other computer into port
8080 on your computer. So if there is a website on
port 3000 on that computer, it will be visible from
port 8080 on your computer (localhost:8080 in a web
browser.)
$ ssh rdolan@cs -L 8080:localhost:3000