docker-entrypoint.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. # Modified based on Squid OCI image entrypoint
  3. # This entrypoint aims to forward the squid logs to stdout to assist users of
  4. # common container related tooling (e.g., kubernetes, docker-compose, etc) to
  5. # access the service logs.
  6. # Moreover, it invokes the squid binary, leaving all the desired parameters to
  7. # be provided by the "command" passed to the spawned container. If no command
  8. # is provided by the user, the default behavior (as per the CMD statement in
  9. # the Dockerfile) will be to use Ubuntu's default configuration [1] and run
  10. # squid with the "-NYC" options to mimic the behavior of the Ubuntu provided
  11. # systemd unit.
  12. # [1] The default configuration is changed in the Dockerfile to allow local
  13. # network connections. See the Dockerfile for further information.
  14. echo "[ENTRYPOINT] re-create snakeoil self-signed certificate removed in the build process"
  15. if [ ! -f /etc/ssl/private/ssl-cert-snakeoil.key ]; then
  16. /usr/sbin/make-ssl-cert generate-default-snakeoil --force-overwrite > /dev/null 2>&1
  17. fi
  18. tail -F /var/log/squid/access.log 2>/dev/null &
  19. tail -F /var/log/squid/error.log 2>/dev/null &
  20. tail -F /var/log/squid/store.log 2>/dev/null &
  21. tail -F /var/log/squid/cache.log 2>/dev/null &
  22. # Replace environment variables in the template and output to the squid.conf
  23. echo "[ENTRYPOINT] replacing environment variables in the template"
  24. awk '{
  25. while(match($0, /\${[A-Za-z_][A-Za-z_0-9]*}/)) {
  26. var = substr($0, RSTART+2, RLENGTH-3)
  27. val = ENVIRON[var]
  28. $0 = substr($0, 1, RSTART-1) val substr($0, RSTART+RLENGTH)
  29. }
  30. print
  31. }' /etc/squid/squid.conf.template > /etc/squid/squid.conf
  32. /usr/sbin/squid -Nz
  33. echo "[ENTRYPOINT] starting squid"
  34. /usr/sbin/squid -f /etc/squid/squid.conf -NYC 1