From e3c391c972aef48c96b972e347af929c167aae30 Mon Sep 17 00:00:00 2001
From: brinn <brinn>
Date: Wed, 17 Aug 2011 08:36:43 +0000
Subject: [PATCH] change: check at server startup of DSS and AS that the user
 who tries to startup the server is not root and exit otherwise

SVN: 22521
---
 datastore_server/dist/datastore_server.sh | 9 +++++++++
 openbis/dist/server/startup.sh            | 5 +++++
 2 files changed, 14 insertions(+)

diff --git a/datastore_server/dist/datastore_server.sh b/datastore_server/dist/datastore_server.sh
index 93f06c6e4bc..80ad1777fb5 100755
--- a/datastore_server/dist/datastore_server.sh
+++ b/datastore_server/dist/datastore_server.sh
@@ -42,6 +42,14 @@ isPIDRunning()
   fi
 }
 
+checkNotRoot()
+{
+  if [ $UID -eq 0 ]; then
+    echo "openBIS Data Store Server cannot run as user 'root'." > /dev/stderr
+    exit 1
+  fi
+}
+
 rotateLogFiles()
 {
   logfile=$1
@@ -143,6 +151,7 @@ CMD="${JAVA_BIN} ${JAVA_OPTS} -classpath $CP ch.systemsx.cisd.openbis.dss.generi
 command="${command#--*}"
 case "$command" in
   start)
+    checkNotRoot
     getStatus
     EXIT_STATUS=$?
     if [ $EXIT_STATUS -eq 0 ]; then
diff --git a/openbis/dist/server/startup.sh b/openbis/dist/server/startup.sh
index aab609826e8..87e75b481f0 100755
--- a/openbis/dist/server/startup.sh
+++ b/openbis/dist/server/startup.sh
@@ -1,5 +1,10 @@
 #! /bin/bash
 
+if [ $UID -eq 0 ]; then
+  echo "openBIS Application Server cannot run as user 'root'." > /dev/stderr
+  exit 1
+fi
+
 source `dirname "$0"`/setup-env
 $JVM -DSTOP.PORT=$JETTY_STOP_PORT \
      -DSTOP.KEY=$JETTY_STOP_KEY \
-- 
GitLab