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

Support Dockerfile HEALTHCHECK of agent #2260

Merged
merged 1 commit into from
Nov 7, 2019
Merged
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
5 changes: 5 additions & 0 deletions agent/app/args/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
licenseUsage = "Print the LICENSE and NOTICE files and exit"
blacholeEC2MetadataUsage = "Blackhole the EC2 Metadata requests. Setting this option can cause the ECS Agent to fail to work properly. We do not recommend setting this option"
windowsServiceUsage = "Run the ECS agent as a Windows Service"
healthcheckServiceUsage = "Run the agent healthcheck"

versionFlagName = "version"
logLevelFlagName = "loglevel"
Expand All @@ -31,6 +32,7 @@ const (
licenseFlagName = "license"
blackholeEC2MetadataFlagName = "blackhole-ec2-metadata"
windowsServiceFlagName = "windows-service"
healthCheckFlagName = "healthcheck"
)

// Args wraps various ECS Agent arguments
Expand All @@ -51,6 +53,8 @@ type Args struct {
ECSAttributes *bool
// WindowsService indicates that the agent should run as a Windows service
WindowsService *bool
// Healthcheck indicates that agent should run healthcheck
Healthcheck *bool
}

// New creates a new Args object from the argument list
Expand All @@ -65,6 +69,7 @@ func New(arguments []string) (*Args, error) {
BlackholeEC2Metadata: flagset.Bool(blackholeEC2MetadataFlagName, false, blacholeEC2MetadataUsage),
ECSAttributes: flagset.Bool(ecsAttributesFlagName, false, ecsAttributesUsage),
WindowsService: flagset.Bool(windowsServiceFlagName, false, windowsServiceUsage),
Healthcheck: flagset.Bool(healthCheckFlagName, false, healthcheckServiceUsage),
}

err := flagset.Parse(arguments)
Expand Down
31 changes: 31 additions & 0 deletions agent/app/healthcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package app

import (
"net/http"

"github.com/aws/amazon-ecs-agent/agent/sighandlers/exitcodes"
"github.com/cihub/seelog"
)

// runHealthcheck runs the Agent's healthcheck
func runHealthcheck() int {
_, err := http.Get("http://localhost:51678/v1/metadata")
if err != nil {
seelog.Warnf("Health check failed with error: %v", err)
return exitcodes.ExitError
}
return exitcodes.ExitSuccess
}
2 changes: 2 additions & 0 deletions agent/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func Run(arguments []string) int {
return printLicense()
} else if *parsedArgs.Version {
return version.PrintVersion()
} else if *parsedArgs.Healthcheck {
return runHealthcheck()
}

logger.SetLevel(*parsedArgs.LogLevel)
Expand Down
3 changes: 3 additions & 0 deletions scripts/dockerfiles/Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ COPY out/cni-plugins /amazon-ecs-cni-plugins
COPY misc/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

EXPOSE 51678 51679

HEALTHCHECK CMD ["/agent", "--healthcheck"]

ENTRYPOINT ["/agent"]