entrypoint.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. cat <<EOF | isql-fb security.db
  19. create or alter user SYSDBA password '$_SYSDBA_PWD' using plugin Srp;
  20. create or alter user SYSDBA password '$_SYSDBA_PWD' using plugin Legacy_UserManager;
  21. commit;
  22. quit;
  23. EOF
  24. if [ -f /secrets/FB3_USER_NAME ] && [ -f /secrets/FB3_USER_PWD ]; then
  25. echo "Setting up Firebird user $(cat /secrets/FB3_USER_NAME) with 'grant create database'"
  26. cat <<EOF | isql-fb security.db
  27. create or alter user $(cat /secrets/FB3_USER_NAME) password '$(cat /secrets/FB3_USER_PWD)' using plugin Srp;
  28. create or alter user $(cat /secrets/FB3_USER_NAME) password '$(cat /secrets/FB3_USER_PWD)' using plugin Legacy_UserManager;
  29. grant create database to user $(cat /secrets/FB3_USER_NAME);
  30. commit;
  31. quit;
  32. EOF
  33. fi
  34. }
  35. function checkbase_init {
  36. mktemp > /etc/firebird/check-database.conf
  37. rm -f $(cat /etc/firebird/check-database.conf)
  38. isql-fb << EOF
  39. CREATE DATABASE "$(cat /etc/firebird/check-database.conf)";
  40. EOF
  41. }
  42. if [ ! -f /secrets/FB3_SYSDBA_PWD ]; then
  43. mkdir -p /secrets
  44. echo $RANDOM$RANDOM > /secrets/FB3_SYSDBA_PWD
  45. echo "Setting SYSDBA's random password: "$( cat /secrets/FB3_SYSDBA_PWD )
  46. fi
  47. _SYSDBA_PWD=$(cat /secrets/FB3_SYSDBA_PWD)
  48. # Вынос security3.fdb на ПМЖ
  49. [[ ${EXT_SECURITY} && ${EXT_SECURITY}="true" ]] && \
  50. { [ ! -d /data/security3.fdb ] && cp /var/lib/firebird/secdb/security3.fdb /data/security3.fdb; }
  51. # Создаем символические ссылки на конфигурационные файлы
  52. for i in $(ls -d /configs/*.conf); do ln -sf ${i} /etc/firebird/;done
  53. [ -f /secrets/cluster.conf ] && ln -sf /secrets/cluster.conf /usr/lib64/firebird/plugins/
  54. sec_init
  55. checkbase_init
  56. mkfifo /var/log/dockerout
  57. tail -f /var/log/dockerout &
  58. log_to_dockerout &
  59. exec "$@"