bytejunkie
bytejunkie

Reputation: 1033

django-chronograph script wont run from cron job or manually due to permissions issue

I've created a custom management command as a py file, in the usual place.

chronograph is installed in the right place and syncd ok.

I've created the cron job as the following

* * * * * /home/shofty/virtualenvs/webbricks/bin/chronograph -e /home/shofty/virtualenvs/webbricks/bin/activate_this.py -p /home/shofty/virtualenvs/webbricks/website

ive also tried the following, as i think it may be correct but not whats in the documentation

* * * * * /home/shofty/virtualenvs/webbricks/bin/chronograph -e /home/shofty/virtualenvs/webbricks/bin/activate_this.py -p /home/shofty/virtualenvs/webbricks/website/manage.py cron

I've added the manage.py cron because its what you run to tell the chronograph function to look for jobs that need running. if im in my virtual env and i run manage.py cron it works and the job runs.

both jobs are failing to run, but when i try to run them manually, as su or my user, they fail due to permissions denied. not sure what permission they're referring to. anyone come across this before?

Upvotes: 1

Views: 1047

Answers (4)

bytejunkie
bytejunkie

Reputation: 1033

The answer for this was that chronograph.sh has been superseded by chronograph. despite this supposedly being able to activate an env, it wasn't doing it early enough to import argparse which as far as i can tell isn't inbuilt to python 2.5 but is in 2.6. then its just down to getting the right combination of arguements for the chronograph script, which for reference is a -p and an -e but not an -s.

also i had to run the script as root but targetting the script inside the users virtualenv.

finally i also had to add site paths for packages directory to the chronograph script as it couldnt find argparse until i did that.

Upvotes: 1

Aaron
Aaron

Reputation: 4286

Is it os permission denied or are your receiving a 403? If it is a 403 I think is most likely caused by Django's CSRF protection. If your script is posting to a particular view, make sure to mark it as csrf_exempt

If the permission denied is at the file system / operating system level then I don't really know.

Upvotes: 0

xentoo
xentoo

Reputation: 130

As you're using a virtual environment: Included is a script called chronograph.sh. Copy this file to your project directory.

cp chronograph.sh ~/virtualenvs/webbricks/chronograph.sh

You need to open up this script and modify the path to your virtual environment's activate script::

$PROJECT_PATH"/home/shofty/virtualenvs/webbricks/bin/activate"

Make sure that this file is executable and then update your crontab to execute the script.

chmod a-x chronograph.sh

Then: crontab -e

* * * * * /home/shofty/virtualenvs/webbricks/chronograph.sh /home/shofty/virtualenvs/webbricks/website

Make sure that you pass /path/to/your/project to the script as the first argument. This should ensure that cron shouldn't have problems finding your project directory.

Upvotes: 0

xentoo
xentoo

Reputation: 130

You may find this comes in handy for issue you have with file permissions. File permission basics

Have you tried running the cron job as the appropriate user/service?

To edit crontab entries of other Linux users, login to root and use -u {username} -e as shown below.

root@dev-db# crontab -u otheruser -e
@monthly /home/otheruser/fedora/bin/monthly-backup
00 09-18 * * * /home/otheruser/ubuntu/bin/check-db-status

Upvotes: 0

Related Questions