How To

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

Last updated Mar 30, 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.


Overview

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. This article describes how you can do this with DS/OpenDJ and covers the following init systems:

  • systemd (init system for newer distributions)
  • System V (the original init system)

You should follow the steps according to which init system you are using. If you are unsure, you should refer to How To Configure a Linux Service to Start Automatically After a Crash or Reboot – Part 1: Practical Examples for further information.

Example service files

The instructions for both init systems 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 (systemd init)

  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:
    [Unit]
    SourcePath=/opt/opendj/bin
    Description=ForgeRock Directory Server (systemd init)
    Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target display-manager.service
    After=
    Conflicts=shutdown.target
    
    [Service]
    Type=simple
    Restart=no
    TimeoutSec=5min
    IgnoreSIGPIPE=no
    KillMode=process
    GuessMainPID=no
    RemainAfterExit=yes
    ExecStart=/opt/opendj/bin/ds.init start
    ExecStop=/opt/opendj/bin/ds.init stop
    
    [Install]
    WantedBy=multi-user.target
  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
    enabled
    
    $ 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 ds.example.com systemd[1]: Started ForgeRock Directory Server.

Configuring DS/OpenDJ (with System V init system)

  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:
    [Unit]
    SourcePath=/opt/opendj/bin
    Description=ForgeRock Directory Server (System V init)
    Before=runlevel5.target shutdown.target
    After=
    Conflicts=shutdown.target
    
    [Service]
    Type=simple
    Restart=no
    TimeoutSec=5min
    IgnoreSIGPIPE=no
    KillMode=process
    GuessMainPID=no
    RemainAfterExit=no
    ExecStart=/opt/opendj/bin/ds.init start
    ExecStop=/opt/opendj/bin/ds.init stop
    
    [Install]
    WantedBy=multi-user.target
  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
    enabled
    
    $ systemctl status ds.service
    ds.service - ForgeRock Directory Server (System V init)
       Loaded: loaded (/opt/opendj/bin; enabled)
       Active: active (exited) since Tue 2020-02-25 14:21:07 GMT; 1min 2s ago
      Process: 650 ExecStart=/opt/opendj/bin/ds.init start (code=exited, status=0/SUCCESS)
    
    Feb 25 14:21:07 ds.example.com systemd[1]: Started ForgeRock Directory Server.
    

See Also

Administration Guide › Managing Server Processes

Auto-starting Services with systemd

systemd.service — Service unit configuration

Auto-starting Services with System V

Related Training

N/A

Related Issue Tracker IDs

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



Copyright and TrademarksCopyright © 2020 ForgeRock, all rights reserved.
Loading...