How To

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

Last updated Aug 10, 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. See one of the following sections for details depending on your version:

Service file

The instructions below generate a systemd service file (DS 7 and later) or provide an example service file (Pre-DS 7) 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 (DS 7 and later)

  1. Generate a DS init script and systemd service file by running the create-rc-script tool as detailed in Maintenance Guide › Server Processes. For example:
    $ ./create-rc-script --userName ds-user --systemdService /etc/systemd/ds.service --outputFile /etc/init.d/ds
    
  2. Enable the service file (called ds.service in this example):
    $ sudo systemctl enable ds.service
    
  3. Reload the daemon:
    $ sudo systemctl daemon-reload
  4. Stop and restart DS:
    $ ./stop-ds
    $ ./start-ds
  5. 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-10-07 15:42:01 GMT; 1min 2s ago
      Process: 673 ExecStart=/etc/init.d/ds start (code=exited, status=0/SUCCESS)
    
    Oct 07 15:42:01 ds.example.com systemd[1]: Started ForgeRock Directory Server.

Configuring DS/OpenDJ (Pre-DS 7)

  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 ds-user --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=
    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.

See Also

Auto-starting Services with systemd

systemd.service — Service unit configuration

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...