2014-03-22 07:38:17 +07:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright (c) 2014 Carlos Ruiz - GlobalQSS
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# System startup script for iDempiere
|
|
|
|
#
|
|
|
|
# LSB compatible service control script; see http://www.linuxbase.org/spec/
|
|
|
|
#
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: idempiere
|
|
|
|
# Required-Start:
|
|
|
|
# Required-Stop:
|
|
|
|
# Default-Start: 3 5
|
2020-09-09 00:37:00 +07:00
|
|
|
# Default-Stop:
|
2014-03-22 07:38:17 +07:00
|
|
|
# Description: Start the iDempiere server
|
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
# initialization
|
|
|
|
# adjust these variables to your environment
|
|
|
|
IDEMPIERE_HOME=/opt/idempiere-server
|
|
|
|
IDEMPIEREUSER=idempiere
|
2018-11-29 15:11:48 +07:00
|
|
|
export TELNET_PORT=12612
|
2014-03-22 07:38:17 +07:00
|
|
|
# Instead of using ENVFILE you can set JAVA_HOME, IDEMPIERE_HOME and add JAVA_HOME/bin to PATH
|
|
|
|
# in this case you can comment the source lines for ENVFILE below
|
|
|
|
# detected some problems with Hardy Heron ubuntu using the bash source command
|
|
|
|
ENVFILE=$IDEMPIERE_HOME/utils/myEnvironment.sh
|
|
|
|
|
|
|
|
# Shell functions sourced from /etc/rc.status:
|
|
|
|
# rc_check check and set local and overall rc status
|
|
|
|
# rc_status check and set local and overall rc status
|
|
|
|
# rc_status -v ditto but be verbose in local rc status
|
|
|
|
# rc_status -v -r ditto and clear the local rc status
|
|
|
|
# rc_failed set local and overall rc status to failed
|
|
|
|
# rc_reset clear local rc status (overall remains)
|
|
|
|
# rc_exit exit appropriate to overall rc status
|
|
|
|
. /etc/rc.status
|
|
|
|
|
|
|
|
# The echo return value for success (defined in /etc/rc.config).
|
|
|
|
rc_reset
|
|
|
|
|
|
|
|
# Return values acc. to LSB for all commands but status:
|
|
|
|
# 0 - success
|
|
|
|
# 1 - generic or unspecified error
|
|
|
|
# 2 - invalid or excess argument(s)
|
|
|
|
# 3 - unimplemented feature (e.g. "reload")
|
|
|
|
# 4 - insufficient privilege
|
|
|
|
# 5 - program is not installed
|
|
|
|
# 6 - program is not configured
|
|
|
|
# 7 - program is not running
|
2020-09-09 00:37:00 +07:00
|
|
|
#
|
2014-03-22 07:38:17 +07:00
|
|
|
# Note that starting an already running service, stopping
|
|
|
|
# or restarting a not-running service as well as the restart
|
|
|
|
# with force-reload (in case signalling is not supported) are
|
|
|
|
# considered a success.
|
|
|
|
|
2020-09-09 00:37:00 +07:00
|
|
|
#
|
2014-03-22 07:38:17 +07:00
|
|
|
IDEMPIERESTATUS=
|
2020-09-09 00:37:00 +07:00
|
|
|
MAXITERATIONS=60
|
2014-03-22 07:38:17 +07:00
|
|
|
|
|
|
|
getidempierestatus() {
|
2018-11-29 15:11:48 +07:00
|
|
|
IDEMPIERESTATUSSTRING=$(ps ax | grep java | grep ${IDEMPIERE_HOME} | grep -v grep)
|
2020-09-09 00:37:00 +07:00
|
|
|
echo "$IDEMPIERESTATUSSTRING" | grep -q ${IDEMPIERE_HOME}
|
2014-03-22 07:38:17 +07:00
|
|
|
IDEMPIERESTATUS=$?
|
|
|
|
}
|
|
|
|
|
|
|
|
start () {
|
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -eq 0 ] ; then
|
|
|
|
echo "iDempiere is already running"
|
|
|
|
rc_failed 0
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo -n "Starting iDempiere ERP: "
|
2020-09-09 00:37:00 +07:00
|
|
|
cd $IDEMPIERE_HOME/utils || exit
|
2021-01-08 23:00:59 +07:00
|
|
|
export ID_ENV=Server
|
2020-09-09 00:37:00 +07:00
|
|
|
. $ENVFILE
|
|
|
|
export LOGFILE=$IDEMPIERE_HOME/log/idempiere_$(date +%Y%m%d%H%M%S).log
|
2015-05-04 23:18:02 +07:00
|
|
|
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 &"
|
2014-03-22 07:38:17 +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
|
2020-09-09 00:37:00 +07:00
|
|
|
grep -q '.*LoggedSessionListener.contextInitialized: context initialized.*' < "$LOGFILE" && STATUSTEST=1
|
2014-03-22 07:38:17 +07:00
|
|
|
echo -n "."
|
2020-09-09 00:37:00 +07:00
|
|
|
ITERATIONS=$((ITERATIONS + 1))
|
2014-03-22 07:38:17 +07:00
|
|
|
if [ $ITERATIONS -gt $MAXITERATIONS ]
|
|
|
|
then
|
|
|
|
break
|
|
|
|
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"
|
|
|
|
rc_failed 1
|
|
|
|
else
|
|
|
|
echo "Service started"
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
echo "Service not started"
|
|
|
|
rc_failed 1
|
|
|
|
fi
|
|
|
|
rc_status -v
|
|
|
|
}
|
|
|
|
|
|
|
|
stop () {
|
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -ne 0 ] ; then
|
|
|
|
echo "iDempiere is already stopped"
|
|
|
|
rc_failed 0
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo -n "Stopping iDempiere ERP: "
|
2020-09-09 00:37:00 +07:00
|
|
|
cd $IDEMPIERE_HOME/utils || exit
|
2021-01-08 23:00:59 +07:00
|
|
|
export ID_ENV=Server
|
2016-05-31 11:24:51 +07:00
|
|
|
. $ENVFILE
|
|
|
|
# try shutdown from OSGi console, then direct kill with signal 15, then signal 9
|
|
|
|
log_warning_msg "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
|
2014-03-22 07:38:17 +07:00
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -ne 0 ] ; then
|
2016-05-31 11:24:51 +07:00
|
|
|
echo "Service stopped with OSGi shutdown"
|
2014-03-22 07:38:17 +07:00
|
|
|
else
|
2016-05-31 11:24:51 +07:00
|
|
|
echo "Trying direct kill with signal -15"
|
2020-09-09 00:37:00 +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 "Service stopped with kill -15"
|
|
|
|
else
|
|
|
|
echo "Trying direct kill with signal -9"
|
2020-09-09 00:37:00 +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 "Service stopped with kill -9"
|
|
|
|
else
|
|
|
|
echo "Service hasn't stopped"
|
|
|
|
rc_failed 1
|
|
|
|
fi
|
|
|
|
fi
|
2014-03-22 07:38:17 +07:00
|
|
|
fi
|
|
|
|
rc_status -v
|
|
|
|
}
|
|
|
|
|
|
|
|
restart () {
|
|
|
|
stop
|
2018-06-18 16:36:40 +07:00
|
|
|
sleep 2
|
2014-03-22 07:38:17 +07:00
|
|
|
start
|
|
|
|
rc_status
|
|
|
|
}
|
|
|
|
|
|
|
|
condrestart () {
|
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -eq 0 ] ; then
|
|
|
|
restart
|
|
|
|
else
|
|
|
|
rc_reset # Not running is not a failure.
|
|
|
|
fi
|
|
|
|
rc_status
|
|
|
|
}
|
|
|
|
|
|
|
|
status () {
|
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -eq 0 ] ; then
|
|
|
|
echo
|
|
|
|
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/'
|
2014-03-22 07:38:17 +07:00
|
|
|
echo
|
|
|
|
else
|
|
|
|
echo "iDempiere is stopped"
|
|
|
|
rc_failed 3
|
|
|
|
fi
|
|
|
|
rc_status -v
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
restart
|
|
|
|
;;
|
|
|
|
condrestart)
|
|
|
|
condrestart
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status
|
|
|
|
;;
|
|
|
|
*)
|
2020-09-09 00:37:00 +07:00
|
|
|
echo "Usage: $0 {start|stop|restart|condrestart|status}"
|
2014-03-22 07:38:17 +07:00
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Inform the caller not only verbosely and set an exit status.
|
|
|
|
rc_exit
|