# To change any of the below values, please use a drop-in file in which
# you can declare overrides according to systemd.unit(5), either of:
# - applying to all instances:
#   /etc/systemd/system/dirsrv@.service.d/custom.conf
# - applying to a single instance (overriding the above):
#   /etc/systemd/system/dirsrv@<instance>.service.d/custom.conf
#
# Some of the most interesting coniguration options are mentioned below.
# See systemd.service(5) and systemd.exec(5) for the respective documentation.
#
# After updating the service configuration, do not forget to apply the changes:
# - reload systemd configuration: systemctl daemon-reload
# - restart the service: systemctl restart @package_name@@<instance>.service

[Service]
TimeoutStartSec=0
TimeoutStopSec=600

# These are from man systemd.exec and man systemd.resource-control

# This controls the resources to the direct child of systemd, in
# this case ns-slapd. Because we are type notify we recieve these
# limits correctly.

# This controls the number of file handles avaliable. File handles
# correlate to sockets for the process, and our access to logs and
# databases.  Note, the configuration setting in Directory Server,
# "nsslapd-maxdescriptors", can override this limit.
#LimitNOFILE=

# You can limit the memory in the cgroup with these, and ns-slapd
# will account for them in it's autotuning.
# Memory account may be controlled by DefaultMemoryAccounting= in systemd-system.conf
#MemoryAccounting=yes
#MemoryLimit=<bytes>

# Limits on the size of coredump that may be produced by the process. It's not
# specified how this interacts with coredumpd.
# 0 means not to produce cores.
#LimitCORE=<bytes>

# Limit number of processes (threads) we may spawn. We don't advise you change
# this as DS will autodetect your threads / cpus and adjust as needed.
#LimitNPROC=

# Preload jemalloc
Environment=LD_PRELOAD=@libdir@/@package_name@/lib/libjemalloc.so.2

# Disable Transparent Huge Pages
Environment=THP_DISABLE=1

##################################################
#         Heap profiling with jemalloc           #
##################################################
# Generated files will be named /run/dirsrv/jeprof*.heap
# Uncomment *one* of the following lines to enable leak checking using jemalloc's heap profiler.
# See https://github.com/jemalloc/jemalloc/wiki/Use-Case%3A-Leak-Checking for more details.
#Environment=MALLOC_CONF=prof:true,prof_leak:true,lg_prof_sample:19,prof_final:true,prof_prefix:/run/dirsrv/jeprof
#
#
# Additionally print stats in a human readable form:
#Environment=MALLOC_CONF=prof:true,prof_leak:true,lg_prof_sample:19,prof_final:true,stats_print:true,prof_prefix:/run/dirsrv/jeprof
#
#
# Or in a machine readable form (JSON)
#Environment=MALLOC_CONF=prof:true,prof_leak:true,lg_prof_sample:19,prof_final:true,stats_print:true,stats_print_opts:J,prof_prefix:/run/dirsrv/jeprof
#
#
##################################################
#          Leak detection with Valgrind          #
##################################################
# Generated files will be named /run/dirsrv/ns-slapd-INSTANCE_NAME.valgrind.PID
# Make sure valgrind is installed and debuginfo is present for 389-ds-base and 389-ds-base-libs.
# E.g. on Fedora/RHEL:
# # dnf install valgrind -y
# # debuginfo-install 389-ds-base 389-ds-base-libs -y
#
# Uncomment the following lines. Empty keys reset their values so we can override them.
#TimeoutStartSec=3600
#TimeoutStopSec=3600
#Environment=
#ExecStartPre=
#ExecStart=
#ExecStart=/usr/bin/valgrind --tool=memcheck --num-callers=40 --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file=/run/dirsrv/ns-slapd-%i.valgrind.%%p /usr/sbin/ns-slapd -D /etc/dirsrv/slapd-%i -i /run/dirsrv/slapd-%i.pid
#
#
##################################################
#      Leak detection with AddressSanitizer      #
##################################################
# Generated files will be named /run/dirsrv/ns-slapd-INSTANCE_NAME.asan.PID
# Make sure libasan is installed and debuginfo is present for 389-ds-base and 389-ds-base-libs.
# E.g. on Fedora/RHEL:
# # dnf install libasan -y
# # debuginfo-install 389-ds-base 389-ds-base-libs -y
#
# To get the exact library name to use with LD_PRELOAD, run 
# # rpm -ql libasan | grep libasan
# 
# On versions of systemd=>246 you also need to ensure that `sysctl fs.suid_dumpable` is set to 1.
# (add fs.suid_dumpable=1 to /etc/sysctl.d/99-sysctl.conf and run `sysctl -p`)
#
# You also might need to temporary disable SELinux:
# # setenforce 0
# Don't forget to enable it back after you're done!
# # setenforce 1
# or create a custom SELinux policy to allow ptrace() for ns-slapd process.
#
# Uncomment the following lines. Empty keys reset their values so we can override them.
#TimeoutStartSec=3600
#TimeoutStopSec=3600
#Environment=
#ExecStartPre=
#Environment=LD_PRELOAD=/usr/lib64/libasan.so.6
#Environment=ASAN_OPTIONS=log_path=/run/dirsrv/ns-slapd-%i.asan:print_stacktrace=1:detect_leaks=1:exit_code=0:fast_unwind_on_malloc=0
