I have a Django application running on Dotcloud. I have tried to add Logentries logging which works in normal usage for my site, but causes my cron jobs to fail with this error -
Traceback (most recent call last):
File "/home/dotcloud/current/my_project/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/dotcloud/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/dotcloud/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/dotcloud/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/home/dotcloud/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/home/dotcloud/env/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/home/dotcloud/env/local/lib/python2.7/site-packages/django/conf/__init__.py", line 50, in _setup
self._configure_logging()
File "/home/dotcloud/env/local/lib/python2.7/site-packages/django/conf/__init__.py", line 80, in _configure_logging
logging_config_func(self.LOGGING)
File "/usr/lib/python2.7/logging/config.py", line 777, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python2.7/logging/config.py", line 575, in configure
'%r: %s' % (name, e))
ValueError: Unable to configure handler 'logentries_handler': expected string or buffer
This is one of the scripts being run from cron -
#!/bin/bash
echo "Loading definitions - check /var/log/supervisor/availsserver.log for results"
. /etc/profile
/home/dotcloud/env/bin/python /home/dotcloud/current/my_project/manage.py load_definitions
These are my settings for Logentries -
'logentries_handler': {
'token': os.getenv("LOGENTRIES_TOKEN"),
'class': 'logentries.LogentriesHandler'
}
....
'logentries': {
'handlers': ['logentries_handler'],
'level': 'INFO',
},
The LOGENTRIES_TOKEN is there when I do dotcloud env list
.
This is a summary of the symptoms -
- Logentries logging works from the site in normal usage.
- If I manually run the script - dotcloud run www ~/current/scripts/load_definitions.sh
it works.
- If I remove the Logentries settings from my settings.py
the cron jobs work.
- The cron jobs fail if Logentries entries are in my settings.py
I have spent hours trying to find a solution. Can anyone help?
I have resolved this.
This is the crontab before -
0 13 * * * /home/dotcloud/current/scripts/load_definitions.sh 2>&1 | mail -s "Load definitions result" [email protected]
which didn't work.
This is how it is now -
0 13 * * * /bin/bash -l -c '/home/dotcloud/current/scripts/load_definitions.sh' 2>&1 | mail -s "Load definitions result" [email protected]
which works. Adding /bin/bash -l -c
fixed it. Perhaps someone can tell me why it didn't work the way it was?