-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-awscli-conf.sh
executable file
·99 lines (88 loc) · 2.63 KB
/
create-awscli-conf.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
cat << EOF
[general]
state_file = /var/lib/awslogs/agent-state
[/var/log/messages]
datetime_format = %b %d %H:%M:%S
file = /var/log/messages
buffer_duration = 5000
log_stream_name = {instance_id}
initial_position = start_of_file
log_group_name = /var/log/messages
[/var/log/mysqld.log]
datetime_format = %Y-%m-%d %H:%M:%S
file = /var/log/mysqld.log
buffer_duration = 5000
log_stream_name = {instance_id}
initial_position = start_of_file
log_group_name = /var/log/mysqld.log
[/var/log/php-fpm/www-error.log]
datetime_format = %d/%b/%Y:%H:%M:%S %z
file = /var/log/php-fpm/www-error.log
buffer_duration = 5000
log_stream_name = {instance_id}
initial_position = start_of_file
log_group_name = /var/log/php-fpm/www-error.log
EOF
for logfile in $(find /var/log/nginx/ -name '*.access.log'); do
logfile_name=${logfile##*/}
logfile_name_without_ext=${logfile_name%.*}
logfile_name_without_ext=${logfile_name_without_ext%.*}
if [[ "$logfile" =~ "backend" ]]; then
logfile_name_without_ext=${logfile_name_without_ext%.*}
logstream_name="-${logfile_name_without_ext}"
if [ "$logstream_name" = "-$INSTANCE_ID" ]; then
logstream_name=""
fi
#echo "backend.access.log: ${logfile}"
cat << EOF
[$logfile]
datetime_format = %d/%b/%Y:%H:%M:%S %z
file = $logfile
buffer_duration = 5000
log_stream_name = {instance_id}$logstream_name
initial_position = start_of_file
log_group_name = /var/log/nginx/backend.access.log
EOF
else
if [[ "$logfile" =~ "access" ]]; then
#echo "access.log: ${logfile}"
logstream_name="-${logfile_name_without_ext}"
if [ "$logstream_name" = "-$INSTANCE_ID" ]; then
logstream_name=""
fi
if [ "$logfile_name" != "access.log" ]; then
cat << EOF
[$logfile]
datetime_format = %d/%b/%Y:%H:%M:%S %z
file = $logfile
buffer_duration = 5000
log_stream_name = {instance_id}$logstream_name
initial_position = start_of_file
log_group_name = /var/log/nginx/access.log
EOF
fi
fi
fi
done
for logfile in $(find /var/log/nginx/ -name '*.error.log'); do
logfile_name=${logfile##*/}
logfile_name_without_ext=${logfile_name%.*}
logfile_name_without_ext=${logfile_name_without_ext%.*}
if [ "$logfile_name" != "error.log" ]; then
logstream_name="-${logfile_name_without_ext}"
if [ "$logstream_name" = "-$INSTANCE_ID" ]; then
logstream_name=""
fi
cat << EOF
[$logfile]
datetime_format = %d/%b/%Y:%H:%M:%S %z
file = $logfile
buffer_duration = 5000
log_stream_name = {instance_id}$logstream_name
initial_position = start_of_file
log_group_name = /var/log/nginx/error.log
EOF
fi
done