From fb7d1b6af5ad23aa5a590fe03c52027a8b9a871c Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Wed, 11 Mar 2015 12:31:00 +0000
Subject: [PATCH] OPENDJ-1772: Check if server is setted up in sysv opendj service

---
 opendj-server-legacy/resource/sysv/opendj |   39 +++++++++++++++++++++++++++++++++++----
 1 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/opendj-server-legacy/resource/sysv/opendj b/opendj-server-legacy/resource/sysv/opendj
index fcfa8f9..5c511a3 100755
--- a/opendj-server-legacy/resource/sysv/opendj
+++ b/opendj-server-legacy/resource/sysv/opendj
@@ -64,7 +64,7 @@
 
 
 # Sets the script vars
-INSTALL_ROOT="/opt/opendj/"
+INSTALL_ROOT="/opt/opendj"
 export INSTALL_ROOT
 DAEMON=opendj
 
@@ -81,8 +81,21 @@
 # Recreates the symlink if needed (/var/run is deleted after reboot (eg. debian)).
 test -h "$PIDFILE" || ln -s $ORIGINPIDFILE $PIDFILE
 
+instance_configured() {
+  if [ -f $INSTALL_ROOT/config/buildinfo ] && [ "$(ls -A $INSTALL_ROOT/config/archived-configs)" ] ; then
+      return 1
+  fi
+
+  return 0
+}
+
 # Starts the server and creates pid file.
 start() {
+    instance_configured
+    if [ $? = 0 ] ; then
+        echo "Instance is not configured. Please run $INSTALL_ROOT/setup"
+        return 1
+    fi
     echo -n "Starting $DAEMON: "
     # Server is running
     if [ -e $PIDFILE ] ; then
@@ -103,6 +116,12 @@
 
 # Stops the server and removes pid file.
 stop() {
+    instance_configured
+    if [ $? = 0 ] ; then
+        echo "Instance is not configured. Please run $INSTALL_ROOT/setup"
+        return 1
+    fi
+
     echo -n "Stopping $DAEMON: "
     if [ -e $PIDFILE ]
     then
@@ -125,6 +144,12 @@
 
 # Displays the service status
 status() {
+    instance_configured
+    if [ $? = 0 ] ; then
+        echo "Instance is not configured. Please run $INSTALL_ROOT/setup"
+        return 1
+    fi
+
     echo -n $"$DAEMON status: "
     if [ -e $PIDFILE ] ; then
         echo "> Running."
@@ -143,9 +168,15 @@
         stop
     ;;
     restart)
-        stop
-        sleep 5
-        start
+        instance_configured
+        if [ $? = 0 ] ; then
+            echo "Instance is not configured. Please run $INSTALL_ROOT/setup"
+            exit 1
+        else
+            stop
+            sleep 5
+            start
+        fi
     ;;
     force-reload)
         # Not implemented.

--
Gitblit v1.10.0