Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of disable-debug mode to ECS Logs Collector #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The following functions are supported:
* Collect Docker logs
* Collect Amazon ECS agent Logs
* Enable debug mode for Docker and the Amazon ECS agent (only available for Systemd init systems and Amazon Linux)
* Disable debug mode for Docker and the Amazon ECS agent (only available for Systemd init systems and Amazon Linux)
* Create a tar zip file in the same folder as the script

## Usage
Expand All @@ -33,11 +34,11 @@ i-ffffffffffffffffff
Download the tarball using your favourite Secure Copy tool.

## Example output
The project can be used in normal or enable-debug mode. Enable debug is only available for Systemd init systems and Amazon Linux.
The project can be used in normal, enable-debug or disable-debug mode. Enable & Disable debug is only available for Systemd init systems and Amazon Linux.

```
# bash ecs-logs-collector.sh --help
USAGE: ./ecs-logs-collector.sh [--mode=[brief|enable-debug]]
USAGE: ./ecs-logs-collector.sh [--mode=[brief|enable-debug|disable-debug]]
./ecs-logs-collector.sh --help

OPTIONS:
Expand All @@ -51,6 +52,8 @@ MODES:
enable-debug Enables debug mode for the Docker daemon and the Amazon
ECS Container Agent. Only supported on Systemd init systems
and Amazon Linux.
disable-debug Disables debug mode for the Docker daemon and the Amazon
ECS Container Agent. reverse of enable-debug option.
```

### Example output in normal mode
Expand Down Expand Up @@ -104,6 +107,20 @@ Trying to enable debug mode for the Amazon ECS Container Agent ... ok
Trying to restart the Amazon ECS Container Agent to enable debug mode ... ok
```

### Example output in disable-debug mode
The following output shows this project disabling debug mode for the Docker daemon and the Amazon ECS Container Agent. This mode only works on Amazon Linux OS and Systemd init systems such as RHEL 7 and Ubuntu 16.04. Note that disable-debug mode restarts Docker and the Amazon ECS agent.

```
# bash ecs-logs-collector.sh --mode=disable-debug
Trying to check if the script is running as root ... ok
Trying to collect system information ... ok
Trying to disable debug mode for the Docker daemon ... ok
Trying to restart Docker daemon to enable debug mode ... ok
Trying to disable debug mode for the Amazon ECS Container Agent ... ok
Trying to restart the Amazon ECS Container Agent to disable debug mode ... ok
Trying to restart the Amazon ECS Container Agent to disable debug mode ... ok
```

## Contributing

Please [create a new GitHub issue](https://github.com/awslabs/ecs-logs-collector/issues/new) for any feature requests, bugs, or documentation improvements.
Expand Down
88 changes: 87 additions & 1 deletion ecs-logs-collector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mode='brief' # defined in parse_options
# ---------------------------------------------------------------------------------------

help() {
echo "USAGE: ${progname} [--mode=[brief|enable-debug]]"
echo "USAGE: ${progname} [--mode=[brief|enable-debug|disable-debug]]"
echo " ${progname} --help"
echo ""
echo "OPTIONS:"
Expand All @@ -77,6 +77,8 @@ help() {
echo " enable-debug Enables debug mode for the Docker daemon and the Amazon"
echo " ECS Container Agent. Only supported on Systemd init systems"
echo " and Amazon Linux."
echo " disable-debug Disables debug mode for the Docker daemon and the Amazon"
echo " ECS Container Agent. reverse of enable-debug option."
}

parse_options() {
Expand Down Expand Up @@ -193,6 +195,13 @@ enable_debug() {
enable_ecs_agent_debug
}

disable_debug() {
is_root
get_init_type
disable_docker_debug
disable_ecs_agent_debug
}

# Routines
# ---------------------------------------------------------------------------------------

Expand Down Expand Up @@ -797,6 +806,80 @@ enable_ecs_agent_debug() {
fi
}

disable_docker_debug() {
try "disable debug mode for the Docker daemon"

if [ -e /etc/sysconfig/docker ] && ! grep -q "^\\s*OPTIONS=\"-D" /etc/sysconfig/docker; then
info "Debug mode is already disabled."
else

if [ -e /etc/sysconfig/docker ]; then
case "${init_type}" in
systemd)
# sed -i 's/^OPTIONS="\(.*\)/OPTIONS="-D \1/g' /etc/sysconfig/docker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: lets remove this comment and L828

sed -i 's/\-D//g' /etc/sysconfig/docker
ok
Comment on lines +820 to +821
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be common to both cases (systemd and *). can we move this to be before the case and remove it here and L829 below?


try "restart Docker daemon to enable debug mode"
systemctl restart docker.service
ok
;;
*)
# echo "OPTIONS=\"-D \$OPTIONS\"" >> /etc/sysconfig/docker
sed -i 's/\-D//g' /etc/sysconfig/docker

try "restart Docker daemon to enable debug mode"
service docker restart
ok

esac

else
warning "the current operating system is not supported."
fi
fi
}

disable_ecs_agent_debug() {
try "disable debug mode for the Amazon ECS Container Agent"

if [ -e /etc/ecs/ecs.config ] && ! grep -q "^\\s*ECS_LOGLEVEL=debug" /etc/ecs/ecs.config; then
info "Debug mode is already disabled."

else
case "${init_type}" in
systemd)
if [ ! -d /etc/ecs ]; then
mkdir /etc/ecs
fi
Comment on lines +852 to +854
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if /etc/ecs doesn't exist then they don't have the ECS_LOGLEVEL=debug set in the config. wonder why we want to create the dir here ?


sed -i '/^\s*ECS_LOGLEVEL=debug/d' /etc/ecs/ecs.config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sets the log level to debug, instead of unsetting it or setting it back to info

ok

try "restart the Amazon ECS Container Agent to disable debug mode"
systemctl restart ecs
ok
;;
*)
if rpm -q --quiet ecs-init; then
if [ ! -d /etc/ecs ]; then
mkdir /etc/ecs
fi

sed -i '/^\s*ECS_LOGLEVEL=debug/d' /etc/ecs/ecs.config
ok

try "restart the Amazon ECS Container Agent to disable debug mode"
stop ecs; start ecs
ok
else
warning "the current operating system is not supported."
fi
;;
esac
fi
}

# nvidia-smi is a tool available on GPU based AMIs provides detailed
# information about the GPU present on the VM.
get_gpu_info() {
Expand Down Expand Up @@ -832,6 +915,9 @@ case "${mode}" in
enable-debug)
enable_debug
;;
disable-debug)
disable_debug
;;
*)
help && exit 1
;;
Expand Down