Commit e51bfcdd by Han Su Kim

Cleaning up dollar vars

typo fix

removing unneeded var declaration

changed ${ vars

changed local vars to $, not ${

typo

changed $region var

changes to ${ vars

changes to lb and rb

typo
parent 5ccc8ce3
...@@ -10,12 +10,7 @@ if (( $EUID != 0 )); then ...@@ -10,12 +10,7 @@ if (( $EUID != 0 )); then
exit 1 exit 1
fi fi
S3_LOGFILE="{{ aws_s3_logfile }}" exec > >(tee "{{ aws_s3_logfile }}")
NOTIFY_EMAIL={{ AWS_S3_LOGS_NOTIFY_EMAIL }}
FROM_EMAIL={{ AWS_S3_LOGS_FROM_EMAIL }}
AWS_CMD={{ aws_cmd }}
exec > >(tee $S3_LOGFILE)
exec 2>&1 exec 2>&1
shopt -s extglob shopt -s extglob
...@@ -23,11 +18,11 @@ shopt -s extglob ...@@ -23,11 +18,11 @@ shopt -s extglob
usage() { usage() {
cat<<EO cat<<EO
A wrapper of s3cmd sync that will sync files to A wrapper of s3cmd sync that will sync files to
an s3 bucket, will send mail to {{ AWS_S3_LOGS_NOTIFY_EMAIL }} an s3 bucket, will send mail to {{ AWS_S3_LOGS_NOTIFY_EMAIL }}
on failures. on failures.
Usage: $PROG Usage: $PROG
-v add verbosity (set -x) -v add verbosity (set -x)
-n echo what will be done -n echo what will be done
...@@ -57,7 +52,7 @@ done ...@@ -57,7 +52,7 @@ done
# bucket # bucket
# If there are any errors from this point # If there are any errors from this point
# send mail to $NOTIFY_EMAIL # send mail to {{ AWS_S3_LOGS_NOTIFY_EMAIL }}
set -e set -e
...@@ -68,22 +63,22 @@ s3_path=unset ...@@ -68,22 +63,22 @@ s3_path=unset
onerror() { onerror() {
if [[ -z $noop ]]; then if [[ -z $noop ]]; then
message_file=/var/tmp/message-$$.json message_file=/var/tmp/message-$$.json
message_string="Error syncing $s3_path: inst_id=$instance_id ip=$ip region=$region" message_string="Error syncing $s3_path: inst_id=$instance_id ip=$ip region={{ region }}"
if [[ -r $S3_LOGFILE ]]; then if [[ -r "{{ aws_s3_logfile }}" ]]; then
python -c "import json; d={'Subject':{'Data':'$message_string'},'Body':{'Text':{'Data':open('$S3_LOGFILE').read()}}};print json.dumps(d)" > $message_file python -c "import json; d={'Subject':{'Data':'$message_string'},'Body':{'Text':{'Data':open('"{{ aws_s3_logfile }}"').read()}}};print json.dumps(d)" > $message_file
else else
cat << EOF > $message_file cat << EOF > $message_file
{"Subject": { "Data": "$message_string" }, "Body": { "Text": { "Data": "!! ERROR !! no logfile" } } } {"Subject": { "Data": "$message_string" }, "Body": { "Text": { "Data": "!! ERROR !! no logfile" } } }
EOF EOF
fi fi
echo "ERROR: syncing $s3_path on $instance_id" echo "ERROR: syncing $s3_path on $instance_id"
$AWS_CMD ses send-email --from $FROM_EMAIL --to $NOTIFY_EMAIL --message file://$message_file --region $region {{ aws_cmd }} ses send-email --from {{ AWS_S3_LOGS_FROM_EMAIL }} --to {{ AWS_S3_LOGS_NOTIFY_EMAIL }} --message file://$message_file --region {{ region }}
else else
echo "Error syncing $s3_path on $instance_id" echo "Error syncing $s3_path on $instance_id"
fi fi
} }
trap onerror ERR SIGHUP SIGINT SIGTERM trap onerror ERR SIGHUP SIGINT SIGTERM
# first security group is used as the directory name in the bucket # first security group is used as the directory name in the bucket
sec_grp=$(ec2metadata --security-groups | head -1) sec_grp=$(ec2metadata --security-groups | head -1)
...@@ -95,5 +90,5 @@ region=${availability_zone:0:${{lb}}#availability_zone{{rb}} - 1} ...@@ -95,5 +90,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 sync {{ item['path'] }} "s3://{{ item['bucket'] }}/$sec_grp/${instance_id}-${ip}/" $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