aws-ec2 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/aws_ec2/cli.rb +1 -1
- data/lib/aws_ec2/scripts/cloudwatch.sh +5 -3
- data/lib/aws_ec2/scripts/cloudwatch/install.sh +1 -2
- data/lib/aws_ec2/scripts/cloudwatch/install/amazonlinux2.sh +4 -0
- data/lib/aws_ec2/scripts/cloudwatch/install/ubuntu.sh +29 -0
- data/lib/aws_ec2/scripts/cloudwatch/service.sh +2 -18
- data/lib/aws_ec2/scripts/cloudwatch/service/amazonlinux2.sh +8 -0
- data/lib/aws_ec2/scripts/cloudwatch/service/ubuntu.sh +10 -0
- data/lib/aws_ec2/scripts/shared/functions.sh +56 -22
- data/lib/aws_ec2/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb267f8cd533d910838799ca725bfb8e792d5c5c09d5214a42dc61f123178507
|
4
|
+
data.tar.gz: ea088020fa9c7fb16933d60bcc598a1cbe2870038c533a1dda9a5ff21c465603
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d31388fb4b6d63789f39b0afce19705aa0fe8b8bf2a7d2b670a7b804278649aaabc28bc149dcabef5231d5d8eaeffd0d2300877c28524cf4057ff6f41594ab1
|
7
|
+
data.tar.gz: 157911b5ab7ea840093bcf3b742de32e6497440e17ca66cfea762d52747297c116acdba140ca259adf42f3a231eb01f2d9c91de8ad57910451e5e1d814f95b39
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [1.4.0]
|
7
|
+
- Merge pull request #8 from tongueroo/cloudwatch
|
8
|
+
- cloudwatch support for amazonlinux2 and ubuntu
|
9
|
+
|
6
10
|
## [1.3.2]
|
7
11
|
- add noop mode for clean ami command
|
8
12
|
|
data/lib/aws_ec2/cli.rb
CHANGED
@@ -13,7 +13,7 @@ module AwsEc2
|
|
13
13
|
|
14
14
|
common_options = Proc.new do
|
15
15
|
option :auto_terminate, type: :boolean, default: false, desc: "automatically terminate the instance at the end of user-data"
|
16
|
-
option :cloudwatch, type: :boolean, default: false, desc: "enable cloudwatch logging,
|
16
|
+
option :cloudwatch, type: :boolean, default: false, desc: "enable cloudwatch logging, supported for amazonlinux2 and ubuntu"
|
17
17
|
end
|
18
18
|
|
19
19
|
desc "create NAME", "create ec2 instance"
|
@@ -10,13 +10,15 @@ if [ $# -eq 0 ]; then
|
|
10
10
|
fi
|
11
11
|
LOG_GROUP_NAME=$1
|
12
12
|
|
13
|
+
# shellcheck disable=SC1091
|
13
14
|
source "/opt/aws-ec2/shared/functions.sh"
|
14
|
-
|
15
|
-
if [ "$
|
16
|
-
echo "Sorry, enable cloudwatch logging with the aws-ec2 tool is only supported for amazonlinux2
|
15
|
+
OS=$(os_name)
|
16
|
+
if [ "$OS" != "amazonlinux2" ] || [ "$OS" != "ubuntu" ] ; then
|
17
|
+
echo "Sorry, enable cloudwatch logging with the aws-ec2 tool is only supported for amazonlinux2 and ubuntu"
|
17
18
|
exit
|
18
19
|
fi
|
19
20
|
|
21
|
+
export OS # used by the scripts to delegate to the right OS script
|
20
22
|
/opt/aws-ec2/cloudwatch/install.sh
|
21
23
|
/opt/aws-ec2/cloudwatch/configure.sh "$LOG_GROUP_NAME"
|
22
24
|
/opt/aws-ec2/cloudwatch/service.sh
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/bin/bash -eux
|
2
|
+
|
3
|
+
# https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/QuickStartEC2Instance.html
|
4
|
+
|
5
|
+
REGION=$(curl -s 169.254.169.254/latest/meta-data/placement/availability-zone | sed s'/.$//')
|
6
|
+
|
7
|
+
type python || apt-get install -y python-pip
|
8
|
+
|
9
|
+
# Install awslogs and the jq JSON parser
|
10
|
+
curl -s https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -O
|
11
|
+
|
12
|
+
# in order to install awslogs non-interactively we need a filler configfile
|
13
|
+
mkdir -p /etc/awslogs
|
14
|
+
cat > /etc/awslogs/awslogs.conf <<- EOL
|
15
|
+
[general]
|
16
|
+
state_file = /var/awslogs/state/agent-state
|
17
|
+
## filler config file, will get replaced by configure.sh script
|
18
|
+
EOL
|
19
|
+
|
20
|
+
# yum install -y awslogs jq also creates this file. We're creating it so that
|
21
|
+
# configure.sh is consistent.
|
22
|
+
cat > /etc/awslogs/awscli.conf <<- EOL
|
23
|
+
[plugins]
|
24
|
+
cwlogs = cwlogs
|
25
|
+
[default]
|
26
|
+
region = us-west-2
|
27
|
+
EOL
|
28
|
+
|
29
|
+
python ./awslogs-agent-setup.py --region "$REGION" --non-interactive --configfile=/etc/awslogs/awslogs.conf
|
@@ -1,19 +1,3 @@
|
|
1
|
-
|
2
|
-
#upstart-job
|
3
|
-
description "Configure and start CloudWatch Logs agent EC2 instance"
|
4
|
-
author "Tung Nguyen"
|
5
|
-
start on startup
|
1
|
+
#!/bin/bash -eux
|
6
2
|
|
7
|
-
|
8
|
-
exec 2>>/var/log/cloudwatch-logs-start.log
|
9
|
-
set -x
|
10
|
-
|
11
|
-
service awslogs start
|
12
|
-
chkconfig awslogs on
|
13
|
-
end script
|
14
|
-
EOL
|
15
|
-
|
16
|
-
initctl list
|
17
|
-
initctl reload-configuration
|
18
|
-
initctl start awslogs
|
19
|
-
initctl list
|
3
|
+
/opt/aws-ec2/cloudwatch/service/"$OS".sh
|
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/bin/bash -exu
|
2
|
+
|
3
|
+
# yum install already has configured
|
4
|
+
# /usr/lib/systemd/system/awslogsd.service
|
5
|
+
# Restart because we adjust the config with configure.sh
|
6
|
+
systemctl daemon-reload
|
7
|
+
systemctl restart awslogsd # with the yum awslogs package the systemd is called awslogsd
|
8
|
+
# systemctl status awslogsd
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#/bin/bash -exu
|
2
|
+
|
3
|
+
# Interestingly, the awslogs-agent-setup.py command in the install.sh script
|
4
|
+
# already sets up systemd.
|
5
|
+
# With the yum awslogs-agent-setup.py setup, the systemd is called awslogs
|
6
|
+
|
7
|
+
# We just have to reload and restart it since we reconfigured it
|
8
|
+
systemctl daemon-reload
|
9
|
+
systemctl restart awslogs
|
10
|
+
# systemctl status awslogs
|
@@ -16,29 +16,63 @@ CONFIGURE_AWS_CLI
|
|
16
16
|
fi
|
17
17
|
}
|
18
18
|
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
19
|
+
# Normalize os name so we can delegate out to os specific scripts.
|
20
|
+
#
|
21
|
+
# Amazon Linux 2
|
22
|
+
# $ cat /etc/os-release
|
23
|
+
# NAME="Amazon Linux"
|
24
|
+
# VERSION="2 (2017.12)"
|
25
|
+
# ID="amzn"
|
26
|
+
# ID_LIKE="centos rhel fedora"
|
27
|
+
# VERSION_ID="2"
|
28
|
+
# PRETTY_NAME="Amazon Linux 2 (2017.12) LTS Release Candidate"
|
29
|
+
# ANSI_COLOR="0;33"
|
30
|
+
# CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
|
31
|
+
# HOME_URL="https://amazonlinux.com/"
|
32
|
+
#
|
33
|
+
# Ubuntu
|
34
|
+
# ubuntu@ip-172-31-6-8:~$ cat /etc/os-release
|
35
|
+
# NAME="Ubuntu"
|
36
|
+
# VERSION="16.04.3 LTS (Xenial Xerus)"
|
37
|
+
# ID=ubuntu
|
38
|
+
# ID_LIKE=debian
|
39
|
+
# PRETTY_NAME="Ubuntu 16.04.3 LTS"
|
40
|
+
# VERSION_ID="16.04"
|
41
|
+
# HOME_URL="http://www.ubuntu.com/"
|
42
|
+
# SUPPORT_URL="http://help.ubuntu.com/"
|
43
|
+
# BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
|
44
|
+
# VERSION_CODENAME=xenial
|
45
|
+
# UBUNTU_CODENAME=xenial
|
46
|
+
#
|
47
|
+
# Note: Amazon Linux and Amazon Linux 2 have the same name
|
48
|
+
#
|
22
49
|
function os_name() {
|
23
|
-
# https://askubuntu.com/questions/459402/how-to-know-if-the-running-platform-is-ubuntu-or-centos-with-help-of-a-bash-scri
|
24
|
-
# Method 1 works for amazonlinux2 and ubuntu
|
25
|
-
# Method 3 the complex script, did not work for amazonlinux2
|
26
50
|
local OS
|
27
|
-
|
28
|
-
# strip surrounding quotes: https://stackoverflow.com/questions/9733338/shell-script-remove-first-and-last-quote-from-a-variable
|
29
|
-
OS="${OS%\"}"
|
30
|
-
OS="${OS#\"}"
|
31
|
-
# Example OS values at this point:
|
32
|
-
# Ubuntu
|
33
|
-
# Amazon Linux AMI
|
51
|
+
local VERSION
|
34
52
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
53
|
+
if [[ "$OSTYPE" == "darwin"* ]]; then
|
54
|
+
OS="macosx" # gawk not available on macosx usually
|
55
|
+
else
|
56
|
+
# https://askubuntu.com/questions/459402/how-to-know-if-the-running-platform-is-ubuntu-or-centos-with-help-of-a-bash-scri
|
57
|
+
# Method 1 works for amazonlinux and ubuntu
|
58
|
+
# Method 3 the complex script, did not work for amazonlinux
|
59
|
+
OS=$(gawk -F= '/^NAME/{print $2}' /etc/os-release)
|
60
|
+
fi
|
61
|
+
|
62
|
+
OS="${OS// /}" # remove spaces
|
63
|
+
OS=$(echo "$OS" | tr '[:upper:]' '[:lower:]')
|
64
|
+
# https://stackoverflow.com/questions/9733338/shell-script-remove-first-and-last-quote-from-a-variable
|
65
|
+
OS="${OS#\"}" # remove leading "
|
66
|
+
OS="${OS%\"}" # remove trailing "
|
67
|
+
|
68
|
+
if [ "$OS" == "amazonlinux" ]; then
|
69
|
+
VERSION=$(gawk -F= '/^VERSION/{print $2}' /etc/os-release)
|
70
|
+
VERSION="${VERSION#\"}" # remove leading "
|
71
|
+
if [[ "$VERSION" =~ ^2 ]] ; then
|
72
|
+
OS="${OS}2"
|
73
|
+
fi
|
74
|
+
fi
|
75
|
+
|
76
|
+
echo "$OS"
|
44
77
|
}
|
78
|
+
OS=$(normalize_os)
|
data/lib/aws_ec2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-ec2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -296,7 +296,11 @@ files:
|
|
296
296
|
- lib/aws_ec2/scripts/cloudwatch.sh
|
297
297
|
- lib/aws_ec2/scripts/cloudwatch/configure.sh
|
298
298
|
- lib/aws_ec2/scripts/cloudwatch/install.sh
|
299
|
+
- lib/aws_ec2/scripts/cloudwatch/install/amazonlinux2.sh
|
300
|
+
- lib/aws_ec2/scripts/cloudwatch/install/ubuntu.sh
|
299
301
|
- lib/aws_ec2/scripts/cloudwatch/service.sh
|
302
|
+
- lib/aws_ec2/scripts/cloudwatch/service/amazonlinux2.sh
|
303
|
+
- lib/aws_ec2/scripts/cloudwatch/service/ubuntu.sh
|
300
304
|
- lib/aws_ec2/scripts/shared/functions.sh
|
301
305
|
- lib/aws_ec2/setting.rb
|
302
306
|
- lib/aws_ec2/template.rb
|