OpenDJ init scripts for RHEL

OpenDJ comes with a little script that will generate a nice Red Hat Enterprise chkconfig compatible init script for you. Here’s how to use it.


To generate an init script, go into the bin directory under your OpenDJ install and run the “create-rc-script” command (for example /opt/opendj/ds-user1/bin/create-rc-script). Following are some typical use cases.

For a script that will run the directory as a non-root user, in this example “opendj” (where it will listen on ports above 1000):

[root@test1 bin]% ./create-rc-script -u opendj -j /usr/lib/jvm/java -f /etc/init.d/ds-user1

The “-u” option sets the name of the user you want the server to run as.

Once you have generated your script it needs to be copied under /etc/init.d and have chkconfig run against it (as root, “/sbin/chkconfig ds-user1 –add” and then “/sbin/chkconfig ds-user1 on”).

#!/bin/sh
#
# CDDL HEADER START
# 
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
# 
# You can obtain a copy of the license at
# https://OpenDS.dev.java.net/OpenDS.LICENSE.
# See the License for the specific language governing permissions
# and limitations under the License.
# 
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at
# trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
# add the following below this CDDL HEADER, with the fields enclosed
# by brackets "[]" replaced with your own identifying information:
#      Portions Copyright [yyyy] [name of copyright owner]
# 
# CDDL HEADER END
# chkconfig: 345 95 25
# description: Control the OpenDJ Directory Server

# Set the path to the OpenDJ instance to manage
INSTALL_ROOT="/opt/opendj/ds-user1"
export INSTALL_ROOT

cd ${INSTALL_ROOT}

# Specify the path to the Java installation to use
OPENDS_JAVA_HOME="/usr/lib/jvm/java"
export OPENDS_JAVA_HOME

# Determine what action should be performed on the server
case "${1}" in
start)
  /bin/su opendj -c "${INSTALL_ROOT}/bin/start-ds --quiet"
  exit ${?}
  ;;
stop)
  /bin/su opendj -c "${INSTALL_ROOT}/bin/stop-ds --quiet"
  exit ${?}
  ;;
restart)
  /bin/su opendj -c "${INSTALL_ROOT}/bin/stop-ds --restart --quiet"
  exit ${?}
  ;;
*)
  echo "Usage:  $0 { start | stop | restart }"
  exit 1
  ;;
esac