2010-11-04 02:46:38 +07:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2012-06-06 21:13:34 +07:00
|
|
|
# FileName: idempiere.init
|
2014-10-29 06:19:18 +07:00
|
|
|
# Description: idempiere erp software startup and shutdown
|
2010-11-04 02:46:38 +07:00
|
|
|
# Vendor: K.K. Alice
|
|
|
|
# Created: 05. April 2004
|
|
|
|
# Author: S. Christians
|
|
|
|
# Updated: Carlos Ruiz - globalqss - tested in Redhat FC4
|
|
|
|
# Carlos Ruiz - globalqss - added timeout review of the log file
|
|
|
|
#
|
2012-06-06 21:13:34 +07:00
|
|
|
# FileTarget: /etc/init.d/idempiere
|
2010-11-04 02:46:38 +07:00
|
|
|
# FileOwner: root.root
|
|
|
|
# FilePerms: 0755
|
|
|
|
#
|
|
|
|
# chkconfig: 2345 97 06
|
2014-10-29 06:19:18 +07:00
|
|
|
# $Id: idempiere,v 1.1 2006/03/16 05:00:28 cruiz Exp $
|
2010-11-04 02:46:38 +07:00
|
|
|
|
|
|
|
# initialization
|
|
|
|
# adjust these variables to your environment
|
2014-03-22 07:38:17 +07:00
|
|
|
IDEMPIERE_HOME=/opt/idempiere-server
|
2012-06-20 15:58:04 +07:00
|
|
|
ENVFILE=$IDEMPIERE_HOME/utils/myEnvironment.sh
|
2012-06-06 21:13:34 +07:00
|
|
|
IDEMPIEREUSER=idempiere
|
2018-11-29 15:11:48 +07:00
|
|
|
export TELNET_PORT=12612
|
2010-11-04 02:46:38 +07:00
|
|
|
|
|
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
|
|
|
|
RETVAL=0
|
2012-06-06 21:13:34 +07:00
|
|
|
IDEMPIERESTATUS=
|
2018-06-18 16:36:40 +07:00
|
|
|
MAXITERATIONS=60 # 2 seconds every iteration, max wait 2 minutes
|
2010-11-04 02:46:38 +07:00
|
|
|
|
2012-06-06 21:13:34 +07:00
|
|
|
getidempierestatus() {
|
2018-11-29 15:11:48 +07:00
|
|
|
IDEMPIERESTATUSSTRING=$(ps ax | grep java | grep ${IDEMPIERE_HOME} | grep -v grep)
|
|
|
|
echo $IDEMPIERESTATUSSTRING | grep -q ${IDEMPIERE_HOME}
|
2012-06-06 21:13:34 +07:00
|
|
|
IDEMPIERESTATUS=$?
|
2010-11-04 02:46:38 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
start () {
|
2012-06-06 21:13:34 +07:00
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -eq 0 ] ; then
|
2012-06-20 15:58:04 +07:00
|
|
|
echo "iDempiere is already running"
|
|
|
|
return 1
|
2010-11-04 02:46:38 +07:00
|
|
|
fi
|
2014-10-29 06:19:18 +07:00
|
|
|
echo -n "Starting iDempiere ERP: "
|
2014-10-02 00:51:47 +07:00
|
|
|
cd $IDEMPIERE_HOME/utils
|
2010-11-04 02:46:38 +07:00
|
|
|
source $ENVFILE
|
2012-06-06 21:13:34 +07:00
|
|
|
export LOGFILE=$IDEMPIERE_HOME/log/idempiere_`date +%Y%m%d%H%M%S`.log
|
|
|
|
su $IDEMPIEREUSER -c "mkdir -p $IDEMPIERE_HOME/log"
|
2018-11-29 15:28:24 +07:00
|
|
|
su $IDEMPIEREUSER -c "export TELNET_PORT=$TELNET_PORT;cd $IDEMPIERE_HOME;$IDEMPIERE_HOME/idempiere-server.sh &> $LOGFILE &"
|
2010-11-04 02:46:38 +07:00
|
|
|
RETVAL=$?
|
|
|
|
if [ $RETVAL -eq 0 ] ; then
|
|
|
|
# wait for server to be confirmed as started in logfile
|
|
|
|
STATUSTEST=0
|
|
|
|
ITERATIONS=0
|
|
|
|
while [ $STATUSTEST -eq 0 ] ; do
|
|
|
|
sleep 2
|
2016-11-12 20:39:20 +07:00
|
|
|
tail -n 9 $LOGFILE | grep -q '.*LoggedSessionListener.contextInitialized: context initialized.*' && STATUSTEST=1
|
2010-11-04 02:46:38 +07:00
|
|
|
echo -n "."
|
|
|
|
ITERATIONS=`expr $ITERATIONS + 1`
|
|
|
|
if [ $ITERATIONS -gt $MAXITERATIONS ]
|
|
|
|
then
|
2012-06-20 15:58:04 +07:00
|
|
|
break
|
2010-11-04 02:46:38 +07:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ $STATUSTEST -eq 0 ]
|
|
|
|
then
|
|
|
|
echo "Service hasn't started within the timeout allowed, please review file $LOGFILE to see the status of the service"
|
|
|
|
echo_warning
|
|
|
|
else
|
|
|
|
echo_success
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
echo_failure
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
stop () {
|
2012-06-06 21:13:34 +07:00
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -ne 0 ] ; then
|
2018-06-18 16:36:40 +07:00
|
|
|
echo "iDempiere is already stopped"
|
2012-06-20 15:58:04 +07:00
|
|
|
return 1
|
2010-11-04 02:46:38 +07:00
|
|
|
fi
|
2012-06-20 15:58:04 +07:00
|
|
|
echo -n "Stopping iDempiere ERP: "
|
2014-10-02 00:51:47 +07:00
|
|
|
cd $IDEMPIERE_HOME/utils
|
2016-05-31 11:24:51 +07:00
|
|
|
source $ENVFILE
|
|
|
|
# try shutdown from OSGi console, then direct kill with signal 15, then signal 9
|
2016-06-06 03:20:59 +07:00
|
|
|
echo "Trying shutdown from OSGi console"
|
2018-11-29 15:11:48 +07:00
|
|
|
( echo exit; echo y; sleep 5 ) | telnet localhost ${TELNET_PORT} > /dev/null 2>&1
|
2012-06-20 15:58:04 +07:00
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -ne 0 ] ; then
|
2016-05-31 11:24:51 +07:00
|
|
|
echo_success
|
2010-11-04 02:46:38 +07:00
|
|
|
else
|
2016-06-06 03:20:59 +07:00
|
|
|
echo "Trying direct kill with signal -15"
|
2018-11-29 15:11:48 +07:00
|
|
|
kill -15 -`ps ax o pgid,command | grep ${IDEMPIERE_HOME} | grep -v grep | sed -e 's/^ *//g' | cut -f 1 -d " " | sort -u`
|
2016-05-31 11:24:51 +07:00
|
|
|
sleep 5
|
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -ne 0 ] ; then
|
|
|
|
echo_success
|
|
|
|
else
|
|
|
|
echo "Trying direct kill with signal -9"
|
2018-11-29 15:11:48 +07:00
|
|
|
kill -9 -`ps ax o pgid,command | grep ${IDEMPIERE_HOME} | grep -v grep | sed -e 's/^ *//g' | cut -f 1 -d " " | sort -u`
|
2016-05-31 11:24:51 +07:00
|
|
|
sleep 5
|
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -ne 0 ] ; then
|
|
|
|
echo_success
|
|
|
|
else
|
|
|
|
echo_warning
|
|
|
|
fi
|
|
|
|
fi
|
2010-11-04 02:46:38 +07:00
|
|
|
fi
|
2012-06-20 15:58:04 +07:00
|
|
|
RETVAL=$?
|
2010-11-04 02:46:38 +07:00
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
restart () {
|
|
|
|
stop
|
|
|
|
sleep 2
|
|
|
|
start
|
|
|
|
}
|
|
|
|
|
|
|
|
condrestart () {
|
2012-06-06 21:13:34 +07:00
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -eq 0 ] ; then
|
2010-11-04 02:46:38 +07:00
|
|
|
restart
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-06-20 15:58:04 +07:00
|
|
|
status () {
|
2012-06-06 21:13:34 +07:00
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -eq 0 ] ; then
|
2010-11-04 02:46:38 +07:00
|
|
|
echo
|
2018-06-18 16:36:40 +07:00
|
|
|
echo "iDempiere is running:"
|
2018-11-29 15:11:48 +07:00
|
|
|
ps ax | grep ${IDEMPIERE_HOME} | grep -v grep | sed 's/^[[:space:]]*\([[:digit:]]*\).*:[[:digit:]][[:digit:]][[:space:]]\(.*\)/\1 \2/'
|
2010-11-04 02:46:38 +07:00
|
|
|
echo
|
|
|
|
else
|
2018-06-18 16:36:40 +07:00
|
|
|
echo "iDempiere is stopped"
|
2010-11-04 02:46:38 +07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
restart
|
|
|
|
;;
|
|
|
|
condrestart)
|
|
|
|
condrestart
|
|
|
|
;;
|
|
|
|
status)
|
2012-06-20 15:58:04 +07:00
|
|
|
status
|
2010-11-04 02:46:38 +07:00
|
|
|
;;
|
|
|
|
*)
|
2014-03-22 07:38:17 +07:00
|
|
|
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
|
2010-11-04 02:46:38 +07:00
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|