tags:

views:

274

answers:

1

I have a simple web server written in Twisted, and I'm trying to start it up daemonized with twistd. Everything works fine with reactor.run() but when I use twistd -y (as root), none of my packages which are in direct child directories get found. I'm running twistd as root, since the server runs on port 80. The manpage for twistd says:

Note that if twistd is run as root, the working directory is not searched for Python modules.

Well that's great but why? And how can I work around? twistd seems to be ignoring --rundir . even if I set that option explicitly.

+4  A: 

General UNIX wisdom is that searching the working directory for things to execute when root is a bad idea. The argument goes that it opens the door to trojans. In not going out of its way to add the working directory to the Python module import search path when running as root, twistd is basically trying to follow this wisdom.

As another commenter said, you can explicitly set PYTHONPATH yourself to include the directories which contain the code your app needs.

You can also skip running as root entirely and use authbind to bind low-numbered ports without having superuser privileges. This is how all of my servers are deployed.

Jean-Paul Calderone
Wait, with authbind I can run on ports < 1024 without being root, and I don't need to recompile my kernel? That's great, wish I knew about that earlier.
darkporter