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
rodzic
d8a38dd768
commit
1cf8a446c1
|
@ -1,30 +1,52 @@
|
|||
#!/usr/bin/with-contenv bash
|
||||
|
||||
# Make sure custom script directory exists and has files in it
|
||||
SCRIPTS_DIR="/config/custom-init-scripts"
|
||||
if [ -e "${SCRIPTS_DIR}" ] && \
|
||||
[ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]; then
|
||||
# Directories
|
||||
SCRIPTS_DIR="/config/custom-cont-init.d"
|
||||
SERVICES_DIR="/config/custom-services.d"
|
||||
|
||||
# Make sure custom init directory exists and has files in it
|
||||
if ([ -e "${SCRIPTS_DIR}" ] && \
|
||||
[ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]); then
|
||||
echo "[custom-init] files found in ${SCRIPTS_DIR} executing"
|
||||
for SCRIPT in ${SCRIPTS_DIR}/*; do
|
||||
echo "[custom-init] ${SCRIPT}: executing..."
|
||||
NAME="$(basename "${SCRIPT}")"
|
||||
if [ -f "${SCRIPT}" ]; then
|
||||
echo "[custom-init] ${NAME}: executing..."
|
||||
/bin/bash ${SCRIPT}
|
||||
echo "[custom-init] ${SCRIPT}: exited $?"
|
||||
echo "[custom-init] ${NAME}: exited $?"
|
||||
elif [ ! -f "${SCRIPT}" ]; then
|
||||
echo "[custom-init] ${NAME}: is not a file"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "[custom-init] no custom scripts found exiting..."
|
||||
echo "[custom-init] no custom init files found"
|
||||
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
|
||||
SERVICES_DIR="/config/custom-services.d"
|
||||
if [ -e "${SERVICES_DIR}" ] && \
|
||||
[ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]; then
|
||||
echo "[custom-init] service folders found in ${SERVICES_DIR} executing"
|
||||
echo "[custom-init] service files found in ${SERVICES_DIR}"
|
||||
for SERVICE in ${SERVICES_DIR}/*; do
|
||||
echo "[custom-init] ${SERVICE}: copying..."
|
||||
cp -r ${SERVICE} /etc/services.d/
|
||||
chmod +x /etc/services.d/${SERVICE}/run
|
||||
echo "[custom-init] ${SERVICE}: done"
|
||||
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 found exiting..."
|
||||
echo "[custom-init] no custom services files found"
|
||||
fi
|
||||
|
||||
echo "[custom-init] done"
|
||||
|
|
Ładowanie…
Reference in New Issue