Last active
January 22, 2018 18:25
-
-
Save bushong1/efa540e47e61d257e09da72c4c0b04a2 to your computer and use it in GitHub Desktop.
A gist to run a dockerize papertrail container for reporting ECS container logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parameters: | |
PapertrailEndpoint: | |
Type: String | |
Default: logsX.papertrailapp.com:XXXXX | |
Resources: | |
LaunchConfig: | |
Properties: | |
... | |
UserData: | |
Fn::Base64: !Sub | | |
#!/bin/bash -xe | |
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 | |
... | |
# Write ECS Agent systemd unit file | |
## See: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/example_user_data_scripts.html | |
# Write Papertrail/logspout systemd unit file | |
# Requires: an existing "docker" service registered with systemd | |
cat << EOF > /etc/systemd/system/[email protected] | |
[Unit] | |
Description=Docker Container Logspout %I | |
Requires=docker.service | |
After=docker.service | |
[Service] | |
Restart=always | |
StartLimitInterval=0 | |
ExecStartPre=-/usr/bin/docker rm -f %i | |
ExecStart=/usr/bin/docker run --name %i \ | |
--privileged \ | |
--restart=on-failure:10 \ | |
--log-driver json-file --log-opt max-size=10m \ | |
--volume=/var/run/docker.sock:/var/run/docker.sock \ | |
gliderlabs/logspout:latest \ | |
"syslog+tls://${PapertrailEndpoint}" | |
ExecStop=/usr/bin/docker stop %i | |
[Install] | |
WantedBy=default.target | |
EOF | |
## Enable docker service; ensure restart on failure | |
### See: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/example_user_data_scripts.html | |
### Additionally, consider the following to ensure process restart: | |
# sed -i 's/^Restart=.*/Restart=always/' /usr/lib/systemd/system/docker.service | |
# sed -i 's/^StartLimitInterval=.*/StartLimitInterval=0/' /usr/lib/systemd/system/docker.service | |
# systemctl daemon-reload | |
# systemctl enable docker | |
# systemctl start docker | |
# Enable/start Papertrail/logspout systemd service | |
systemctl enable [email protected] | |
systemctl start [email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment