Restarting ECS Containers
This guide explains how to manually restart containers in AWS ECS (Elastic Container Service) for the CNF Odoo application.
When to Restart Containers
You may need to restart ECS containers in the following situations: - Application is unresponsive or experiencing issues - After deploying new code that requires a fresh container - Memory leaks or performance degradation - Configuration changes that require a restart
Prerequisites
- Access to AWS Console with appropriate ECS permissions
- Knowledge of which ECS cluster and service you need to restart
Step-by-Step Process
1. Access the ECS Console
- Open AWS Console: Navigate to AWS Console
- Find ECS Service:
- Search for "ECS" in the services search bar
- Click on "Elastic Container Service"
2. Navigate to Your Cluster
- Select Clusters: In the ECS dashboard, click on "Clusters" in the left sidebar
- Choose Your Cluster: Click on the cluster name
Odoo_ECS_Clusterwhere your CNF Odoo application is running
3. Locate the Service
- Services Tab: In the cluster overview, click on the "Services" tab
- Find Your Service: Locate the service
odoo-httprunning your Odoo application - Click Service Name: Click on the
odoo-httpservice name to open the service details
4. Access Running Tasks
- Tasks Tab: In the service details page, click on the "Tasks" tab
- View Running Tasks: You'll see a list of currently running tasks
- Tasks show status (RUNNING, PENDING, STOPPED)
- Each task has a unique Task ID
5. Stop the Running Task
- Select Task: Click on the Task ID of the running task you want to restart
- Stop Task:
- Click the "Stop" button at the top of the task details page
- Confirm the action when prompted
- Confirm Shutdown: The task status will change to "STOPPING" then "STOPPED"
6. Wait for New Task to Start
- Automatic Replacement: ECS will automatically start a new task to replace the stopped one
- Monitor Progress:
- Return to the service's Tasks tab
- Watch for a new task to appear with "PENDING" status
- The status will progress: PENDING → PROVISIONING → RUNNING
- Verify Health: Once the new task shows "RUNNING" status, verify the application is accessible
Important Notes
Service Configuration
- Desired Count: ECS maintains the desired number of running tasks
- Auto-replacement: When you stop a task, ECS automatically starts a replacement
- Rolling Updates: This process ensures zero-downtime restarts
Monitoring During Restart
- Task Startup Time: New tasks typically take 2-5 minutes to fully start
- Health Checks: ECS performs health checks before marking tasks as healthy
- Load Balancer: If using a load balancer, it will route traffic away from stopping tasks
Troubleshooting
If the new task fails to start:
- Check Task Definition: Ensure the task definition is valid
- Review Logs: Check CloudWatch logs for startup errors
- Resource Limits: Verify CPU/memory limits are appropriate
- Network Configuration: Ensure security groups and networking are correct
Alternative Restart Methods
Using AWS CLI
# Get running tasks
aws ecs list-tasks --cluster Odoo_ECS_Cluster --service-name odoo-http
# Stop a specific task
aws ecs stop-task --cluster Odoo_ECS_Cluster --task task-arn
Using ECS Service Update
For a more controlled restart of all tasks: 1. Go to the service details page 2. Click "Update service" 3. Check "Force new deployment" 4. Click "Update service"
This method restarts all tasks in a rolling fashion.
Best Practices
- Off-Peak Hours: Perform manual restarts during low-traffic periods when possible
- Monitor Logs: Keep CloudWatch logs open during restarts to catch any issues
- Health Checks: Wait for health checks to pass before considering the restart complete
- Document Issues: Note the reason for restart in your incident tracking system
- Team Communication: Notify relevant team members when performing restarts
Verification Steps
After restarting:
- Application Access: Verify the application loads correctly
- Database Connectivity: Ensure database connections are working
- Integration Points: Test key integrations (APIs, external services)
- Performance: Monitor response times and resource usage
- Error Logs: Check for any new errors in the application logs
For persistent issues that require multiple restarts, consider investigating underlying causes such as memory leaks, database connection issues, or infrastructure problems.