I have an application from a vendor, which consists of a bunch of binaries and I need to dockerize it for our development lab environment. The application is built such that an "entrypoint" binary launches all those other binaries and exits.
This application's architecture is such that it has a single binary "entrypoint", which creates a shared memory file and launches a bunch of processes that use this file, and then exits. So it cannot be used as the docker process and it can't be used with any kind of init system because it does not launch any bash jobs that could be waited on with wait
instruction and if it does keep a list of PIDs somehow, I do not know how.
And when I want to shut everything down, I need to call that entrypoint binary again so it would clean up the shared memory file and kill the processes it launched.
Also, this architecture means that instead of outputting everything to stdout, all those processes write logs to a specific file. As a result I can't track the logs either. I tried to ln -sf /proc/1/fd/1 /app/log/app.log
in the docker image but it doesn't seem to do anything.
I tried to make the following entrypoint but it doesn't work and just hangs there, never exiting:
#!/bin/bash
set -x
dbus-daemon --system --print-address
trap "/opt/app/entrypoint --terminate; exit" 0 SIGINT
su -s /bin/bash app -c "/opt/app/entrypoint $@"
# now it would launch the processes and exit
tail -f /opt/app/logs/app.log
Is there any way that such an application can be containerized or should I reach out to the vendor to change it somehow?
I got it working with the following script set as entrypoint:
#!/usr/bin/env bash
set -x
# "mde" is the main binary that spawns all those processes
trap 'echo "terminating..." && su -s /bin/bash mde -c "./mde -t"' SIGTERM SIGINT SIGQUIT SIGHUP ERR
# ... a bunch of file manipulations to hack the way application is set up
tail -n+1 -F logs/app.log &
tailpid=$!
su -s /bin/bash mde -c "./mde -e" &
mdepid=$!
echo $tailpid > tailpid
echo $mdepid > mdepid
wait "$tailpid" "$mdepid"
What this basically does is just make the "tail" a primary process of the container, since "mde" just spawns all those other processes and exits. Needless to say, I do not recommend doing this to anyone, it was just a temporary hack for us.