Question

I've used web.py to create a web service that returns results in json.

I run it on my local box as python scriptname.py 8888

However, I now want to run it on a linux box.

How can I run it as a service on the linux box?

update

After the answers it seems like the question isn't right. I am aware of the deployment process, frameworks, and the webserver. Maybe the following back story will help:

I had a small python script that takes as input a file and based on some logic splits that file up. I wanted to use this script with a web front end I already have in place (Grails). I wanted to call this from the grails application but did not want to do it by executing a command line. So I wrapped the python script as a webservice. which takes in two parameters and returns, in json, the number of split files. This webservice will ONLY be used by my grails front end and nothing else.

So, I simply wish to run this little web.py service so that it can respond to my grails front end.

Please correct me if I'm wrong, but would I still need ngix and the like after the above? This script sounds trivial but eventually i will be adding more logic to it so I wanted it as a webservice which can be consumed by a web front end.

Was it helpful?

Solution

In general, there are two parts of this.

The "remote and event-based" part: Service used remotely over network needs certain set of skills: to be able to accept (multiple) connections, read requests, process, reply, speak at least basic TCP/HTTP, handle dead connections, and if it's more than small private LAN, it needs to be robust (think DoS) and maybe also perform some kind of authentication.

If your script is willing to take care of all of this, then it's ready to open its own port and listen. I'm not sure if web.py provides all of these facilities.

Then there's the other part, "daemonization", when you want to run the server unattended: running at boot, running under the right user, not blocking your parent (ssh, init script or whatever), not having ttys open but maybe logging somewhere...

Servers like nginx and Apache are built for this, and provide interfaces like mod_python or WSGI, so that much simpler applications can give up as much of the above as possible.

So the answer would be: yes, you still need Nginx or the likes, unless:

  • you can implement it yourself in Python,

  • or you are using the script on localhost only and are willing to take some risks of instability.

Then probably you can do on your own.

OTHER TIPS

try this

python scriptname.py 8888 2>/dev/null

it will run as daemon

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top