-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathlogs.sh
More file actions
executable file
·90 lines (82 loc) · 2.75 KB
/
logs.sh
File metadata and controls
executable file
·90 lines (82 loc) · 2.75 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
######################################################################
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# SPDX-License-Identifier: MIT-0 #
######################################################################
source .env
if [ "${DEBUG}" == "true" ]; then
set -x
fi
echo ""
echo "Showing logs from container ${CONTAINER} on ${TO} ..."
case "${TO}" in
"compose")
if [ "$1" == "" ]; then
CMD="${DOCKER_COMPOSE} -f ${COMPOSE_FILE} logs -f"
else
CMD="docker logs -f ${COMPOSE_PROJECT_NAME}_${CONTAINER}_$1"
fi
;;
"swarm")
if [ "$1" == "" ]; then
CMD="docker service logs -f ${SWARM_STACK_NAME}_${SWARM_SERVICE_NAME}"
else
CMD="docker service ps ${SWARM_STACK_NAME}_${SWARM_SERVICE_NAME} | grep ${SWARM_SERVICE_NAME}.$1 | cut -d ' ' -f 1 | xargs docker service logs -f"
fi
;;
"ecs")
CONTAINER_INDEX=1
if [ ! "$1" == "" ]; then
CONTAINER_INDEX=$1
fi
CMD="${ECS_CLI} logs --task-id $(./status.sh | grep RUNNING | head -n ${CONTAINER_INDEX} | tail -n 1 | cut -d '/' -f 2) --follow"
;;
"kubernetes")
CMD="${KUBETAIL} ${APP_NAME} -n ${NAMESPACE} -s 30m"
;;
"lambda")
since="--since 1h"
if [ ! "$1" == "" ]; then
since="--since $1"
fi
CMD="aws logs tail ${since} --follow /aws/lambda/${LAMBDA_FUNCTION_NAME}"
;;
"batch")
if [ "$1" == "" ]; then
JOB_IDS_RUNNING=$(aws batch list-jobs --job-queue ${BATCH_JOB_QUEUE_NAME} --job-status RUNNING --query 'jobSummaryList[*].jobId' --output text)
JOB_IDS_SUCCEEDED=$(aws batch list-jobs --job-queue ${BATCH_JOB_QUEUE_NAME} --job-status SUCCEEDED --query 'jobSummaryList[*].jobId' --output text)
JOB_IDS_FAILED=$(aws batch list-jobs --job-queue ${BATCH_JOB_QUEUE_NAME} --job-status FAILED --query 'jobSummaryLists[*].jobId' --output text)
JOB_IDS="$JOB_IDS_RUNNING $JOB_IDS_SUCCEEDED $JOB_IDS_FAILED"
else
JOB_IDS="$@"
fi
for JOB_ID in ${JOB_IDS}; do
if [ ! "$JOB_ID" == "None" ]; then
echo ""
echo "Getting log evewnts for job ${JOB_ID} ..."
LOG_STREAM=$(aws batch describe-jobs --jobs ${JOB_ID} --query 'jobs[*].container.logStreamName' --output text)
CMD="aws logs get-log-events --log-group-name /aws/batch/job --no-paginate --query 'events[*].{timestamp:timestamp,message:message}' --output text --log-stream-name ${LOG_STREAM}"
if [ "${VERBOSE}" == "true" ]; then
echo "${CMD}"
fi
if [ "${DRY_RUN}" == "false" ]; then
eval "${CMD}"
fi
fi
done
CMD=""
;;
*)
checkTO "${TO}"
CMD="docker container logs -f ${CONTAINER}"
;;
esac
if [ "${VERBOSE}" == "true" ]; then
echo "${CMD}"
fi
if [ "${DRY_RUN}" == "false" ]; then
eval "${CMD}"
fi
if [ "${DEBUG}" == "true" ]; then
set +x
fi