-
Notifications
You must be signed in to change notification settings - Fork 619
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
Windows service #1070
Windows service #1070
Changes from all commits
2954177
6eadfe7
c3d7f6c
d3d57cd
2f7dc6d
b87ab7e
4aea88d
903ec56
9ce866b
d8c4796
d83b49a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,26 +48,68 @@ See also the Advanced Usage section below. | |
|
||
### On Windows Server 2016 | ||
|
||
On Windows Server 2016, the Amazon ECS Container Agent runs as a process on the | ||
host. Unlike Linux, the agent may not run inside a container as it uses the | ||
host's registry and the named pipe at `\\.\pipe\docker_engine` to communicate | ||
with the Docker daemon. | ||
On Windows Server 2016, the Amazon ECS Container Agent runs as a process or | ||
service on the host. Unlike Linux, the agent may not run inside a container as | ||
it uses the host's registry and the named pipe at `\\.\pipe\docker_engine` to | ||
communicate with the Docker daemon. | ||
|
||
#### As a Service | ||
To install the service, you can do the following: | ||
|
||
```powershell | ||
PS C:\> # Set up directories the agent uses | ||
PS C:\> New-Item -Type directory -Path ${env:ProgramFiles}\Amazon\ECS -Force | ||
PS C:\> New-Item -Type directory -Path ${env:ProgramData}\Amazon\ECS -Force | ||
PS C:\> # Set up configuration | ||
PS C:\> $ecsExeDir = "${env:ProgramFiles}\Amazon\ECS" | ||
PS C:\> [Environment]::SetEnvironmentVariable("ECS_CLUSTER", "my-windows-cluster", "Machine") | ||
PS C:\> [Environment]::SetEnvironmentVariable("ECS_LOGFILE", "${env:ProgramData}\Amazon\ECS\log\ecs-agent.log", "Machine") | ||
PS C:\> [Environment]::SetEnvironmentVariable("ECS_DATADIR", "${env:ProgramData}\Amazon\ECS\data", "Machine") | ||
PS C:\> # Download the agent | ||
PS C:\> $agentVersion = "latest" | ||
PS C:\> $agentZipUri = "https://s3.amazonaws.com/amazon-ecs-agent/ecs-agent-windows-$agentVersion.zip" | ||
PS C:\> $zipFile = "${env:TEMP}\ecs-agent.zip" | ||
PS C:\> Invoke-RestMethod -OutFile $zipFile -Uri $agentZipUri | ||
PS C:\> # Put the executables in the executable directory. | ||
PS C:\> Expand-Archive -Path $zipFile -DestinationPath $ecsExeDir -Force | ||
PS C:\> Set-Location ${ecsExeDir} | ||
PS C:\> # Set $EnableTaskIAMRoles to $true to enable task IAM roles | ||
PS C:\> # Note that enabling IAM roles will make port 80 unavailable for tasks. | ||
PS C:\> [bool]$EnableTaskIAMRoles = $false | ||
PS C:\> if (${EnableTaskIAMRoles} { | ||
>> .\hostsetup.ps1 | ||
>> } | ||
PS C:\> # Install the agent service | ||
PS C:\> New-Service -Name "AmazonECS" ` | ||
-BinaryPathName "$ecsExeDir\amazon-ecs-agent.exe -windows-service" ` | ||
-DisplayName "Amazon ECS" ` | ||
-Description "Amazon ECS service runs the Amazon ECS agent" ` | ||
-DependsOn Docker ` | ||
-StartupType Manual | ||
``` | ||
|
||
To run the service, you can do the following: | ||
```powershell | ||
Start-Service AmazonECS | ||
``` | ||
|
||
#### As a Process | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to continue to support this? Whats the thought here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'd like to continue documenting this at least until we vend an easier way to install the agent. |
||
|
||
```powershell | ||
PS C:\> # Set up directories the agent uses | ||
PS C:\> New-Item -Type directory -Path $ProgramFiles\Amazon\ECS | ||
PS C:\> New-Item -Type directory -Path $ProgramData\Amazon\ECS | ||
PS C:\> New-Item -Type directory -Path ${env:ProgramFiles}\Amazon\ECS -Force | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Even thought it's case insensitive, powershell docs capitalize Env There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to leave this as-is for now; we can come back and fix it later. |
||
PS C:\> New-Item -Type directory -Path ${env:ProgramData}\Amazon\ECS -Force | ||
PS C:\> # Set up configuration | ||
PS C:\> $ecsExeDir = "$env:ProgramFiles\Amazon\ECS" | ||
PS C:\> $ecsExeDir = "${env:ProgramFiles}\Amazon\ECS" | ||
PS C:\> [Environment]::SetEnvironmentVariable("ECS_CLUSTER", "my-windows-cluster", "Machine") | ||
PS C:\> [Environment]::SetEnvironmentVariable("ECS_LOGFILE", "$ProgramData\Amazon\ECS\log\ecs-agent.log", "Machine") | ||
PS C:\> [Environment]::SetEnvironmentVariable("ECS_DATADIR", "$ProgramData\Amazon\ECS\data", "Machine") | ||
PS C:\> [Environment]::SetEnvironmentVariable("ECS_LOGFILE", "${env:ProgramData}\Amazon\ECS\log\ecs-agent.log", "Machine") | ||
PS C:\> [Environment]::SetEnvironmentVariable("ECS_DATADIR", "${env:ProgramData}\Amazon\ECS\data", "Machine") | ||
PS C:\> # Set this environment variable to "true" to enable IAM roles. Note that enabling IAM roles will make port 80 unavailable for tasks. | ||
PS C:\> [Environment]::SetEnvironmentVariable("ECS_ENABLE_TASK_IAM_ROLE", "false", "Machine") | ||
PS C:\> # Download the agent | ||
PS C:\> $agentVersion = "latest" | ||
PS C:\> $agentZipUri = "https://s3.amazonaws.com/amazon-ecs-agent/ecs-agent-windows-$agentVersion.zip" | ||
PS C:\> $zipFile = "$env:TEMP\ecs-agent.zip" | ||
PS C:\> $zipFile = "${env:TEMP}\ecs-agent.zip" | ||
PS C:\> Invoke-RestMethod -OutFile $zipFile -Uri $agentZipUri | ||
PS C:\> # Put the executables in the executable directory. | ||
PS C:\> Expand-Archive -Path $zipFile -DestinationPath $ecsExeDir -Force | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,9 +46,9 @@ import ( | |
"github.com/aws/amazon-ecs-agent/agent/utils" | ||
"github.com/aws/amazon-ecs-agent/agent/version" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
aws_credentials "github.com/aws/aws-sdk-go/aws/credentials" | ||
"github.com/aws/aws-sdk-go/aws/defaults" | ||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/cihub/seelog" | ||
) | ||
|
||
|
@@ -76,8 +76,12 @@ type agent interface { | |
// printECSAttributes prints the Agent's capabilities based on | ||
// its environment | ||
printECSAttributes() int | ||
// startWindowsService starts the agent as a Windows Service | ||
startWindowsService() int | ||
// start starts the Agent execution | ||
start() int | ||
// setTerminationHandler sets the termination handler | ||
setTerminationHandler(sighandlers.TerminationHandler) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. neat! |
||
} | ||
|
||
// ecsAgent wraps all the entities needed to start the ECS Agent execution. | ||
|
@@ -100,9 +104,10 @@ type ecsAgent struct { | |
mac string | ||
metadataManager containermetadata.Manager | ||
resource resources.Resource | ||
terminationHandler sighandlers.TerminationHandler | ||
} | ||
|
||
// newAgent returns a new ecsAgent object | ||
// newAgent returns a new ecsAgent object, but does not start anything | ||
func newAgent( | ||
ctx context.Context, | ||
blackholeEC2Metadata bool, | ||
|
@@ -158,9 +163,10 @@ func newAgent( | |
PluginsPath: cfg.CNIPluginsPath, | ||
MinSupportedCNIVersion: config.DefaultMinSupportedCNIVersion, | ||
}), | ||
os: oswrapper.New(), | ||
metadataManager: metadataManager, | ||
resource: resources.New(), | ||
os: oswrapper.New(), | ||
metadataManager: metadataManager, | ||
resource: resources.New(), | ||
terminationHandler: sighandlers.StartDefaultTerminationHandler, | ||
}, nil | ||
} | ||
|
||
|
@@ -184,6 +190,10 @@ func (agent *ecsAgent) printECSAttributes() int { | |
return exitcodes.ExitSuccess | ||
} | ||
|
||
func (agent *ecsAgent) setTerminationHandler(handler sighandlers.TerminationHandler) { | ||
agent.terminationHandler = handler | ||
} | ||
|
||
// start starts the ECS Agent | ||
func (agent *ecsAgent) start() int { | ||
sighandlers.StartDebugHandler() | ||
|
@@ -514,7 +524,7 @@ func (agent *ecsAgent) startAsyncRoutines( | |
go imageManager.StartImageCleanupProcess(agent.ctx) | ||
} | ||
|
||
go sighandlers.StartTerminationHandler(stateManager, taskEngine) | ||
go agent.terminationHandler(stateManager, taskEngine) | ||
|
||
// Agent introspection api | ||
go handlers.ServeHttp(&agent.containerInstanceARN, taskEngine, agent.cfg) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it confusing the call the ECS Agent service "AmazonECS"? This is the agent. Would it be better to call it "AmazonECSAgent"?
Sorry if this topic came up before, feel free to ignore & point me to any existing discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I named it "AmazonECS" so that we'd have the flexibility to swap out a bit in terms of implementation without requiring customers to change the name that they're using or making the name confusing. Specifically, this enables us to potentially transition to running the agent inside a container and using a service on the host to manage the container (similar to what we do with ecs-init on Linux). If we called it "AmazonECSAgent", we could still do that but it could create confusion because the service is separate from the agent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AmazonECSService?