forked from SergeyZh/docker-awslogs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-services.sh
More file actions
66 lines (50 loc) · 1.38 KB
/
run-services.sh
File metadata and controls
66 lines (50 loc) · 1.38 KB
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
63
64
65
66
#!/bin/bash
shutdown_awslogs()
{
echo "Stopping container..."
kill $(pgrep -f /var/awslogs/bin/aws)
exit 0
}
trap shutdown_awslogs INT TERM HUP
# [/mnt/logs/access.log]
# datetime_format = %d/%b/%Y:%H:%M:%S %z
# file = /mnt/logs/access.log
# buffer_duration = 5000
# log_stream_name = {instance_id}
# initial_position = start_of_file
# log_group_name = nginx-server
LOGFILE=${AWS_LOGFILE:-"/mnt/logs/access.log"}
LOGFORMAT=${AWS_LOGFORMAT:-"%d/%b/%Y:%H:%M:%S %z"}
DURATION=${AWS_DURATION:-"5000"}
GROUPNAME=${AWS_GROUPNAME:-"nginx-server"}
STREAM_NAME=${AWS_STREAM_NAME:-"{instance_id\}"}
INITIAL_POSITION=${AWS_INITIAL_POSITION:-"start-of-file"}
REGION=${AWS_REGION:-"us-east-1"}
cp -f /awslogs.conf.dummy /var/awslogs/etc/awslogs.conf
cat >> /var/awslogs/etc/awslogs.conf <<EOF
[general]
logging_config_file=/var/awslogs/etc/logger.conf
[${LOGFILE}]
datetime_format = ${LOGFORMAT}
file = ${LOGFILE}
buffer_duration = ${DURATION}
log_stream_name = ${STREAM_NAME}
initial_position = ${INITIAL_POSITION}
log_group_name = ${GROUPNAME}
EOF
cat > /var/awslogs/etc/aws.conf <<EOF
[plugins]
cwlogs = cwlogs
[default]
region = ${AWS_REGION}
EOF
if [ ! -z ${AWS_ACCESS_KEY_ID} ]; then
mkdir /root/.aws
cat > /root/.aws/credentials <<EOF
[default]
aws_access_key_id = ${AWS_ACCESS_KEY_ID}
aws_secret_access_key = ${AWS_SECRET_ACCESS_KEY}
EOF
fi
/var/awslogs/bin/awslogs-agent-launcher.sh &
wait