Skip to content
Snippets Groups Projects
Commit 5940cc71 authored by alex-phillips's avatar alex-phillips
Browse files

modified logic to have init script and services folder checks in single check

parent 1cf8a446
No related branches found
No related tags found
No related merge requests found
...@@ -4,24 +4,6 @@ ...@@ -4,24 +4,6 @@
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 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
NAME="$(basename "${SCRIPT}")"
if [ -f "${SCRIPT}" ]; then
echo "[custom-init] ${NAME}: executing..."
/bin/bash ${SCRIPT}
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 init files found"
fi
# Remove all existing custom services before continuing to ensure # Remove all existing custom services before continuing to ensure
# we aren't running anything the user may have removed # we aren't running anything the user may have removed
if [ -n "$(/bin/ls -A /etc/services.d/custom-service-* 2>/dev/null)" ]; then if [ -n "$(/bin/ls -A /etc/services.d/custom-service-* 2>/dev/null)" ]; then
...@@ -29,24 +11,40 @@ if [ -n "$(/bin/ls -A /etc/services.d/custom-service-* 2>/dev/null)" ]; then ...@@ -29,24 +11,40 @@ if [ -n "$(/bin/ls -A /etc/services.d/custom-service-* 2>/dev/null)" ]; then
rm -rf /etc/services.d/custom-service-* rm -rf /etc/services.d/custom-service-*
fi fi
# Make sure custom services directory exists and has files in it # Make sure custom init directory exists and has files in it
if [ -e "${SERVICES_DIR}" ] && \ if ([ -e "${SCRIPTS_DIR}" ] && \
[ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]; then [ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]) || \
echo "[custom-init] service files found in ${SERVICES_DIR}" ([ -e "${SERVICES_DIR}" ] && \
for SERVICE in ${SERVICES_DIR}/*; do [ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]); then
NAME="$(basename "${SERVICE}")" if [ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]; then
if [ -f "${SERVICE}" ]; then echo "[custom-init] files found in ${SCRIPTS_DIR} executing"
echo "[custom-init] ${NAME}: service detected, copying..." for SCRIPT in ${SCRIPTS_DIR}/*; do
mkdir -p /etc/services.d/custom-service-${NAME}/ NAME="$(basename "${SCRIPT}")"
cp ${SERVICE} /etc/services.d/custom-service-${NAME}/run if [ -f "${SCRIPT}" ]; then
chmod +x /etc/services.d/custom-service-${NAME}/run echo "[custom-init] ${NAME}: executing..."
echo "[custom-init] ${NAME}: copied" /bin/bash ${SCRIPT}
elif [ ! -f "${SERVICE}" ]; then echo "[custom-init] ${NAME}: exited $?"
echo "[custom-init] ${NAME}: is not a file" elif [ ! -f "${SCRIPT}" ]; then
fi echo "[custom-init] ${NAME}: is not a file"
done fi
done
fi
if [ -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
fi
fi
else else
echo "[custom-init] no custom services files found" echo "[custom-init] no custom files found exiting..."
fi fi
echo "[custom-init] done"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment