osixia / docker-openldap

OpenLDAP container image 🐳🌴
MIT License
4.06k stars 978 forks source link

New slave container is not starting due to missing database #651

Closed nix-power closed 1 year ago

nix-power commented 1 year ago

I want to start container (as a slave) with existent configuration, and ldap db it should pull from the master. I am starting the container as followiing

docker run -idt  
  --net host 
  --volume /srv/ldap/ssl:/etc/ldap/ssl 
  --volume /srv/ldap/config:/etc/ldap/slapd.d
  --volume /srv/ldap/db:/var/lib/ldap
  --env LDAP_REPLICATIOn=own
  --env KEEP_EXISTING_CONFIG=true
  --env HOSTNAME=ldap-1.example.net
  --env LDAP_OPENLDAP_UID=114
  --env LDAP_OPENLDAP_GID=118
  --name openldap osixia/openldap:1.5.0
  --loglevel debug

However, if the /srv/ldap/db is empty i get the following error

***  DEBUG  | 2023-03-02 16:31:15 | ------------------------------------------
***  INFO   | 2023-03-02 16:31:15 | openldap user and group adjustments
***  INFO   | 2023-03-02 16:31:15 | get current openldap uid/gid info inside container
***  INFO   | 2023-03-02 16:31:15 | CUR_USER_UID (911) does't match LDAP_OPENLDAP_UID (114), adjusting...
***  INFO   | 2023-03-02 16:31:15 | CUR_USER_GID (911) does't match LDAP_OPENLDAP_GID (118), adjusting...
***  INFO   | 2023-03-02 16:31:15 | -------------------------------------
***  INFO   | 2023-03-02 16:31:15 | openldap GID/UID
***  INFO   | 2023-03-02 16:31:15 | -------------------------------------
***  INFO   | 2023-03-02 16:31:15 | User uid: 114
***  INFO   | 2023-03-02 16:31:15 | User gid: 118
***  INFO   | 2023-03-02 16:31:15 | uid/gid changed: true
***  INFO   | 2023-03-02 16:31:15 | -------------------------------------
***  INFO   | 2023-03-02 16:31:15 | updating file uid/gid ownership
***  ERROR  | 2023-03-02 16:31:16 | Error: the database directory (/var/lib/ldap) is empty but not the config directory (/etc/ldap/slapd.d)
***  ERROR  | 2023-03-02 16:31:16 | /container/run/startup/slapd failed with status 1

How can i make this working ?

nix-power commented 1 year ago

Actually i have fixed this by changing code of startup.sh script and using new environment variable

   # Error: the database directory (/var/lib/ldap) is empty but not the config directory (/etc/ldap/slapd.d)
   #
   elif [ -z "$(ls -A -I lost+found --ignore=.* /var/lib/ldap)" ] && [ ! -z "$(ls -A -I lost+found --ignore=.* /etc/ldap/slapd.d)" ]; then
-    log-helper error "Error: the database directory (/var/lib/ldap) is empty but not the config directory (/etc/ldap/slapd.d)"
-    exit 1
+    if [ -z ${SLAVE_MOOE} ]; then
+      log-helper error "Error: the database directory (/var/lib/ldap) is empty but not the config directory (/etc/ldap/slapd.d)"
+      exit 1
+    fi

Aftter rebuilding the image and ruinning it with --env SLAVE_MODE=true replication works fine and pulls all db files from master on startup. This could be closed.