views:

134

answers:

2

I'm using mod_wsgi apache2 adapter for a django site and I like to call some bash process within a view, using the usual

...
p = subprocess.Popen("/home/example.com/restart-tomcat.sh", shell=True)
sts = os.waitpid(p.pid, 0)[1]
...

This code works perfectly from within a usual python shell but does nothing (I can trace right now) when called within django. Am I missing some wsgi constraints? The script has 755 perms, so it should be executable.

A quick test

p = subprocess.Popen("date >> home/example.com/wsgi-test.txt", shell=True)
sts = os.waitpid(p.pid, 0)[1]

reveals that it does not even executes trivial commands. I am out of ideas at the moment and thankful for any input.

Thanks.

+2  A: 

The script itself may have 755 permissions, but things it calls might not have the correct permissions. Especially if you have tomcat running on port 80, which is a privileged port.

There are ways you can get around this sort of thing (setuid, sudo), but you'd better know exactly what you're doing.

I'd change your Popen call to open a different script that has the contents date >> /home/example.com/test.txt just to see if it's executing it at all, and then you can worry about trying to debug permissions.

synic
Thanks, did a test; it does not seem to execute anything, it does not even raise any OSError either .. Tomcat runs on a non-proviledged port, so that should not be a problem
chang
I almost want to ask if you can do something like opening a regular file at that path using python file io, `h = open('/home/example.com/test.txt', 'a'); h.write('line\n'); h.close();`. Really weird, if all the permissions are correct. It should work.
synic
Thank you for your comment. I am in the process of checking all the permissions right now .. especially the ones needed for a proper tomcat restart ..
chang
The Apache user may not have write access to that location. Write to a file in /tmp instead.
Graham Dumpleton
A: 

Writing To Standard Output

here: http://code.google.com/p/modwsgi/wiki/ApplicationIssues

Does that apply here? I'm research a similar problem....

gene
If you are using mod_wsgi 3.X then no, as that restriction was lifted because no one wanted to write portable code. See 'http://blog.dscpl.com.au/2009/04/wsgi-and-printing-to-standard-output.html'.
Graham Dumpleton