Running twistd as root, modules aren't found

筅森魡賤 提交于 2019-12-04 03:38:28

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/1807484/running-twistd-as-root-modules-arent-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!