#!/bin/bash

. ./param_bash.ini

clear

START "Starting Rosetta Servers" "$0"

if [ ! -w /etc/passwd ] && [ "$USER" != "$MAIN_USER" ] ; then
	ERROR "Run the script as $MAIN_USER user or root user" "$0"
fi

MainUserExist
if [ "$?" = "1" ] ; then 
	ERROR "$MAIN_USER user does not exist" "$0"
fi

if [ ! -d $APP_HOME/$SOFT_DIR$SLOT_NUMBER ] ; then
	ERROR "The directory ${APP_HOME}/${SOFT_DIR}$SLOT_NUMBER does not exist on the server" "$0"
fi

$PS | grep -v grep | grep ${SOFT_DIR}$SLOT_NUMBER > /dev/null 2>&1
if [ "$?" != "0" ] ; then
	if [ ! -w /etc/passwd ] ; then
		csh -f dps_startup.csh '${APP_HOME}/${SOFT_DIR}${SLOT_NUMBER}/profile' '$SOFT_DIR$SLOT_NUMBER' '$PS' >> $gen_log 2>&1
	else
		su $param_to_su $MAIN_USER -c "csh -f dps_startup.csh '${APP_HOME}/${SOFT_DIR}${SLOT_NUMBER}/profile' '$SOFT_DIR$SLOT_NUMBER' '$PS'" >> $gen_log 2>&1  
	fi
	if [ "$?" = "0" ] ; then 
		INFORM "The Rosetta servers were started"
	else
		ERROR "Failed to startup the Rosetta servers" "$0"
	fi
else
	INFORM "The Rosetta server is already up" 
fi

echo "Rosetta 2.1 installation - The Rosetta software was started correctly" | $MAIL_UTIL -s "The Rosetta installation automated message" $MAIL

DONE "The Rosetta software was started correctly" "$0"
