WebFaction
Community site: login faq

If I call ~/webapps/django/apache2/bin/restart from the command line it works, if I run a python script that calls this command it works, but if I set a cronjob that calls the python script, it doesn't, the site just displays "Internal Server Error", any idea why? Also can't seem to find a relevant error log.

Just to be clear the script does run when using a cronjob, it just results in a Internal Server Error instead of restarting the site correctly.

Cron:

9,29,49 * * * * ~/webapps/django/apache2/bin/start
5,25,45 * * * * ~/webapps/bjarni/apache2/bin/start
18,38,58 * * * * ~/webapps/ps/apache2/bin/start
*/1 * * * * ~/restart_service.py

Script:

#!/usr/bin/python

from subprocess import call
import urllib

a = urllib.urlopen("http://mysite.is/")
code = a.getcode()
if code == 200:
  print "is"
  call(['echo "$(date) 200" > ~/rlog.txt'], shell=True)
else:
  print "isnot"
  call(['echo "$(date) NOT200" > ~/rlogNOT.txt'], shell=True)
  call(["~/webapps/django/apache2/bin/restart"], shell=True)

asked 18 May, 14:00

01AutoMonkey's gravatar image

01AutoMonkey
11
accept rate: 0%

edited 18 May, 14:01

Generally, a simple cron apache restart task should work fine if it runs from the command line. Can you try redirecting the cron job output to a log to see if it can provide any errors that can help us troubleshoot it?

See: https://docs.webfaction.com/software/general.html?highlight=cron#scheduling-tasks-with-cron

(19 May, 23:05) NickR ♦♦ NickR's gravatar image

Just discovered that directly restarting the service through a cronjob (not through a script) also results in an Internal Server Error, so it's definitely not a problem with the script but with calling restart from cron, hmmmmmmmmmm.

(yesterday) 01AutoMonkey 01AutoMonkey's gravatar image

Cron runs under a different environment - eg, things like the PATH environment variable are different.

Your apache error log is ~/logs/user/error_django.log - the error that appears there should give you some clue about whatever environment/config is missing when the aapp is restarted via your script.

permanent link

answered yesterday

seanf's gravatar image

seanf ♦♦
11.4k21233
accept rate: 37%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×328
×78

question asked: 18 May, 14:00

question was seen: 97 times

last updated: yesterday

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2016 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM