How to call a bash process from django / wsgi?

I use the mod_wsgi apache2 adapter for the django site, and I like to name some bash process in the view using regular

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

This code works fine from a regular python shell, but does nothing (I can track right now) when called in django. Am I missing some wsgi restrictions? The script has 755 perm, so it must be executed.

Quick test

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

shows that he doesn't even execute trivial commands. At the moment I am out of ideas and grateful for any contribution.

Thanks.

+4
source share
2 answers

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

There are ways you can get around this thing (setuid, sudo), but you better know what you are doing.

I would change your call to Popen to open another script that has the contents of date >> /home/example.com/test.txt to see if it actually executes it, and then you may worry about trying to debug permissions.

+2
source

Write to standard output

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

Is this applicable? I am exploring a similar problem ...

0
source

Source: https://habr.com/ru/post/1306485/


All Articles