docker-entrypoint.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env bash
  2. set -e
  3. function log_to_dockerout {
  4. cd /var/log/firebird
  5. while true
  6. do
  7. for i in $(ls *.log)
  8. do
  9. if [ -z "$(pgrep -f ${i})" ] ; then
  10. echo Processing ${i} > /var/log/dockerout
  11. tail -f /var/log/firebird/$i 2> /dev/null | while read fread; do echo "[${i}]: ${fread}" >> /var/log/dockerout; :> /var/log/firebird/$i; done &
  12. fi
  13. done
  14. sleep 10
  15. done
  16. }
  17. function sec_init
  18. {
  19. cat <<EOF | isql-fb security.db
  20. create or alter user SYSDBA password '$_SYSDBA_PWD' using plugin Srp;
  21. create or alter user SYSDBA password '$_SYSDBA_PWD' using plugin Legacy_UserManager;
  22. commit;
  23. quit;
  24. EOF
  25. if [ -f /run/secrets/FB3_USER_NAME ] && [ -f /run/secrets/FB3_USER_PWD ]; then
  26. echo "Setting up Firebird user $(cat /run/secrets/FB3_USER_NAME) with 'grant create database'"
  27. cat <<EOF | isql-fb security.db
  28. create or alter user $(cat /run/secrets/FB3_USER_NAME) password '$(cat /run/secrets/FB3_USER_PWD)' using plugin Srp;
  29. create or alter user $(cat /run/secrets/FB3_USER_NAME) password '$(cat /run/secrets/FB3_USER_PWD)' using plugin Legacy_UserManager;
  30. grant create database to user $(cat /run/secrets/FB3_USER_NAME);
  31. commit;
  32. quit;
  33. EOF
  34. fi
  35. }
  36. function checkbase_init
  37. {
  38. mktemp > /etc/firebird/check-database.conf
  39. rm -f $(cat /etc/firebird/check-database.conf)
  40. isql-fb << EOF
  41. CREATE DATABASE "$(cat /etc/firebird/check-database.conf)";
  42. EOF
  43. }
  44. if [ ! -f /run/secrets/FB3_SYSDBA_PWD ]; then
  45. mkdir -p /run/secrets
  46. echo $RANDOM$RANDOM > /run/secrets/FB3_SYSDBA_PWD
  47. echo "Setting SYSDBA's random password: "$( cat /run/secrets/FB3_SYSDBA_PWD )
  48. fi
  49. _SYSDBA_PWD=$(cat /run/secrets/FB3_SYSDBA_PWD)
  50. sec_init
  51. checkbase_init
  52. mkfifo /var/log/dockerout
  53. tail -f /var/log/dockerout &
  54. log_to_dockerout &
  55. exec "$@"