I need to run c++ application inside a docker container and it is deployed using AWS ECS. The application should run as user abcd and it should be able to generate core files. Initially I had a run script that handles enabling core files and run as abcd user. My initial run script looks like below and script is linked in docker file using CMD tag.
#!/bin/bash
echo ‘/var/dumps/core.%e.%p.%t’ | tee /proc/sys/kernel/core_pattern
ulimit -c unlimited
exec su -s /bin/bash abcd -c “myApp”
In this case I was able to run and it was generating core files in case of crash. But when shutting down, it was not graceful because su was running as PID 1 and, once PID 1 process receives the SIGTERM, it exits first. Just after shutting down su, myApp terminates in the middle of the stopping process.
Then I referred AWS Graceful Shutdown documentation and tried to make myApp process runs as PID 1. I updated run script as below.
#!/bin/bash
ulimit -c unlimited
exec “myApp”
Also, I switched my user to abcd and enabled core patterns in docker file. Initially this case it shuts down gracefully, but it wasn’t generating core files.
Can you help me how can I achieve all three of my conditions which are,
- Run as abcd user
- Graceful shutdown
- Generate core files when crashing
Thank you in advance.