2010-11-04 02:46:38 +07:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2012-06-06 21:13:34 +07:00
|
|
|
# FileName: idempiere.init
|
2010-11-04 02:46:38 +07:00
|
|
|
# Description: adempiere erp software startup and shutdown
|
|
|
|
# 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
|
|
|
|
# $Id: adempiere,v 1.1 2006/03/16 05:00:28 cruiz Exp $
|
|
|
|
|
|
|
|
# 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
|
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=
|
2010-11-04 02:46:38 +07:00
|
|
|
MAXITERATIONS=60 # 2 seconds every iteration, max wait 2 minutes)
|
|
|
|
|
2012-06-06 21:13:34 +07:00
|
|
|
getidempierestatus() {
|
2012-06-20 15:58:04 +07:00
|
|
|
IDEMPIERESTATUSSTRING=$(ps ax | grep -v grep | grep $IDEMPIERE_HOME)
|
|
|
|
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
|
|
|
|
echo -n "Starting ADempiere ERP: "
|
|
|
|
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"
|
2012-06-20 15:58:04 +07:00
|
|
|
su $IDEMPIEREUSER -c "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
|
2012-06-20 15:58:04 +07:00
|
|
|
tail -n 9 $LOGFILE | grep -q '.*WebUIServlet.*started successfully.*' && 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
|
2012-06-20 15:58:04 +07:00
|
|
|
echo "idempiere is already stopped"
|
|
|
|
return 1
|
2010-11-04 02:46:38 +07:00
|
|
|
fi
|
2012-06-20 15:58:04 +07:00
|
|
|
echo -n "Stopping iDempiere ERP: "
|
2010-11-04 02:46:38 +07:00
|
|
|
source $ENVFILE
|
2012-06-20 15:58:04 +07:00
|
|
|
echo "Trying direct kill with signal -15"
|
|
|
|
# Adempiere didn't finish - try direct kill with signal 15, then signal 9
|
2014-01-08 20:21:10 +07:00
|
|
|
kill -15 -`ps ax o pgid,command | grep -v grep | grep $IDEMPIERE_HOME | sed -e 's/^ *//g' | cut -f 1 -d " " | sort -u`
|
2012-06-20 15:58:04 +07:00
|
|
|
sleep 5
|
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -ne 0 ] ; then
|
|
|
|
echo_success
|
2010-11-04 02:46:38 +07:00
|
|
|
else
|
2012-06-20 15:58:04 +07:00
|
|
|
echo "Trying direct kill with signal -9"
|
2014-01-08 20:21:10 +07:00
|
|
|
kill -9 -`ps ax o pgid,command | grep -v grep | grep $IDEMPIERE_HOME | sed -e 's/^ *//g' | cut -f 1 -d " " | sort -u`
|
2012-06-20 15:58:04 +07:00
|
|
|
sleep 5
|
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -ne 0 ] ; then
|
|
|
|
echo_success
|
|
|
|
else
|
|
|
|
echo_warning
|
|
|
|
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
|
2012-06-06 21:13:34 +07:00
|
|
|
echo "idempiere is running:"
|
2012-06-20 15:58:04 +07:00
|
|
|
ps ax | grep -v grep | grep $IDEMPIERE_HOME | sed 's/^[[:space:]]*\([[:digit:]]*\).*:[[:digit:]][[:digit:]][[:space:]]\(.*\)/\1 \2/'
|
2010-11-04 02:46:38 +07:00
|
|
|
echo
|
|
|
|
else
|
2012-06-06 21:13:34 +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
|