3

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.

2
  • at command only takes the name of the executable which is to be scheduled for execution with no parameters. echo basically forces at to schedule the executable along with it's parameters. Look up the man page for at Commented Aug 18, 2011 at 21:06
  • I think you're missing a set of quotes. Echo is written as a python keyword. Commented Aug 18, 2011 at 21:14

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

It ain't a recurring job, so can I use cron?
It's not recurring? I assumed it was. When/how often do you want this task run?
I would suggest using celery for spinning off tasks. You can use it without a broker, it's fairly easy to setup. To work around the root issue, you could setup a daemon process running as root, and issue commands to it with zeromq or something.
Thanks. I'll take a note of it next time. However, I made python write a bash file and made at execute that file to circumvent the root issue. However I noted that this issue only turns up on the production with apache on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.