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).
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.initAn example init script is attached to this article for reference.
- 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
- Enable the service file (called ds.service in this example):
$ sudo systemctl enable ds.service
- Reload the daemon:
$ sudo systemctl daemon-reload
- Stop and restart DS/OpenDJ:
$ ./stop-ds $ ./start-ds
- 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: Started ForgeRock Directory Server.