I don't have the code on my right now, but I remember it involved
using Python's standard libraries to set the UID and GID of the
running app (so it doesn't run as root), writing out the .pid file so
I can use kill to stop the app, and maybe a few more things.
http://docs.python.org/library/os.html#os.setuid
http://docs.python.org/library/os.html#os.setgid
http://docs.python.org/library/os.html#os.getpid
The .pid is written out to a known location, so the daemon script can
use it to kill the process.
You also want to redirect sys.stdout to a file. To background the
process, I used nohup. It's much easier than using a python library.
> --
> You are member of the "bottlepy" group at google groups.
> See http://groups.google.de/group/bottlepy for mailing list options.
> See http://bottlepy.org/ for news and documentation.
>
http://www.brankovukelic.com/post/2743988069/running-web-apps-as-linux-system-service
On Sat, Jun 11, 2011 at 1:47 PM, Branko Vukelic
branko@megafox:~$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> f = open('test.log', 'w')
>>> sys.stdout = f
>>> print "bogus"
>>> f.close()
>>>
branko@megafox:~$ cat test.log
bogus
In production, you'd handle the SIGTERM to close the file.
I'm not sure how x-sendfile works. At any rate, GAE doesn't have
static file storage other than for your application files. It has a
blobstore which is a datastore-based file storage. I haven't used
those yet.
For normal web apps that do not deal with files, it's ok. datastore is
very difficult to work with, and requires much more work in the DB
schema design phase, as opposed to SQL (no joins, etc). Main advantage
of GAE, though, is it's sheer power and ease of deployment. The
platform also offers good tools, and so far, I haven't met much
difficulty.
I didn't choose to use GAE, though. It was more or less requested by
the employer. I kinda thought it might be fun, so I said ok. I guess
it's not bad, overall. At least I don't have to fiddle with the kind
of stuff discussed in this thread. :D
--
Branko