From e254f030fc0817b66400b317d9276903a4731a00 Mon Sep 17 00:00:00 2001 From: drosenst Date: Thu, 9 Mar 2017 16:03:24 +0200 Subject: [PATCH] added more options to script including region for logs --- Dockerfile | 3 +- README.md | 16 ++++- eu-west-1/Dockerfile | 15 ---- eu-west-1/awslogs.conf.dummy | 128 ----------------------------------- eu-west-1/run-services.sh | 41 ----------- run-services.sh | 28 +++++++- 6 files changed, 42 insertions(+), 189 deletions(-) delete mode 100644 eu-west-1/Dockerfile delete mode 100644 eu-west-1/awslogs.conf.dummy delete mode 100644 eu-west-1/run-services.sh diff --git a/Dockerfile b/Dockerfile index 9876180..19c3cc6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,8 @@ RUN apt-get install -q -y python python-pip wget RUN cd / ; wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py ADD awslogs.conf.dummy / -RUN python /awslogs-agent-setup.py -n -r us-east-1 -c ./awslogs.conf.dummy +RUN mkdir /etc/cron.d +RUN python awslogs-agent-setup.py --region us-east-1 --non-interactive --configfile=./awslogs.conf.dummy # ONBUILD ADD aws.conf /var/awslogs/etc/aws.conf # ONBUILD ADD awslogs.conf /var/awslogs/etc/awslogs.conf diff --git a/README.md b/README.md index 0c9ade1..fbc2b89 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,15 @@ log_group_name = nginx-server * `AWS_LOGFORMAT` default is "%d/%b/%Y:%H:%M:%S %z" * `AWS_DURATION` default is "5000" * `AWS_GROUPNAME` default is "nginx-server" +* `AWS_STREAM_NAME` default is the instance_id +* `AWS_REGION` default is us-east-1 (region where logs are published) +* `AWS_INITIAL_POSITION` default is start-of-file (other option is end-of-file) + +If you have not defined a role for this instance, then you will need to pass +the AWS keys +* `AWS_ACCESS_KEY_ID` +* `AWS_SECRET_ACCESS_KEY` + ### Example @@ -32,11 +41,16 @@ docker run -d --name nginx -v /mnt/logs:/var/log/nginx -p 80:80 sergeyzh/centos6 docker run -d --name awslogs -e AWS_LOGFILE=/mnt/logs/access.log -e AWS_DURATION=10000 -v /mnt/logs:/mnt/logs sergeyzh/awslogs ``` -Now you can see access logs of your Nginx at [AWS Console](https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs:). +Now you can see access logs of your Nginx at [AWS Console](https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs:). NOTE: Of course you should run it on the Amazon EC2 and you should set IAM role for you instance according [manual](http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/QuickStartEC2Instance.html). +If you do not then run as follows + +docker run -d --name awslogs -e AWS_LOGFILE=/var/log/applogs.log -e AWS_DURATION=5000 -e AWS_GROUPNAME=/ci/messaging -e AWS_LOGFORMAT="%Y-%m-%d %H:%M:%S" -v /var/lib/docker/log/myapp/:/var/log awslogs + ### MAINTAINERS * Ryuta Otaki * Sergey Zhukov +* David Rosenstark diff --git a/eu-west-1/Dockerfile b/eu-west-1/Dockerfile deleted file mode 100644 index d981d1a..0000000 --- a/eu-west-1/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM ubuntu:latest -MAINTAINER Ryuta Otaki , Sergey Zhukov - -RUN apt-get update -RUN apt-get install -q -y python python-pip wget -RUN cd / ; wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py - -ADD awslogs.conf.dummy / -RUN python /awslogs-agent-setup.py -n -r eu-west-1 -c ./awslogs.conf.dummy -# ONBUILD ADD aws.conf /var/awslogs/etc/aws.conf -# ONBUILD ADD awslogs.conf /var/awslogs/etc/awslogs.conf - -ADD run-services.sh / -RUN chmod a+x /run-services.sh -CMD /run-services.sh diff --git a/eu-west-1/awslogs.conf.dummy b/eu-west-1/awslogs.conf.dummy deleted file mode 100644 index ec5170c..0000000 --- a/eu-west-1/awslogs.conf.dummy +++ /dev/null @@ -1,128 +0,0 @@ - -# -# ------------------------------------------ -# CLOUDWATCH LOGS AGENT CONFIGURATION FILE -# ------------------------------------------ -# -# --- DESCRIPTION --- -# This file is used by the CloudWatch Logs Agent to specify what log data to send to the service and how. -# You can modify this file at any time to add, remove or change configuration. -# -# NOTE: A running agent must be stopped and restarted for configuration changes to take effect. -# -# --- CLOUDWATCH LOGS DOCUMENTATION --- -# https://aws.amazon.com/documentation/cloudwatch/ -# -# --- CLOUDWATCH LOGS CONSOLE --- -# https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs: -# -# --- AGENT COMMANDS --- -# To check or change the running status of the CloudWatch Logs Agent, use the following: -# -# To check running status: /etc/init.d/awslogs status -# To stop the agent: /etc/init.d/awslogs stop -# To start the agent: /etc/init.d/awslogs start -# -# --- AGENT LOG OUTPUT --- -# You can find logs for the agent in /var/log/awslogs.log -# You can find logs for the agent script in /var/log/awslogs-agent-setup.log -# - -# ------------------------------------------ -# CONFIGURATION DETAILS -# ------------------------------------------ - -[general] -# Path to the CloudWatch Logs agent's state file. The agent uses this file to maintain -# client side state across its executions. -state_file = /var/awslogs/state/agent-state - -## Each log file is defined in its own section. The section name doesn't -## matter as long as its unique within this file. -#[kern.log] -# -## Path of log file for the agent to monitor and upload. -#file = /var/log/kern.log -# -## Name of the destination log group. -#log_group_name = kern.log -# -## Name of the destination log stream. You may use {hostname} to use target machine's hostname. -#log_stream_name = {instance_id} # Defaults to ec2 instance id -# -## Format specifier for timestamp parsing. Here are some sample formats: -## Use '%b %d %H:%M:%S' for syslog (Apr 24 08:38:42) -## Use '%d/%b/%Y:%H:%M:%S' for apache log (10/Oct/2000:13:55:36) -## Use '%Y-%m-%d %H:%M:%S' for rails log (2008-09-08 11:52:54) -#datetime_format = %b %d %H:%M:%S # Specification details in the table below. -# -## A batch is buffered for buffer-duration amount of time or 32KB of log events. -## Defaults to 5000 ms and its minimum value is 5000 ms. -#buffer_duration = 5000 -# -# Use 'end_of_file' to start reading from the end of the file. -# Use 'start_of_file' to start reading from the beginning of the file. -#initial_position = start_of_file -# -## Encoding of file -#encoding = utf-8 # Other supported encodings include: ascii, latin-1 -# -# -# -# Following table documents the detailed datetime format specification: -# ---------------------------------------------------------------------------------------------------------------------- -# Directive Meaning Example -# ---------------------------------------------------------------------------------------------------------------------- -# %a Weekday as locale's abbreviated name. Sun, Mon, ..., Sat (en_US) -# ---------------------------------------------------------------------------------------------------------------------- -# %A Weekday as locale's full name. Sunday, Monday, ..., Saturday (en_US) -# ---------------------------------------------------------------------------------------------------------------------- -# %w Weekday as a decimal number, where 0 is Sunday and 6 is Saturday. 0, 1, ..., 6 -# ---------------------------------------------------------------------------------------------------------------------- -# %d Day of the month as a zero-padded decimal numbers. 01, 02, ..., 31 -# ---------------------------------------------------------------------------------------------------------------------- -# %b Month as locale's abbreviated name. Jan, Feb, ..., Dec (en_US) -# ---------------------------------------------------------------------------------------------------------------------- -# %B Month as locale's full name. January, February, ..., December (en_US) -# ---------------------------------------------------------------------------------------------------------------------- -# %m Month as a zero-padded decimal number. 01, 02, ..., 12 -# ---------------------------------------------------------------------------------------------------------------------- -# %y Year without century as a zero-padded decimal number. 00, 01, ..., 99 -# ---------------------------------------------------------------------------------------------------------------------- -# %Y Year with century as a decimal number. 1970, 1988, 2001, 2013 -# ---------------------------------------------------------------------------------------------------------------------- -# %H Hour (24-hour clock) as a zero-padded decimal number. 00, 01, ..., 23 -# ---------------------------------------------------------------------------------------------------------------------- -# %I Hour (12-hour clock) as a zero-padded decimal numbers. 01, 02, ..., 12 -# ---------------------------------------------------------------------------------------------------------------------- -# %p Locale's equivalent of either AM or PM. AM, PM (en_US) -# ---------------------------------------------------------------------------------------------------------------------- -# %M Minute as a zero-padded decimal number. 00, 01, ..., 59 -# ---------------------------------------------------------------------------------------------------------------------- -# %S Second as a zero-padded decimal numbers. 00, 01, ..., 59 -# ---------------------------------------------------------------------------------------------------------------------- -# %f Microsecond as a decimal number, zero-padded on the left. 000000, 000001, ..., 999999 -# ---------------------------------------------------------------------------------------------------------------------- -# %z UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive). (empty), +0000, -0400, +1030 -# ---------------------------------------------------------------------------------------------------------------------- -# %j Day of the year as a zero-padded decimal number. 001, 002, ..., 365 -# ---------------------------------------------------------------------------------------------------------------------- -# %U Week number of the year (Sunday as the first day of the week) as a zero padded 00, 01, ..., 53 -# decimal number. All days in a new year preceding the first Sunday are considered -# to be in week 0. -# ---------------------------------------------------------------------------------------------------------------------- -# %W Week number of the year (Monday as the first day of the week) as a decimal number. 00, 01, ..., 53 -# All days in a new year preceding the first Monday are considered to be in week 0. -# ---------------------------------------------------------------------------------------------------------------------- -# %c Locale's appropriate date and time representation. Tue Aug 16 21:30:00 1988 (en_US) -# ---------------------------------------------------------------------------------------------------------------------- - - -# [/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 - diff --git a/eu-west-1/run-services.sh b/eu-west-1/run-services.sh deleted file mode 100644 index 740889c..0000000 --- a/eu-west-1/run-services.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh - -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"} - -cp -f /awslogs.conf.dummy /var/awslogs/etc/awslogs.conf - -cat >> /var/awslogs/etc/awslogs.conf <> /var/awslogs/etc/awslogs.conf < /var/awslogs/etc/aws.conf < /root/.aws/credentials <