Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
configuration
Commits
aa780887
Commit
aa780887
authored
Aug 25, 2014
by
John Jarvis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync logs on rotation instead of by a cron job
parent
e3a6dca1
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
50 additions
and
51 deletions
+50
-51
playbooks/edx-east/lifecycle_inventory.py
+6
-6
playbooks/edx-east/retire_host.yml
+5
-25
playbooks/roles/aws/defaults/main.yml
+1
-11
playbooks/roles/aws/tasks/main.yml
+3
-2
playbooks/roles/aws/templates/etc/init/sync-on-stop.conf.j2
+3
-2
playbooks/roles/aws/templates/send-logs-to-s3.j2
+17
-4
playbooks/roles/common/defaults/main.yml
+5
-1
playbooks/roles/common/templates/etc/logrotate.d/hourly/edx_logrotate.j2
+7
-0
playbooks/roles/common/templates/etc/logrotate.d/hourly/edx_logrotate_tracking_log.j2
+3
-0
No files found.
playbooks/edx-east/lifecycle_inventory.py
View file @
aa780887
...
@@ -64,10 +64,10 @@ class LifecycleInventory():
...
@@ -64,10 +64,10 @@ class LifecycleInventory():
for
instance
in
group
.
instances
:
for
instance
in
group
.
instances
:
private_ip_address
=
instances
[
instance
.
instance_id
]
.
private_ip_address
private_ip_address
=
instances
[
instance
.
instance_id
]
.
private_ip_address
if
private_ip_address
:
inventory
[
group
.
name
]
.
append
(
private_ip_address
)
inventory
[
group
.
name
]
.
append
(
private_ip_address
)
inventory
[
group
.
name
+
"_"
+
instance
.
lifecycle_state
]
.
append
(
private_ip_address
)
inventory
[
group
.
name
+
"_"
+
instance
.
lifecycle_state
]
.
append
(
private_ip_address
)
inventory
[
instance
.
lifecycle_state
.
replace
(
":"
,
"_"
)]
.
append
(
private_ip_address
)
inventory
[
instance
.
lifecycle_state
.
replace
(
":"
,
"_"
)]
.
append
(
private_ip_address
)
print
json
.
dumps
(
inventory
,
sort_keys
=
True
,
indent
=
2
)
print
json
.
dumps
(
inventory
,
sort_keys
=
True
,
indent
=
2
)
...
@@ -77,8 +77,8 @@ if __name__=="__main__":
...
@@ -77,8 +77,8 @@ if __name__=="__main__":
parser
.
add_argument
(
'-p'
,
'--profile'
,
help
=
'The aws profile to use when connecting.'
)
parser
.
add_argument
(
'-p'
,
'--profile'
,
help
=
'The aws profile to use when connecting.'
)
parser
.
add_argument
(
'-l'
,
'--list'
,
help
=
'Ansible passes this, we ignore it.'
,
action
=
'store_true'
,
default
=
True
)
parser
.
add_argument
(
'-l'
,
'--list'
,
help
=
'Ansible passes this, we ignore it.'
,
action
=
'store_true'
,
default
=
True
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
LifecycleInventory
(
args
.
profile
)
.
run
()
LifecycleInventory
(
args
.
profile
)
.
run
()
playbooks/edx-east/retire_host.yml
View file @
aa780887
# ansible-playbook -i ./lifecycle_inventory.py ./retire_host.yml
# ansible-playbook -i ./lifecycle_inventory.py ./retire_host.yml
# -e@/vars/env.yml --limit Terminating_Wait
# -e@/vars/env.yml --limit Terminating_Wait
#
#
...
@@ -19,35 +19,15 @@
...
@@ -19,35 +19,15 @@
sudo
:
True
sudo
:
True
gather_facts
:
False
gather_facts
:
False
tasks
:
tasks
:
-
name
:
Force a log rotation
# We only force a rotation of edx logs.
command
:
/usr/sbin/logrotate -f /etc/logrotate.d/{{ item }}
# Forced rotation of system logfiles will only
with_items
:
# work if there hasn't already been a previous rotation
-
"
apport"
-
name
:
Force a log rotation which will call the log sync
-
"
apt"
-
"
aptitude"
-
"
dpkg"
-
"
hourly"
-
"
landscape-client"
-
"
newrelic-sysmond"
-
"
nginx"
-
"
nginx-access"
-
"
nginx-error"
-
"
ppp"
-
"
rsyslog"
-
"
ufw"
-
"
unattended-upgrades"
-
"
upstart"
-
name
:
Force a log rotation
command
:
/usr/sbin/logrotate -f /etc/logrotate.d/hourly/{{ item }}
command
:
/usr/sbin/logrotate -f /etc/logrotate.d/hourly/{{ item }}
with_items
:
with_items
:
-
"
tracking.log"
-
"
tracking.log"
-
"
edx-services"
-
"
edx-services"
-
name
:
Terminate existing s3 log sync
command
:
/usr/bin/pkill send-logs-to-s3 ||
true
-
name
:
Send logs to s3
command
:
/edx/bin/send-logs-to-s3
-
name
:
Run minos verification
-
name
:
Run minos verification
hosts
:
Terminating_Wait
hosts
:
Terminating_Wait
sudo
:
True
sudo
:
True
...
...
playbooks/roles/aws/defaults/main.yml
View file @
aa780887
...
@@ -23,16 +23,6 @@ AWS_S3_LOGS: false
...
@@ -23,16 +23,6 @@ AWS_S3_LOGS: false
# This relies on your server being able to send mail
# This relies on your server being able to send mail
AWS_S3_LOGS_NOTIFY_EMAIL
:
dummy@example.com
AWS_S3_LOGS_NOTIFY_EMAIL
:
dummy@example.com
AWS_S3_LOGS_FROM_EMAIL
:
dummy@example.com
AWS_S3_LOGS_FROM_EMAIL
:
dummy@example.com
# Separate buckets for tracking logs and everything else
# You should be overriding the environment and deployment vars
# Order of precedence is left to right for exclude and include options
AWS_S3_LOG_PATHS
:
-
bucket
:
"
edx-{{
COMMON_ENVIRONMENT
}}-{{
COMMON_DEPLOYMENT
}}/logs/tracking"
path
:
"
{{
COMMON_LOG_DIR
}}/tracking/*"
-
bucket
:
"
edx-{{
COMMON_ENVIRONMENT
}}-{{
COMMON_DEPLOYMENT
}}/logs/application"
path
:
"
{{
COMMON_LOG_DIR
}}/!(*tracking*)"
-
bucket
:
"
edx-{{
COMMON_ENVIRONMENT
}}-{{
COMMON_DEPLOYMENT
}}/logs/system"
path
:
"
/var/log/*"
#
#
# vars are namespace with the module name.
# vars are namespace with the module name.
...
@@ -45,7 +35,7 @@ aws_s3_logfile: "{{ aws_log_dir }}/s3-log-sync.log"
...
@@ -45,7 +35,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"
aws_region
:
"
us-east-1"
aws_region
:
"
us-east-1"
# default path to the aws binary
# default path to the aws binary
s3cmd_
cmd
:
"
{{
COMMON_BIN_DIR
}}/s3cmd"
aws_s3
cmd
:
"
{{
COMMON_BIN_DIR
}}/s3cmd"
aws_cmd
:
"
/usr/local/bin/aws"
aws_cmd
:
"
/usr/local/bin/aws"
#
#
# OS packages
# OS packages
...
...
playbooks/roles/aws/tasks/main.yml
View file @
aa780887
...
@@ -68,7 +68,7 @@
...
@@ -68,7 +68,7 @@
-
name
:
create symlink for s3cmd
-
name
:
create symlink for s3cmd
file
:
>
file
:
>
src={{ aws_app_dir }}/{{ aws_s3cmd_version }}/s3cmd
src={{ aws_app_dir }}/{{ aws_s3cmd_version }}/s3cmd
dest={{
COMMON_BIN_DIR }}/s3cmd
dest={{
aws_s3cmd }}
state=link
state=link
-
name
:
create s3 log sync script
-
name
:
create s3 log sync script
...
@@ -84,7 +84,7 @@
...
@@ -84,7 +84,7 @@
dest={{ COMMON_BIN_DIR }}/{{ aws_s3_sync_script|basename }}
dest={{ COMMON_BIN_DIR }}/{{ aws_s3_sync_script|basename }}
when
:
AWS_S3_LOGS
when
:
AWS_S3_LOGS
-
name
:
run s3 log sync script on supervisor shutdown
-
name
:
force logrotate on supervisor stop
template
:
>
template
:
>
src=etc/init/sync-on-stop.conf.j2
src=etc/init/sync-on-stop.conf.j2
dest=/etc/init/sync-on-stop.conf
dest=/etc/init/sync-on-stop.conf
...
@@ -99,4 +99,5 @@
...
@@ -99,4 +99,5 @@
user
:
root
user
:
root
minute
:
0
minute
:
0
job
:
"
{{
aws_s3_sync_script
}}
>
/dev/null
2>&1"
job
:
"
{{
aws_s3_sync_script
}}
>
/dev/null
2>&1"
state
:
absent
when
:
AWS_S3_LOGS
when
:
AWS_S3_LOGS
playbooks/roles/aws/templates/etc/init/sync-on-stop.conf.j2
View file @
aa780887
start on stopped supervisor
start on stopped supervisor
description "sync
s3
logs on supervisor shutdown"
description "sync
tracking
logs on supervisor shutdown"
script
script
/bin/bash {{ aws_s3_sync_script }}
/usr/sbin/logrotate -f /etc/logrotate.d/hourly/tracking.log
/usr/sbin/logrotate -f /etc/logrotate.d/hourly/edx-services
end script
end script
playbooks/roles/aws/templates/send-logs-to-s3.j2
View file @
aa780887
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#
#
# This script can be called from logrotate
# This script can be called from logrotate
# to sync logs to s3
# to sync logs to s3
#
if (( $EUID != 0 )); then
if (( $EUID != 0 )); then
echo "Please run as the root user"
echo "Please run as the root user"
...
@@ -31,10 +32,12 @@ usage() {
...
@@ -31,10 +32,12 @@ 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
-d directory to sync
-b bucket path to sync to
EO
EO
}
}
while getopts "vhn" opt; do
while getopts "vhn
b:d:
" opt; do
case $opt in
case $opt in
v)
v)
set -x
set -x
...
@@ -48,9 +51,21 @@ while getopts "vhn" opt; do
...
@@ -48,9 +51,21 @@ while getopts "vhn" opt; do
noop="echo Would have run: "
noop="echo Would have run: "
shift
shift
;;
;;
d)
directory=$OPTARG
;;
b)
bucket_path=$OPTARG
;;
esac
esac
done
done
if [[ -z $bucket_path || -z $directory ]]; then
echo "ERROR: You must provide a directory and a bucket to sync!"
usage
exit 1
fi
# grab the first security group for the instance
# grab the first security group for the instance
# which will be used as a directory name in the s3
# which will be used as a directory name in the s3
# bucket
# bucket
...
@@ -93,6 +108,4 @@ availability_zone=$(ec2metadata --availability-zone)
...
@@ -93,6 +108,4 @@ availability_zone=$(ec2metadata --availability-zone)
region=${availability_zone:0:${{lb}}#availability_zone{{rb}} - 1}
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 -%}
$noop {{ aws_s3cmd }} sync $directory "s3://${bucket_path}/${sec_grp}/${instance_id}-${ip}/"
$noop {{ s3cmd_cmd }} sync {{ item['path'] }} "s3://{{ item['bucket'] }}/$sec_grp/${instance_id}-${ip}/"
{% endfor %}
playbooks/roles/common/defaults/main.yml
View file @
aa780887
...
@@ -7,7 +7,11 @@
...
@@ -7,7 +7,11 @@
COMMON_ENABLE_BASIC_AUTH
:
False
COMMON_ENABLE_BASIC_AUTH
:
False
COMMON_HTPASSWD_USER
:
edx
COMMON_HTPASSWD_USER
:
edx
COMMON_HTPASSWD_PASS
:
edx
COMMON_HTPASSWD_PASS
:
edx
# Turn on syncing logs on rotation for edx
# application and tracking logs, must also
# have the AWS role installed
COMMON_AWS_SYNC
:
False
COMMON_AWS_SYNC_BUCKET
:
"
edx-{{
COMMON_ENVIRONMENT
}}-{{
COMMON_DEPLOYMENT
}}"
COMMON_BASE_DIR
:
/edx
COMMON_BASE_DIR
:
/edx
COMMON_DATA_DIR
:
"
{{
COMMON_BASE_DIR}}/var"
COMMON_DATA_DIR
:
"
{{
COMMON_BASE_DIR}}/var"
COMMON_APP_DIR
:
"
{{
COMMON_BASE_DIR}}/app"
COMMON_APP_DIR
:
"
{{
COMMON_BASE_DIR}}/app"
...
...
playbooks/roles/common/templates/etc/logrotate.d/hourly/edx_logrotate.j2
View file @
aa780887
...
@@ -12,5 +12,12 @@
...
@@ -12,5 +12,12 @@
size 1M
size 1M
postrotate
postrotate
/usr/bin/killall -HUP rsyslogd
/usr/bin/killall -HUP rsyslogd
{% if COMMON_AWS_SYNC -%}
for dir in `ls {{ COMMON_LOG_DIR }}`; do
if echo $dir | grep -qv tracking; then
{{ aws_s3_sync_script }} -d {{ COMMON_LOG_DIR }}/$dir -b "{{ COMMON_AWS_SYNC_BUCKET }}/logs/application"
fi
done
{% endif -%}
endscript
endscript
}
}
playbooks/roles/common/templates/etc/logrotate.d/hourly/edx_logrotate_tracking_log.j2
View file @
aa780887
...
@@ -10,5 +10,8 @@
...
@@ -10,5 +10,8 @@
size 1M
size 1M
postrotate
postrotate
/usr/bin/killall -HUP rsyslogd
/usr/bin/killall -HUP rsyslogd
{% if COMMON_AWS_SYNC -%}
{{ aws_s3_sync_script }} -d "{{ COMMON_LOG_DIR }}/tracking/*" -b "{{ COMMON_AWS_SYNC_BUCKET }}/logs/tracking"
{% endif -%}
endscript
endscript
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment