custom services are now copied into easily identifiable directory so we can remove and 'start fresh' every container run. This allows users to remove services and the changes to take effect on a restart rather than having to rebuild the container

This commit is contained in:
alex-phillips 2019-05-18 10:39:46 -04:00
parent 9b0dd02566
commit 68483bc920

View file

@ -4,42 +4,49 @@
SCRIPTS_DIR="/config/custom-cont-init.d" SCRIPTS_DIR="/config/custom-cont-init.d"
SERVICES_DIR="/config/custom-services.d" SERVICES_DIR="/config/custom-services.d"
# Make sure custom directories exist and have files in them # Make sure custom init directory exists and has files in it
if ([ -e "${SCRIPTS_DIR}" ] && \ if ([ -e "${SCRIPTS_DIR}" ] && \
[ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]) || \ [ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]); then
([ -e "${SERVICES_DIR}" ] && \ echo "[custom-init] files found in ${SCRIPTS_DIR} executing"
[ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]); then for SCRIPT in ${SCRIPTS_DIR}/*; do
if [ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]; then NAME="$(basename "${SCRIPT}")"
echo "[custom-init] files found in ${SCRIPTS_DIR} executing" if [ -f "${SCRIPT}" ]; then
for SCRIPT in ${SCRIPTS_DIR}/*; do echo "[custom-init] ${NAME}: executing..."
NAME="$(basename "${SCRIPT}")" /bin/bash ${SCRIPT}
if [ -f "${SCRIPT}" ]; then echo "[custom-init] ${NAME}: exited $?"
echo "[custom-init] ${NAME}: executing..." elif [ ! -f "${SCRIPT}" ]; then
/bin/bash ${SCRIPT} echo "[custom-init] ${NAME}: is not a file"
echo "[custom-init] ${NAME}: exited $?" fi
elif [ ! -f "${SCRIPT}" ]; then done
echo "[custom-init] ${NAME}: is not a file"
fi
done
fi
if [ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]; then
echo "[custom-init] service files found in ${SERVICES_DIR} copying"
for SERVICE in ${SERVICES_DIR}/*; do
NAME="$(basename "${SERVICE}")"
if ! $(cmp -s ${SERVICE} /etc/services.d/${NAME}/run) && \
[ -f "${SERVICE}" ]; then
echo "[custom-init] ${NAME}: new file detected copying..."
mkdir -p /etc/services.d/${NAME}/
cp ${SERVICE} /etc/services.d/${NAME}/run
chmod +x /etc/services.d/${NAME}/run
echo "[custom-init] ${NAME}: copied"
elif [ ! -f "${SERVICE}" ]; then
echo "[custom-init] ${NAME}: is not a file"
else
echo "[custom-init] ${NAME}: is up to date"
fi
done
fi
else else
echo "[custom-init] no custom files found exiting..." echo "[custom-init] no custom init files found"
fi fi
# Remove all existing custom services before continuing to ensure
# we aren't running anything the user may have removed
if [ -n "$(/bin/ls -A /etc/services.d/custom-service-* 2>/dev/null)" ]; then
echo "[custom-init] removing existing custom services..."
rm -rf /etc/services.d/custom-service-*
fi
# Make sure custom services directory exists and has files in it
if [ -e "${SERVICES_DIR}" ] && \
[ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]; then
echo "[custom-init] service files found in ${SERVICES_DIR}"
for SERVICE in ${SERVICES_DIR}/*; do
NAME="$(basename "${SERVICE}")"
if [ -f "${SERVICE}" ]; then
echo "[custom-init] ${NAME}: service detected, copying..."
mkdir -p /etc/services.d/custom-service-${NAME}/
cp ${SERVICE} /etc/services.d/custom-service-${NAME}/run
chmod +x /etc/services.d/custom-service-${NAME}/run
echo "[custom-init] ${NAME}: copied"
elif [ ! -f "${SERVICE}" ]; then
echo "[custom-init] ${NAME}: is not a file"
fi
done
else
echo "[custom-init] no custom services files found"
fi
echo "[custom-init] done"