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/开发者_JAVA技巧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.
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.
精彩评论