Starting Oracle Unified Directory on system boot is essential for production environment. Unfortunately OUD just provides a script to create the init.d script. But newer system in general use systemd initialise and startup. Nevertheless, creating a custom unit file for OUD is simple and straightforward. First, let’s create a regular init.d script with the create-rc-script from oud. The created custom script can be used as template for the systemd unit file.
create-rc-script does allow a couple of parameter to specify the script name, OS user for OUD and the JAVA_HOME. The following example of create-rc-script does show how to create a regular start script for OUD instance oud_ad_proxy.
export OUD_HOME=/u00/app/oracle/instances/oud_ad_proxy export JAVA_HOME=/u00/app/oracle/product/jdk1.7.0_141 cd $OUD_HOME/OUD/bin create-rc-script -f oud_ad_proxy.sh -u oracle -j $JAVA_HOME
This does create the following bornshell script for init.d.
#!/bin/sh # # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. # # # chkconfig: 345 90 30 # description: Oracle Unified Directory startup script # # Set the path to the Oracle Unified Directory instance to manage INSTALL_ROOT="/u00/app/oracle/instances/oud_ad_proxy/OUD" export INSTALL_ROOT # Specify the path to the Java installation to use OPENDS_JAVA_HOME="/u00/app/oracle/product/jdk1.7.0_141" export OPENDS_JAVA_HOME # Determine what action should be performed on the server case "${1}" in start) /bin/su - oracle -- "${INSTALL_ROOT}/bin/start-ds" --quiet exit ${?} ;; stop) /bin/su - oracle -- "${INSTALL_ROOT}/bin/stop-ds" --quiet exit ${?} ;; restart) /bin/su - oracle -- "${INSTALL_ROOT}/bin/stop-ds" --restart --quiet exit ${?} ;; *) echo "Usage: $0 { start | stop | restart }" exit 1 ;; esac
The same start / stop commands can now be used in the unit file. So let’s create a new custom unit file in /etc/systemd/system. The unit file is named according the old instance.
sudo vi /etc/systemd/system/oud_ad_proxy.service
Add the following content to the new unit file.
[Unit] Description=OUD AD Proxy Instance oud_ad_proxy Wants=network.target After=network.target [Service] Type=forking User=oracle Group=osdba Environment=OPENDS_JAVA_HOME="/u00/app/oracle/product/jdk1.7.0_141" ExecStart=/u00/app/oracle/instances/oud_ad_proxy/OUD/bin/start-ds --quiet ExecStop=/u00/app/oracle/instances/oud_ad_proxy/OUD/bin/stop-ds --quiet ExecReload=/u00/app/oracle/instances/oud_ad_proxy/OUD/bin/stop-ds --restart --quiet StandardOutput=syslog [Install] WantedBy=multi-user.target
As soon as we have the new unit file we have to enable the service.
sudo systemctl enable oud_ad_proxy.service
Start the OUD instance using systemctl.
sudo systemctl start oud_ad_proxy.service
Stop the OUD instance using systemctl.
sudo systemctl stop oud_ad_proxy.service
Display the status of the OUD service.
sudo systemctl status oud_ad_proxy.service oud_ad_proxy.service - OUD AD Proxy Instance oud_ad_proxy Loaded: loaded (/etc/systemd/system/oud_ad_proxy.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2017-05-16 22:41:09 CEST; 28s ago Process: 18300 ExecStop=/u00/app/oracle/instances/oud_ad_proxy/OUD/bin/stop-ds --quiet (code=exited, status=0/SUCCESS) Process: 18397 ExecStart=/u00/app/oracle/instances/oud_ad_proxy/OUD/bin/start-ds --quiet (code=exited, status=0/SUCCESS) Main PID: 18477 (java) CGroup: /system.slice/oud_ad_proxy.service └─18477 /u00/app/oracle/product/jdk1.7.0_141/jre/bin/java -server -Dorg.opends.server.scriptName=start-ds org.opends.server.core.DirectoryServer --configClass org.opends.server.extensions.ConfigFileHandler -... May 16 22:41:01 euterpe systemd[1]: Starting OUD AD Proxy Instance oud_ad_proxy... May 16 22:41:09 euterpe systemd[1]: Started OUD AD Proxy Instance oud_ad_proxy.
Some references and links to MOS Notes:
- OUD11g: How to Start OUD Servers on Boot [2019451.1]
- Oracle® Fusion Middleware Administering Oracle Unified Directory 11g Release 2 (11.1.2.3) create-rc-script
- Red Hat Enterprise Linux 7 System Administrator’s Guide Creating and Modifying systemd Unit Files
- Understanding Systemd Units and Unit Files
- Wikipedia systemd
Pingback: Start ODSM on boot using systemd | OraDBA
Pingback: Oracle Unified Directory systemd unit file | OraDBA