Skip to content

Commit

Permalink
Ensure log direcotory exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmac committed Mar 10, 2015
1 parent 8470b23 commit ba450fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,9 @@ language: python
python:
- "2.7"
env:
- PIP_DOWNLOAD_CACHE="pip_cache"
global:
- PIP_DOWNLOAD_CACHE="pip_cache"
- CRON_LOG_DIR="/tmp/bedrock-cron-log"
branches:
only:
- master
Expand Down
10 changes: 9 additions & 1 deletion bin/gen-crons.py
Expand Up @@ -7,7 +7,7 @@

HEADER = '!!AUTO-GENERATED!! Edit {template}.tmpl instead.'
TEMPLATE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'etc', 'cron.d'))
LOG_DIR = '/var/log/bedrock'
LOG_DIR = os.getenv('CRON_LOG_DIR', '/var/log/bedrock')


def main():
Expand All @@ -32,6 +32,13 @@ def main():
if not opts.template:
parser.error('-t must be defined')

# ensure log path exists
if not os.path.isdir(LOG_DIR):
try:
os.mkdir(LOG_DIR)
except OSError:
parser.error('failed to create log directory: ' + LOG_DIR)

log_file = 'cron-{0}.log'.format(opts.template.split('-')[1])
django_manage = 'cd {{dir}} && {py} manage.py'.format(py=opts.python)
django_cron = '{0} cron'.format(django_manage)
Expand Down Expand Up @@ -65,5 +72,6 @@ def main():
# atomically move into place
os.rename(tmpl_temp_name, tmpl_final_name)


if __name__ == '__main__':
main()

0 comments on commit ba450fd

Please sign in to comment.