entrypoint.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. # Log everything to this log file
  3. #exec &> $ENTRYLOG
  4. # Inspired by https://github.com/acobaugh/openldap-alpine
  5. # When not limiting the open file descriptors, the memory consumption
  6. # of slapd is absurdly high. See https://github.com/docker/docker/issues/8231
  7. ulimit -n 8192
  8. # If there's no cn=config database, initialize one.
  9. # Take the original slapd.conf file as template.
  10. if [ ! -d '/etc/openldap/slapd.d/cn=config' ]; then
  11. # Limit the access to the database
  12. SLAPD_CONFIG_ROOTPW=`< /dev/urandom tr -dc A-Za-z0-9 | head -c14; echo`
  13. # Generate a password hash
  14. config_rootpw_hash=`slappasswd -s "${SLAPD_CONFIG_ROOTPW}"`
  15. echo $SLAPD_CONFIG_ROOTPW > /etc/openldap/slapd.d/slapd_config_rootpw
  16. chmod 400 /etc/openldap/slapd.d/slapd_config_rootpw
  17. # Check if all certificates and keys are present
  18. # if [ ! -f ${SSL_PATH}/slurm.ch-rootCA.crt ] || \
  19. # [ ! -f ${SSL_PATH}/ldap.slurm.ch.crt ] || \
  20. # [ ! -f ${SSL_PATH}/ldap.slurm.ch.key ]; then
  21. # echo "Not all certificates and keys found for TLS."
  22. # exit 1
  23. # fi
  24. # Use the original slapd.conf file
  25. cp /etc/openldap/slapd.conf /tmp/slapd.conf
  26. # Set the correct suffix
  27. #sed -i -e "s/dc=my-domain,dc=com/${SUFFIX}/g" /tmp/slapd.conf
  28. #sed -i -e "/core.schema/a include\t\t/etc/openldap/schema/cosine.schema" /tmp/slapd.conf
  29. #sed -i -e "/cosine.schema/a include\t\t/etc/openldap/schema/inetorgperson.schema" /tmp/slapd.conf
  30. # Add configuration for TLS and set root password for config database.
  31. cat <<-EOF >> /tmp/slapd.conf
  32. #TLSCACertificateFile ${SSL_PATH}/slurm.ch-rootCA.crt
  33. #TLSCertificateFile ${SSL_PATH}/ldap.slurm.ch.crt
  34. #TLSCertificateKeyFile ${SSL_PATH}/ldap.slurm.ch.key
  35. #TLSCipherSuite HIGH:-SSLv2:-SSLv3
  36. #######################################################################
  37. # Dynamic config
  38. #######################################################################
  39. database config
  40. rootDN "cn=admin,cn=config"
  41. rootPW $config_rootpw_hash
  42. EOF
  43. # Generate config database from slapd.conf file.
  44. echo Generating configuration
  45. slaptest -f /tmp/slapd.conf -F /etc/openldap/slapd.d
  46. fi
  47. # Set all ownerships straight.
  48. chown -R ldap:ldap /etc/openldap/slapd.d
  49. mkdir /var/lib/openldap/run || true
  50. echo Starting slapd with $@
  51. exec "$@"