Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Apache - Run script as Root

My django project calls a python file at a scheduled time using "at" scheduler. This is executed within my models.py

command = 'echo "python /path/to/script.py params" | /usr/bin/at -t [time] &> path/to/at.log'
status = os.system(command)

Where [time] is schedule time. It works perfectly when I run it within Django Dev server (I usually run as root but it also works with other users as well) But when I deployed my application on Apache using mod_wsgi, it doesn't work. at logs shows that the job was schedule but it doesn't execute it. I tried everything from changing the ownership to www-data, permissions, made it into executable to all users, to setuid to root (Huge Security Issue) The last thing I want to do is run apache as root user.

like image 568
melsk Avatar asked Jan 19 '26 16:01

melsk


1 Answers

Use cron or celery for scheduled tasks. If you need to run something as root, it'd make sense to re-write your script as a simple daemon and run that as root, you can pass commands to it pretty easily with zeromq.

like image 127
zeekay Avatar answered Jan 21 '26 05:01

zeekay