forked from SergeyZh/docker-awslogs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure-awslogs.sh
executable file
·64 lines (46 loc) · 1.56 KB
/
configure-awslogs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
add_log()
{
LOG_FILE_VAR_NAME=AWS_LOGFILE$1
LOG_FILE=${!LOG_FILE_VAR_NAME}
if [ "$LOG_FILE" == "" ]; then
return 0
fi
LOG_FORMAT_VAR_NAME=AWS_LOGFORMAT$1
LOG_FORMAT=${!LOG_FORMAT_VAR_NAME:-"%d/%b/%Y:%H:%M:%S %z"}
DURATION_VAR_NAME=AWS_DURATION$1
DURATION=${!DURATION_VAR_NAME:-"5000"}
GROUP_NAME_VAR_NAME=AWS_GROUPNAME$1
GROUP_NAME=${!GROUP_NAME_VAR_NAME:-"nginx-server"}
LOG_STREAM_NAME_VAR_NAME=AWS_LOG_STREAM_NAME$1
LOG_STREAM_NAME=${!LOG_STREAM_NAME_VAR_NAME:-'{instance_id}'}
LOG_GROUP_RETENTION_POLICY_DAYS_VAR_NAME=AWS_LOG_GROUP_RETENTION_POLICY_DAYS$1
LOG_GROUP_RETENTION_POLICY_DAYS=${!LOG_GROUP_RETENTION_POLICY_DAYS_VAR_NAME:-'90'}
MULTI_LINE_START_PATTERN_VAR_NAME=AWS_MULTI_LINE_START_PATTERN$1
MULTI_LINE_START_PATTERN=${!MULTI_LINE_START_PATTERN_VAR_NAME:-'^[^\s]'}
cat >> /var/awslogs/etc/awslogs.conf <<EOF
[${LOG_FILE}]
datetime_format = ${LOG_FORMAT}
file = ${LOG_FILE}
buffer_duration = ${DURATION}
log_stream_name = ${LOG_STREAM_NAME}
initial_position = start_of_file
log_group_name = ${GROUP_NAME}
multi_line_start_pattern = ${MULTI_LINE_START_PATTERN}
EOF
# Trying to create the log group so we can set a policy on it. It will simply fail if the
# log group already exists
aws logs create-log-group --log-group-name ${GROUP_NAME}
# Set retention policy
aws logs put-retention-policy --log-group-name ${GROUP_NAME} --retention-in-days ${LOG_GROUP_RETENTION_POLICY_DAYS}
return 1
}
add_log
result=1
index=1
while [ "$result" = "1" ]
do
add_log $index
result=$?
index=`expr $index + 1`
done