tools/scripts/rc.scipio
#!/bin/sh
#####################################################################
# This file is subject to the terms and conditions defined in the\n
# files 'LICENSE' and 'NOTICE', which are part of this source\n
# code package.
#####################################################################
#
# scipio This shell script takes care of starting and stopping
# the Scipio ERP server
#
# chkconfig: - 80 10
# description: Scipio ERP
# Source function library
# this does not exist in Debian/Ubuntu/etc. => see rc.ofbiz.for.debian
# => comment out and use "echo failure" and "echo success" in place of echo_failure and echo_success (minor anyway)
. /etc/rc.d/init.d/functions
# Source networking configuration
# this does not exist in Debian/Ubuntu/etc. => see rc.ofbiz.for.debian
. /etc/sysconfig/network
# Paths - Edit for your locations
JAVA_BINARY=$JAVA_HOME/bin/java
SCIPIO_HOME=/home/scipio/scipioce
# SCIPIO (11/06/2018): Uncomment this to enable console logging
#SCIPIO_LOG=$SCIPIO_HOME/runtime/logs/console.log
# VM Options
JAVA_VMOPTIONS="-Xms128M -Xmx3512M -XX:MaxPermSize=1024m"
# Java arguments
JAVA_ARGS="-Djava.security.egd=file:///dev/./urandom -jar ofbiz.jar"
# *nix user ofbiz should run as (you must create this user first)
SCIPIO_USER=scipio
# Scipio ERP processes running
ofbizprocs() {
SCIPIO_PROCS=`/bin/ps h -o pid,args -C java | /bin/grep -e "$JAVA_ARGS" | /bin/egrep -o "^[[:space:]]*[[:digit:]]*"`
}
# Checking user...
checkuser() {
if [ "$USER" != "$SCIPIO_USER" ]; then
echo_failure
echo
echo "Only users root or $SCIPIO_USER should start/stop the application"
exit 1
fi
}
# Start Scipio ERP
start() {
echo -n "Starting Scipio ERP: "
checkuser
ofbizprocs
if [ "$SCIPIO_PROCS" != "" ]; then
echo_failure
echo
echo "Scipio ERP is already running..."
return 1
fi
# All clear
cd $SCIPIO_HOME
umask 007
if [ "$SCIPIO_LOG" != "" ]; then
/bin/rm -f $SCIPIO_LOG
$JAVA_BINARY $JAVA_VMOPTIONS $JAVA_ARGS >>$SCIPIO_LOG 2>>$SCIPIO_LOG&
else
$JAVA_BINARY $JAVA_VMOPTIONS $JAVA_ARGS > /dev/null 2> 1&
fi
echo_success
return 0
}
# Stop Scipio ERP
stop() {
echo -n "Stopping Scipio ERP: "
checkuser
ofbizprocs
if [ "$SCIPIO_PROCS" == "" ]; then
echo_failure
echo
echo "Scipio ERP is not running..."
return 1
fi
# All clear
cd $SCIPIO_HOME
umask 007
if [ "$SCIPIO_LOG" != "" ]; then
$JAVA_BINARY $JAVA_VMOPTIONS $JAVA_ARGS -shutdown >>$SCIPIO_LOG
else
$JAVA_BINARY $JAVA_VMOPTIONS $JAVA_ARGS -shutdown > /dev/null
fi
ofbizprocs
if [ "$SCIPIO_PROCS" != "" ]; then
# Let's try to -TERM
/bin/kill -TERM $SCIPIO_PROCS
fi
ofbizprocs
if [ "$SCIPIO_PROCS" != "" ]; then
# Let's try it the hard way!
/bin/kill -9 $SCIPIO_PROCS
fi
ofbizprocs
if [ "$SCIPIO_PROCS" != "" ]; then
echo_failure
echo
echo "Some processes could not be stopped:"
echo $SCIPIO_PROCS
echo "A possible solution is to try this command once more!"
return 1
else
echo_success
return 0
fi
}
# If root is running this script, su to $SCIPIO_USER first
# Note that under Debian/Ubuntu/etc. you should use instead
# if [ "$USER" = "root" ]; then
if [ "$UID" = "0" ]; then
exec su - $SCIPIO_USER -c "$0 $1"
fi
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'status')
ofbizprocs
if [ "$SCIPIO_PROCS" == "" ]; then
echo "Scipio ERP is stopped"
exit 1
else
echo "Scipio ERP is running"
exit 0
fi
;;
*)
echo "Usage: $0 {start|stop|kill|restart|status|help}"
exit 1
;;
esac
echo
exit $?