2010-11-04 02:46:38 +07:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
|
|
|
|
### BEGIN INIT INFO
|
2019-04-20 00:20:05 +07:00
|
|
|
# Provides: idempiere
|
2010-11-04 02:46:38 +07:00
|
|
|
# Required-Start: postgresql
|
|
|
|
# Required-Stop: postgresql
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 1
|
2012-06-06 21:13:34 +07:00
|
|
|
# Short-Description: iDempiere 1.0.0 server
|
2019-04-20 00:20:05 +07:00
|
|
|
# Description: Provides iDempiere ERP-CRM Server startup and shutdown script. Requires PostgreSQL server.
|
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
|
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
# initialization
|
|
|
|
# adjust these variables to your environment
|
2014-03-22 07:38:17 +07:00
|
|
|
IDEMPIERE_HOME=/opt/idempiere-server
|
2012-06-06 21:13:34 +07:00
|
|
|
IDEMPIEREUSER=idempiere
|
2018-11-29 15:11:48 +07:00
|
|
|
export TELNET_PORT=12612
|
2012-06-06 21:13:34 +07:00
|
|
|
# Instead of using ENVFILE you can set JAVA_HOME, IDEMPIERE_HOME and add JAVA_HOME/bin to PATH
|
2010-11-04 02:46:38 +07:00
|
|
|
# in this case you can comment the source lines for ENVFILE below
|
|
|
|
# detected some problems with Hardy Heron ubuntu using the bash source command
|
2012-06-20 15:58:04 +07:00
|
|
|
ENVFILE=$IDEMPIERE_HOME/utils/myEnvironment.sh
|
2010-11-04 02:46:38 +07:00
|
|
|
|
|
|
|
. /lib/lsb/init-functions
|
2020-09-09 00:37:00 +07:00
|
|
|
|
2010-11-04 02:46:38 +07:00
|
|
|
RETVAL=0
|
2012-06-06 21:13:34 +07:00
|
|
|
IDEMPIERESTATUS=
|
2020-09-09 00:37:00 +07:00
|
|
|
MAXITERATIONS=60
|
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)
|
2020-09-09 00:37:00 +07:00
|
|
|
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
|
|
|
|
echo "iDempiere is already running"
|
2010-11-04 02:46:38 +07:00
|
|
|
return 1
|
|
|
|
fi
|
2012-06-06 21:13:34 +07:00
|
|
|
echo -n "Starting iDempiere ERP: "
|
2020-09-09 00:37:00 +07:00
|
|
|
cd $IDEMPIERE_HOME/utils || exit
|
|
|
|
. $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 &"
|
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
|
2020-09-09 00:37:00 +07:00
|
|
|
grep -q '.*LoggedSessionListener.contextInitialized: context initialized.*' < "$LOGFILE" && STATUSTEST=1
|
2010-11-04 02:46:38 +07:00
|
|
|
echo -n "."
|
2020-09-09 00:37:00 +07:00
|
|
|
ITERATIONS=$((ITERATIONS + 1))
|
|
|
|
if [ "$ITERATIONS" -gt $MAXITERATIONS ]
|
2010-11-04 02:46:38 +07:00
|
|
|
then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ $STATUSTEST -eq 0 ]
|
|
|
|
then
|
|
|
|
log_warning_msg "Service hasn't started within the timeout allowed, please review file $LOGFILE to see the status of the service"
|
|
|
|
else
|
|
|
|
log_success_msg "Service started"
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
log_failure_msg "Service not started"
|
|
|
|
echo
|
|
|
|
fi
|
2012-06-20 15:58:04 +07:00
|
|
|
RETVAL=$?
|
2010-11-04 02:46:38 +07:00
|
|
|
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-06 21:13:34 +07:00
|
|
|
echo -n "Stopping iDempiere ERP: "
|
2020-09-09 00:37:00 +07:00
|
|
|
cd $IDEMPIERE_HOME/utils || exit
|
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
|
2012-06-20 15:58:04 +07:00
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -ne 0 ] ; then
|
2016-05-31 11:24:51 +07:00
|
|
|
log_success_msg "Service stopped with OSGi shutdown"
|
2010-11-04 02:46:38 +07:00
|
|
|
else
|
2016-05-31 11:24:51 +07:00
|
|
|
log_warning_msg "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
|
|
|
|
log_success_msg "Service stopped with kill -15"
|
|
|
|
else
|
2016-06-06 03:20:59 +07:00
|
|
|
log_warning_msg "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
|
|
|
|
log_success_msg "Service stopped with kill -9"
|
|
|
|
else
|
|
|
|
log_warning_msg "Service hasn't stopped"
|
|
|
|
fi
|
|
|
|
fi
|
2010-11-04 02:46:38 +07:00
|
|
|
fi
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
restart () {
|
|
|
|
stop
|
2018-06-18 16:36:40 +07:00
|
|
|
sleep 2
|
2010-11-04 02:46:38 +07:00
|
|
|
start
|
|
|
|
}
|
|
|
|
|
|
|
|
condrestart () {
|
2012-06-06 21:13:34 +07:00
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -eq 0 ] ; then
|
2012-06-20 15:58:04 +07:00
|
|
|
restart
|
2010-11-04 02:46:38 +07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-06-20 15:58:04 +07:00
|
|
|
status () {
|
2012-06-06 21:13:34 +07:00
|
|
|
getidempierestatus
|
|
|
|
if [ $IDEMPIERESTATUS -eq 0 ] ; then
|
2012-06-20 15:58:04 +07:00
|
|
|
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/'
|
2012-06-20 15:58:04 +07:00
|
|
|
echo
|
|
|
|
else
|
|
|
|
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
|
|
|
;;
|
|
|
|
*)
|
2020-09-09 00:37:00 +07:00
|
|
|
echo "Usage: $0 {start|stop|restart|condrestart|status}"
|
2010-11-04 02:46:38 +07:00
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|