Commit 750de2e5 by John Jarvis

Merge pull request #811 from edx/jarv/add-back-s3cmd

Jarv/add back s3cmd
parents 0bd18c13 0314201c
...@@ -28,14 +28,11 @@ AWS_S3_LOGS_FROM_EMAIL: dummy@example.com ...@@ -28,14 +28,11 @@ AWS_S3_LOGS_FROM_EMAIL: dummy@example.com
# Order of precedence is left to right for exclude and include options # Order of precedence is left to right for exclude and include options
AWS_S3_LOG_PATHS: AWS_S3_LOG_PATHS:
- bucket: "{{ COMMON_ENVIRONMENT }}-{{ COMMON_DEPLOYMENT }}-app-logs" - bucket: "{{ COMMON_ENVIRONMENT }}-{{ COMMON_DEPLOYMENT }}-app-logs"
path: "{{ COMMON_LOG_DIR }}/" path: "{{ COMMON_LOG_DIR }}/!(*tracking*)"
extra_args: "--exclude '*tracking*'"
- bucket: "{{ COMMON_ENVIRONMENT }}-{{ COMMON_DEPLOYMENT }}-app-logs" - bucket: "{{ COMMON_ENVIRONMENT }}-{{ COMMON_DEPLOYMENT }}-app-logs"
path: "/var/log/" path: "/var/log/*"
extra_args: ""
- bucket: "{{ COMMON_ENVIRONMENT }}-{{ COMMON_DEPLOYMENT }}-tracking-logs" - bucket: "{{ COMMON_ENVIRONMENT }}-{{ COMMON_DEPLOYMENT }}-tracking-logs"
path: "{{ COMMON_LOG_DIR }}/" path: "{{ COMMON_LOG_DIR }}/*tracking*"
extra_args: "--exclude '*' --include '*tracking*'"
# set this to true dump all extra vars # set this to true dump all extra vars
# this is currently broken when extra vars # this is currently broken when extra vars
...@@ -55,7 +52,7 @@ aws_s3_logfile: "{{ aws_log_dir }}/s3-log-sync.log" ...@@ -55,7 +52,7 @@ aws_s3_logfile: "{{ aws_log_dir }}/s3-log-sync.log"
aws_log_dir: "{{ COMMON_LOG_DIR }}/aws" aws_log_dir: "{{ COMMON_LOG_DIR }}/aws"
# default path to the aws binary # default path to the aws binary
aws_cmd: "/usr/local/bin/aws" aws_cmd: "{{ COMMON_BIN_DIR }}/s3cmd"
# #
# OS packages # OS packages
# #
...@@ -68,3 +65,5 @@ aws_pip_pkgs: ...@@ -68,3 +65,5 @@ aws_pip_pkgs:
- awscli - awscli
aws_redhat_pkgs: [] aws_redhat_pkgs: []
aws_s3cmd_version: s3cmd-1.5.0-beta1
aws_s3cmd_url: "http://files.edx.org/s3cmd/{{ aws_s3cmd_version }}.tar.gz"
...@@ -21,6 +21,18 @@ ...@@ -21,6 +21,18 @@
# #
# #
- name: create data and app directories
file: >
path={{ item }}
state=directory
owner=root
group=root
mode=0700
with_items:
- "{{ aws_data_dir }}"
- "{{ aws_app_dir }}"
- "{{ aws_log_dir }}"
- name: install system packages - name: install system packages
apt: > apt: >
pkg={{','.join(aws_debian_pkgs)}} pkg={{','.join(aws_debian_pkgs)}}
...@@ -33,17 +45,22 @@ ...@@ -33,17 +45,22 @@
extra_args="-i {{ COMMON_PYPI_MIRROR_URL }}" extra_args="-i {{ COMMON_PYPI_MIRROR_URL }}"
with_items: aws_pip_pkgs with_items: aws_pip_pkgs
- name: create data and app directories - name: get s3cmd
get_url: >
url={{ aws_s3cmd_url }}
dest={{ aws_data_dir }}/
- name: untar s3cmd
shell: >
tar xf {{ aws_data_dir }}/{{ aws_s3cmd_version }}.tar.gz
creates={{ aws_app_dir }}/{{ aws_s3cmd_version }}/s3cmd
chdir={{ aws_app_dir }}
- name: create symlink for s3cmd
file: > file: >
path={{ item }} src={{ aws_app_dir }}/{{ aws_s3cmd_version }}/s3cmd
state=directory dest={{ COMMON_BIN_DIR }}/s3cmd
owner=root state=link
group=root
mode=0700
with_items:
- "{{ aws_data_dir }}"
- "{{ aws_app_dir }}"
- "{{ aws_log_dir }}"
# The sync script and config file are now symlinks # The sync script and config file are now symlinks
# Remove them if they are regular files # Remove them if they are regular files
...@@ -122,14 +139,10 @@ ...@@ -122,14 +139,10 @@
when: AWS_S3_LOGS when: AWS_S3_LOGS
# cron job runs the aws s3 sync script # cron job runs the aws s3 sync script
# with the -c option which skips over
# .log files. This is because aws s3 sync
# has issues syncing files that are written
# to during the sync
- name: cronjob for s3 log sync - name: cronjob for s3 log sync
cron: > cron: >
name="cronjob for s3 log sync" name="cronjob for s3 log sync"
user=root user=root
minute=0 minute=0
job="{{ aws_s3_sync_script }} -c" job={{ aws_s3_sync_script }}
when: AWS_S3_LOGS when: AWS_S3_LOGS
...@@ -13,7 +13,7 @@ fi ...@@ -13,7 +13,7 @@ fi
S3_LOGFILE="{{ aws_s3_logfile }}" S3_LOGFILE="{{ aws_s3_logfile }}"
NOTIFY_EMAIL={{ AWS_S3_LOGS_NOTIFY_EMAIL }} NOTIFY_EMAIL={{ AWS_S3_LOGS_NOTIFY_EMAIL }}
FROM_EMAIL={{ AWS_S3_LOGS_FROM_EMAIL }} FROM_EMAIL={{ AWS_S3_LOGS_FROM_EMAIL }}
AWS_CMD="{{ aws_cmd }} --debug" AWS_CMD={{ aws_cmd }}
exec > >(tee $S3_LOGFILE) exec > >(tee $S3_LOGFILE)
exec 2>&1 exec 2>&1
...@@ -32,11 +32,10 @@ usage() { ...@@ -32,11 +32,10 @@ usage() {
-v add verbosity (set -x) -v add verbosity (set -x)
-n echo what will be done -n echo what will be done
-h this -h this
-c run as a cron which will exclude .log files
EO EO
} }
while getopts "vhnc" opt; do while getopts "vhn" opt; do
case $opt in case $opt in
v) v)
set -x set -x
...@@ -50,10 +49,6 @@ while getopts "vhnc" opt; do ...@@ -50,10 +49,6 @@ while getopts "vhnc" opt; do
noop="echo Would have run: " noop="echo Would have run: "
shift shift
;; ;;
c)
cron_exclude=\-\-exclude\ '*log'
shift
;;
esac esac
done done
...@@ -100,5 +95,5 @@ region=${availability_zone:0:${{lb}}#availability_zone{{rb}} - 1} ...@@ -100,5 +95,5 @@ region=${availability_zone:0:${{lb}}#availability_zone{{rb}} - 1}
s3_path="${2}/$sec_grp/" s3_path="${2}/$sec_grp/"
{% for item in AWS_S3_LOG_PATHS -%} {% for item in AWS_S3_LOG_PATHS -%}
$noop $AWS_CMD s3 sync {{ item['path'] }} "s3://{{ item['bucket'] }}/$sec_grp/${instance_id}-${ip}/" --region $region {{ item['extra_args'] }} $cron_exclude $noop $AWS_CMD sync {{ item['path'] }} "s3://{{ item['bucket'] }}/$sec_grp/${instance_id}-${ip}/"
{% endfor %} {% endfor %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment