Daemonized processes inside the chroot cause image building to hang indefinitely
(This happened to me while performing a CFEngine bootstrap in a script while building the image which happens to start its own daemon processes, disregarding the init system and any policies.)
For context, what I'm now doing is:
config_space/scripts/ZDV/42-cfengine
:
#!/bin/bashset -ux
ROOTCMD="unshare --pid --fork --kill-child --mount-proc chroot $FAI_ROOT"
$ROOTCMD cf-agent -B config-01.zdv.uni-mainz.de $ROOTCMD cf-agent -K -D bootstrap $ROOTCMD cf-agent -K -D bootstrap
My (updated) solution is to use the following in the script that does perform the problematic operations:
ROOTCMD="unshare --pid --fork --kill-child --mount-proc chroot $FAI_ROOT"
My initial solution was to put something like this after the problematic script or in a finish hook:
PIDS="$(lsof -t +D $FAI_ROOT)" if [[ -n ${PIDS} ]]; then for SIGNAL in TERM KILL; do kill -s ${SIGNAL} ${PIDS} sleep 1 done fi
Now I have two questions:
-
Do you think this would help others with similar problems if included in the Cloud images config_space
or in FAI itself? -
Would you have come up with a better solution?
Edited by Moritz Schlarb