How To

How do I configure DS/OpenDJ (All versions) to be stopped and started as a service using systemd and systemctl?

Last updated Jun 9, 2020

The purpose of this article is to provide assistance with configuring DS/OpenDJ to be stopped and started as a service using systemd and systemctl if you are using a Linux® system. This method uses init scripts created with create-rc script.


systemd is backwards compatible with Linux initialization scripts as detailed in: How To Configure a Linux Service to Start Automatically After a Crash or Reboot – Part 1: Practical Examples.

The key thing to be aware of when using systemd is that you must create your own init scripts and enable the services to start automatically.

Example service file

The instructions below give an example service file that you can use as the basis of your service file (alternatively, you could copy an existing service file from your system and use that as the basis instead).

You should adjust this as needed for your system, but consider the following points around specific settings:

  • SourcePath is the path to the location of the starting binary/script file.
  • ExecStart is the path to the init script that was created by the create-rc-script command.
  • TimeoutSec is set to timeout after 5 minutes on start or stop.
  • KillMode is set to kill the process if the timeout expires.
  • GuessMainPID is not needed since DS/OpenDJ only ever starts up as a single process.
  • PIDFile has been excluded from these examples with Restart=no because we advise against auto-restarting DS/OpenDJ. If the server crashes, you should investigate what has happened and why, and also check for other issues such as disabled backends before restarting the server manually. Additionally, auto-restarting the server could cause issues for client applications (such as AM/OpenAM) that ping an alive endpoint but do not know if the backend they require is actually available.

    If you do include PIDFile, it should only be for the purpose of helping systemctl/systemd identify the process ID (Restart should still equal no).

Configuring DS/OpenDJ

  1. Generate a DS/OpenDJ init script by running the create-rc-script tool as detailed in Administration Guide › Managing Server Processes. For example:
    $ ./create-rc-script --userName root --outputFile ds.init
    An example init script is attached to this article for reference.
  2. Create a service file. The following example can be used as the basis of your file:
    Description=ForgeRock Directory Server (systemd init) display-manager.service
    ExecStart=/opt/opendj/bin/ds.init start
    ExecStop=/opt/opendj/bin/ds.init stop
  3. Enable the service file (called ds.service in this example):
    $ sudo systemctl enable ds.service
  4. Reload the daemon:
    $ sudo systemctl daemon-reload
  5. Stop and restart DS/OpenDJ:
    $ ./stop-ds
    $ ./start-ds
  6. Verify the service is online as follows:
    $ systemctl is-enabled ds.service
    $ systemctl status ds.service
    ds.service - ForgeRock Directory Server (systemd init)
       Loaded: loaded (/opt/opendj/bin; enabled; vendor preset: disabled)
       Active: active (exited) since Tue 2020-02-25 14:21:07 GMT; 1min 2s ago
      Process: 673 ExecStart=/opt/opendj/bin/ds.init start (code=exited, status=0/SUCCESS)
    Feb 25 14:21:07 systemd[1]: Started ForgeRock Directory Server.

See Also

Administration Guide › Managing Server Processes

Auto-starting Services with systemd

systemd.service — Service unit configuration

Related Training


Related Issue Tracker IDs

OPENDJ-3810 (Add Linux systemd support for OPENDJ startup)

Copyright and TrademarksCopyright © 2020 ForgeRock, all rights reserved.