Reputation: 1985
I'm working on a service which will scan the given file. I'm using the ECS Fargate task for that. ECS task will keep scanning given files and if malware is found, it will perform the required action on that file and terminate itself. To terminate the task, I'm using System.exit(0)
. Few months back, it was working well. It was terminating the task and Fargate service was creating another task to handle the load. Yesterday I noticed that System.exit(0)
is not terminating the task any more. Its just exiting from my java application. I could still see java process by using ps -eaf
command.
I tried using System.exit(1)
which restart the main method instead of terminating the task.
I tried killing the java process manually in an ECS task using command kill -9
. But it starts the java process again with a different process id (but not triggering the main method again).
Not sure what has changed again. I'm pretty much sure it was working before.
Terminating the task is the security requirement and we don't have an option to skip that.
What am I missing here?
Upvotes: 0
Views: 2971
Reputation: 1396
As I described in thread : Stopping AWS ECS Fargate task when docker container stops You need to use ((ConfigurableApplicationContext) context).close(); insteed System.exit(0)
Upvotes: 0
Reputation: 200436
ECS isn't restarting your Java process inside the container. That is something that is being done by software that is configured inside your docker container. It sounds like you have some sort of startup script you are using as the ECS container's CMD
or ENTRYPOINT
, and that script has changed recently to catch the Java exit and restart the process, instead of just letting the process exit.
All AWS (ECS/Fargate) knows is that it has started a docker container based on the image you gave it, and the primary process of the docker container has not exited yet. If your Java app is being started by some sort of wrapper script, then that script is the primary process, and until that script exits the container will continue to run.
Upvotes: 1