[SOLVED] Changing mode / group of WSGIServer socket in Python 2.7.x
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have looked at the online documentation for WSGIServer 1.3 but it does not seem to have its own way of changing the group and mode of the sockets it creates.
How can I change the group + permissions of a socket at the moment it is created? Or, failing that, how can those changes be done from within Python in any other way?
Where is that line of code you pasted coming from? I'm asking because WSGIServer class from the package that you linked to doesn't support bindAddress keyword argument, here's what I get when I try to run simple WSGI app using it:
Code:
Traceback (most recent call last):
File "/tmp/foo.py", line 9, in <module>
WSGIServer(application, bindAddress='/tmp/moinmoin.sock').run()
TypeError: __init__() got an unexpected keyword argument 'bindAddress'
This can only mean that WSGIServer class in your code is unrelated to the package you linked to and comes from another codebase.
MoinMoin uses flup library for FCGI, its WSGIServer class accepts umask keyword argument, so you can use that to set required permissions:
Code:
# Prepend number with zero to treat it as an octal.
WSGIServer(application, bindAddress="/var/www/run/sockets/moinmoin.sock", umask=0077).run()
Regarding socket group, you could use os.chown() for that, but it must be called before WSGIServer().run() is called, because run() method won't terminate (it will listen to the socket forever unless interrupted) and the socket file itself is not created before run() method is called, so it's a bit of a chicken-and-egg problem. Of course, you could change socket group from another process.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.