Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compatibility with kubernetes #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 76 additions & 18 deletions clamav/unstable/alpine/scripts/docker-entrypoint-unprivileged.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# needing to learn about --entrypoint
# https://github.com/docker-library/official-images#consistency

set -eu
set -u

# run command if it is not starting with a "-" and is an executable in PATH
if [ "${#}" -gt 0 ] && \
Expand All @@ -24,45 +24,103 @@ else
fi
# else default to running clamav's servers

# Ensure we have some virus data, otherwise clamd refuses to start
if [ ! -f "/var/lib/clamav/main.cvd" ]; then
echo "Updating initial database"
freshclam --foreground --stdout
fi
# Ensure we have some up to date virus data, otherwise clamd refuses to start
echo "Updating initial database"
freshclam --foreground --stdout

if [ "${CLAMAV_NO_FRESHCLAMD:-false}" != "true" ]; then
echo "Starting Freshclamd"
freshclam \
--checks="${FRESHCLAM_CHECKS:-1}" \
--daemon \
--foreground \
--stdout \
--user="clamav" \
&

while true; do
ps aux |grep freshclam |grep -q -v grep
status=$?

if [ $status -ne 0 ]; then
freshclam \
--checks="${FRESHCLAM_CHECKS:-1}" \
--daemon \
--foreground \
--stdout \
--user="clamav" \
&
else
break;
fi

if [ "${_timeout:=0}" -gt "${FRESHCLAM_STARTUP_TIMEOUT:=600}" ]; then
echo
echo "Failed to start freshclam"
exit 1
fi

ps aux |grep freshclam |grep -q -v grep
status=$?

if [ $status -ne 0 ]; then
echo "freshclam not started yet, retrying (${_timeout}/${FRESHCLAM_STARTUP_TIMEOUT}) ..."
sleep 3
_timeout="$((_timeout + 1))"
fi
done
fi

if [ "${CLAMAV_NO_CLAMD:-false}" != "true" ]; then
echo "Starting ClamAV"

if [ -S "/tmp/clamd.sock" ]; then
unlink "/tmp/clamd.sock"
fi
clamd --foreground &

while [ ! -S "/tmp/clamd.sock" ]; do
if [ "${_timeout:=0}" -gt "${CLAMD_STARTUP_TIMEOUT:=1800}" ]; then
ps aux |grep clamd |grep -q -v grep
status=$?

if [ $status -ne 0 ]; then
clamd --foreground &
fi

if [ "${_timeout:=0}" -gt "${CLAMD_STARTUP_TIMEOUT:=600}" ]; then
echo
echo "Failed to start clamd"
exit 1
fi
printf "\r%s" "Socket for clamd not found yet, retrying (${_timeout}/${CLAMD_STARTUP_TIMEOUT}) ..."
sleep 1

echo "Socket for clamd not found yet, retrying (${_timeout}/${CLAMD_STARTUP_TIMEOUT}) ..."
sleep 3
_timeout="$((_timeout + 1))"
done
echo "socket found, clamd started."
fi

if [ "${CLAMAV_NO_MILTERD:-true}" != "true" ]; then
echo "Starting clamav milterd"
clamav-milter &

while true; do
ps aux |grep clamav-milter |grep -q -v grep
status=$?

if [ $status -ne 0 ]; then
clamav-milter &
else
break;
fi

if [ "${_timeout:=0}" -gt "${MILTER_STARTUP_TIMEOUT:=600}" ]; then
echo
echo "Failed to start clamav-milter"
exit 1
fi


ps aux |grep clamav-milter |grep -q -v grep
status=$?

if [ $status -ne 0 ]; then
echo "clamav-milter not started yet, retrying (${_timeout}/${MILTER_STARTUP_TIMEOUT}) ..."
sleep 3
_timeout="$((_timeout + 1))"
fi
done
fi

# Wait forever (or until canceled)
Expand Down