Add custom service handling
This commit is contained in:
parent
92a97355b4
commit
1f81e9ac8a
|
|
@ -131,3 +131,65 @@ done
|
|||
|
||||
# Set executable bit on cont-init and services that may have been unpacked by mods
|
||||
set_legacy_executable_bits
|
||||
|
||||
# Process Custom Services
|
||||
SERVICES_DIR_OLD="/config/custom-services.d"
|
||||
SERVICES_DIR="/custom-services.d"
|
||||
|
||||
if [ -e "${SERVICES_DIR_OLD}" ]; then
|
||||
chown -R 0:0 "${SERVICES_DIR_OLD}"
|
||||
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/s6-overlay/s6-rc.d/custom-svc-* 2>/dev/null)" ]; then
|
||||
echo "[custom-init] removing existing custom services..."
|
||||
rm -rf /etc/s6-overlay/s6-rc.d/custom-svc-*
|
||||
fi
|
||||
|
||||
if { [ -z "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]; } && \
|
||||
{ [ -z "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]; }; then
|
||||
echo "[custom-init] no custom files found, exiting..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Make sure custom init directory exists and has files in it
|
||||
if { [ -e "${SERVICES_DIR}" ] && [ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]; }; then
|
||||
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/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/
|
||||
cp "${SERVICE}" /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run
|
||||
chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run
|
||||
echo "oneshot" > /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type
|
||||
echo "/etc/s6-overlay/s6-rc.d/custom-svc-${NAME}/run" > /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/up
|
||||
echo "[custom-init] ${NAME}: copied"
|
||||
elif [ ! -f "${SERVICE}" ]; then
|
||||
echo "[custom-init] ${NAME}: is not a file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
if { [ -e "${SERVICES_DIR_OLD}" ] && [ -n "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]; }; then
|
||||
if [ -n "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]; then
|
||||
echo "[custom-init] service files found in ${SERVICES_DIR_OLD}"
|
||||
for SERVICE in ${SERVICES_DIR_OLD}/*; do
|
||||
NAME="$(basename "${SERVICE}")"
|
||||
if [ -f "${SERVICE}" ]; then
|
||||
echo "[custom-init] ${NAME}: service detected, copying..."
|
||||
mkdir -p /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/
|
||||
cp "${SERVICE}" /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run
|
||||
chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run
|
||||
echo "oneshot" > /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type
|
||||
echo "/etc/s6-overlay/s6-rc.d/custom-svc-${NAME}/run" > /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/up
|
||||
echo "[custom-init] ${NAME}: copied"
|
||||
elif [ ! -f "${SERVICE}" ]; then
|
||||
echo "[custom-init] ${NAME}: is not a file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
Loading…
Reference in a new issue