How to delay the directory sync on startup in Confluence
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Purpose
In larger environments with over 1000 LDAP groups, or over 10,000 users, the LDAP sync on Confluence startup can take a long time to complete. This occurs on startup and in some cases can prevent users from logging into the product until the sync is complete.
This article explains how to delay this sync, which will allow for Confluence to complete startup in a reasonable amount of time and allow users to login. The sync can be scheduled to run during off-peak hours to minimize the impact.
This article will serve the purpose of a workaround until this feature request is implemented: CONFSERVER-22326 - Getting issue details... STATUS
Solution - Dynamic Sync Start Time
To delay the directory sync on startup of Confluence, set a value in milliseconds for which the sync should be delayed.
Add the following jvm parameter to <confluence-install>/bin/setenv.sh (or setenv.bat in Windows), or your custom startup script:
-Dcrowd.polling.startdelay=<delay_value_in_milliseconds>
For example, if you wish to delay the sync by 12 hours:
-Dcrowd.polling.startdelay=43200000
- Restart Confluence for the changes to take effect.
This will start the sync 12 hours after Confluence starts, effectively allowing Confluence to be fully up and running and not waiting on a sync to complete before becoming available to users.
Solution - Fixed Sync Start Time
If you wish to use a fixed time, such as 3am to perform the syncs, you can define the number of milliseconds at startup dynamically by creating a variable:
Add the following to your <confluence-install>/bin/setenv.sh file:
TIME_TO_3AM_IN_MS=$(($(($((86400+$(($(date -d "03:00" +%s)-$(date +%s)))))%86400))*1000)) echo "On startup, initial crowd sync will be delayed up to 3AM, which is in $TIME_TO_3AM_IN_MS ms." CATALINA_OPTS="-Dcrowd.polling.startdelay=$TIME_TO_3AM_IN_MS $CATALINA_OPTS"
Or, 7pm for example:
TIME_TO_7PM_IN_MS=$(($(($((86400+$(($(date -d "19:00" +%s)-$(date +%s)))))%86400))*1000)) echo "On startup, initial crowd sync will be delayed up to 7PM, which is in $TIME_TO_7PM_IN_MS ms." CATALINA_OPTS="-Dcrowd.polling.startdelay=$TIME_TO_7PM_IN_MS ${CATALINA_OPTS}"
- Restart Confluence for the changes to take effect.
Breakdown of each step above
# 3am in seconds
3AM_IN_SECONDS=$(date -d "03:00" +%s)
# current time in seconds
CURRENT_TIME_IN_SECONDS=$(date +%s)
# difference between the above
TIME_DIFF=$(($3AM_IN_SECONDS - $CURRENT_TIME_IN_SECONDS))
# add 1 day, modulo 1 day, in case the date command retrieved 3am in the past, causing a negative time difference
# Note that modulo of a negative number *should* be positive according to mathematics but shell script doesn't do this correctly, which is why the day has to be added first
ADJUSTED_TIME_DIFF=$(($((86400 + $TIME_DIFF)) % 86400))
# multiply by 1000 to get ms instead of seconds
TIME_TO_3AM_IN_MS=$(($ADJUSTED_TIME_DIFF * 1000))
Notes
- While this KB article was written for Confluence, this JVM parameter can also be applied in other applications.
- Please note that this parameter is currently not working in newer versions of Crowd. See the following Crowd bug for more details CWD-5437 - Getting issue details... STATUS
- On Confluence Data Center the directory synchronization schedule works on different way and the parameter described in this KB doesn't work out of the box. See the following Confluence bug for more details CONFSERVER-60516 - Getting issue details... STATUS