aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2020-07-15 19:05:34 +0000
committerGerrit Code Review <gerrit@onap.org>2020-07-15 19:05:34 +0000
commita7aa5467c72ebb4df47487797e546c01bb040089 (patch)
treef0b02971a8ee9fbdbdeb1aab1a7862e27d993058 /policy-management
parent99baab38585a1d3cbfccb6383f4cb9b77bddf7a3 (diff)
parent77d4b439b198ec7a08d714770c0e94a1f1fab0ec (diff)
Merge "exec pdp-d java process to run in the foreground"
Diffstat (limited to 'policy-management')
-rw-r--r--policy-management/src/main/server-gen/bin/policy-management-controller291
1 files changed, 183 insertions, 108 deletions
diff --git a/policy-management/src/main/server-gen/bin/policy-management-controller b/policy-management/src/main/server-gen/bin/policy-management-controller
index 56db98df..1d9633bc 100644
--- a/policy-management/src/main/server-gen/bin/policy-management-controller
+++ b/policy-management/src/main/server-gen/bin/policy-management-controller
@@ -24,29 +24,27 @@ SNAME="Policy Management"
PNAME=policy-management
CLASS=org.onap.policy.drools.system.Main
-
function start() {
- um_start
- if [[ ${RETVAL} != 0 ]]; then
- update_monitor off
- else
- update_monitor on
- fi
+ if [[ $DEBUG == y ]]; then
+ echo "-- ${FUNCNAME[0]} --"
+ set -x
+ fi
+
+ um_start
+ if [[ ${RETVAL} != 0 ]]; then
+ update_monitor off
+ else
+ update_monitor on
+ fi
}
-# unmonitored start, does not change monitor status (immutable)
-function um_start() {
- status
- if [ "$_RUNNING" = "1" ]; then
- echo $_STATUS
- RETVAL=0
- return
+function preRunning() {
+ if [[ $DEBUG == y ]]; then
+ echo "-- ${FUNCNAME[0]} --"
+ set -x
fi
+
mkdir -p $_LOGS
- if [ -e $_LOGS/$PNAME.out.1 ]; then mv $_LOGS/$PNAME.out.1 $_LOGS/$PNAME.out.2; fi
- if [ -e $_LOGS/$PNAME.err.1 ]; then mv $_LOGS/$PNAME.err.1 $_LOGS/$PNAME.err.2; fi
- if [ -e $_LOGS/$PNAME.out ]; then mv $_LOGS/$PNAME.out $_LOGS/$PNAME.out.1; fi
- if [ -e $_LOGS/$PNAME.err ]; then mv $_LOGS/$PNAME.err $_LOGS/$PNAME.err.1; fi
CP=$(ls $_DIR/lib/*.jar | xargs -I X printf ":%s" X)
# pick up any new changes in the environment every time we start
@@ -59,92 +57,153 @@ function um_start() {
# Note that the following also handles property values with spaces.
IFS=$'\n'
systemProperties=($(
- if [[ -f $_DIR/config/system.properties ]] ; then
+ if [[ -f $_DIR/config/system.properties ]]; then
sed -n -e 's/^[ \t]*\([^ \t#]*\)[ \t]*=[ \t]*\(.*\)$/-D\1=\2/p' \
$_DIR/config/system.properties
fi
))
cd $_DIR
+
+}
+
+function exec_start() {
+ if [[ $DEBUG == y ]]; then
+ echo "-- ${FUNCNAME[0]} --"
+ set -x
+ fi
+
+ status
+ echo "$_STATUS"
+ if [ "$_RUNNING" = "1" ]; then
+ exit 1
+ fi
+
+ preRunning
+ exec $JAVA_HOME/bin/java "${JVM_OPTS[@]}" -cp $_DIR/config:$_DIR/lib:$CP "${systemProperties[@]}" "$@" $CLASS
+}
+
+# unmonitored start, does not change monitor status (immutable)
+function um_start() {
+ if [[ $DEBUG == y ]]; then
+ echo "-- ${FUNCNAME[0]} --"
+ set -x
+ fi
+
+ status
+ if [ "$_RUNNING" = "1" ]; then
+ echo ""
+ RETVAL=1
+ return
+ fi
+
+ preRunning
+ if [ -e $_LOGS/$PNAME.out.1 ]; then mv $_LOGS/$PNAME.out.1 $_LOGS/$PNAME.out.2; fi
+ if [ -e $_LOGS/$PNAME.err.1 ]; then mv $_LOGS/$PNAME.err.1 $_LOGS/$PNAME.err.2; fi
+ if [ -e $_LOGS/$PNAME.out ]; then mv $_LOGS/$PNAME.out $_LOGS/$PNAME.out.1; fi
+ if [ -e $_LOGS/$PNAME.err ]; then mv $_LOGS/$PNAME.err $_LOGS/$PNAME.err.1; fi
+
(
- if [[ "${cfg}" != "" ]] ; then
- # need to make sure that we don't pass the lock file descriptor
- # to subprocesses
- exec {cfg}>&-
- fi
- nohup $JAVA_HOME/bin/java "${JVM_OPTS[@]}" -cp $_DIR/config:$_DIR/lib:$CP "${systemProperties[@]}" "$@" $CLASS > >( while read line; do echo "$(date): ${line}"; done > $_LOGS/$PNAME.out) 2> >( while read line; do echo "$(date): ${line}"; done > $_LOGS/$PNAME.err) &
-
- _PID=$!
- echo $_PID > $_PIDFILE
+ if [[ "${cfg}" != "" ]]; then
+ # need to make sure that we don't pass the lock file descriptor
+ # to subprocesses
+ exec {cfg}>&-
+ fi
+ nohup $JAVA_HOME/bin/java "${JVM_OPTS[@]}" -cp $_DIR/config:$_DIR/lib:$CP "${systemProperties[@]}" "$@" $CLASS > >(while read line; do echo "$(date): ${line}"; done >$_LOGS/$PNAME.out) 2> >(while read line; do echo "$(date): ${line}"; done >$_LOGS/$PNAME.err) &
+
+ _PID=$!
+ echo $_PID >$_PIDFILE
)
sleep 5
status
echo $_STATUS
if [ "$_RUNNING" = "1" ]; then
- RETVAL=0
+ RETVAL=0
else
- echo "Failed to start"
- remove_pid_file
- RETVAL=1
+ echo "Failed to start"
+ remove_pid_file
+ RETVAL=1
fi
}
function stop() {
- um_stop
- update_monitor off
+ if [[ $DEBUG == y ]]; then
+ echo "-- ${FUNCNAME[0]} --"
+ set -x
+ fi
+
+ um_stop
+ update_monitor off
}
# unmonitored stop, does not change monitor status (immutable)
function um_stop() {
+ if [[ $DEBUG == y ]]; then
+ echo "-- ${FUNCNAME[0]} --"
+ set -x
+ fi
+
status
if [ "$_RUNNING" = "0" ]; then
- echo $_STATUS
- remove_pid_file
+ echo $_STATUS
+ remove_pid_file
else
- if [[ -n ${TELEMETRY_PASSWORD} ]]; then
- http_proxy= timeout 10 curl -k --silent --user ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} -X DELETE https://localhost:${TELEMETRY_PORT}/policy/pdp/engine -o /dev/null
- else
- http_proxy= timeout 10 curl -k --silent -X DELETE https://localhost:${TELEMETRY_PORT}/policy/pdp/engine -o /dev/null
- fi
- sleep 5
- echo "Stopping $SNAME..."
- _PID_TO_KILL=$_PID;
- echo "$SNAME (pid=${_PID_TO_KILL}) is stopping..."
- kill -TERM $_PID_TO_KILL 2> /dev/null
- sleep 5
- check_status_of_pid $_PID_TO_KILL
- if [ "$_RUNNING" = "1" ]; then
- kill -TERM $_PID_TO_KILL
- fi
- while [ "$_RUNNING" = "1" ]; do
- sleep 2
- check_status_of_pid $_PID_TO_KILL
- done
- remove_pid_file
- echo "$SNAME has stopped."
+ if [[ -n ${TELEMETRY_PASSWORD} ]]; then
+ http_proxy= timeout 10 curl -k --silent --user ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} -X DELETE https://localhost:${TELEMETRY_PORT}/policy/pdp/engine -o /dev/null
+ else
+ http_proxy= timeout 10 curl -k --silent -X DELETE https://localhost:${TELEMETRY_PORT}/policy/pdp/engine -o /dev/null
+ fi
+ sleep 5
+ echo "Stopping $SNAME..."
+ _PID_TO_KILL=$_PID
+ echo "$SNAME (pid=${_PID_TO_KILL}) is stopping..."
+ kill -TERM $_PID_TO_KILL 2>/dev/null
+ sleep 5
+ check_status_of_pid $_PID_TO_KILL
+ if [ "$_RUNNING" = "1" ]; then
+ kill -TERM $_PID_TO_KILL
+ fi
+ while [ "$_RUNNING" = "1" ]; do
+ sleep 2
+ check_status_of_pid $_PID_TO_KILL
+ done
+ remove_pid_file
+ echo "$SNAME has stopped."
fi
RETVAL=0
}
function status() {
+ if [[ $DEBUG == y ]]; then
+ echo "-- ${FUNCNAME[0]} --"
+ set -x
+ fi
+
if [ -f "${_PIDFILE}" ]; then
- _PID=`cat "${_PIDFILE}"`
- check_status_of_pid $_PID
+ _PID=$(cat "${_PIDFILE}")
+ check_status_of_pid "$_PID"
+ elif [[ ${POLICY_DOCKER} == true ]] && _PID=$(pidof -s java); then
+ echo "${_PID}" > ${_PIDFILE}
+ check_status_of_pid "$_PID"
else
_STATUS="$SNAME (no pidfile) is NOT running"
_RUNNING=0
fi
- if [[ $_RUNNING = 1 ]]; then
+
+ if [[ $_RUNNING == 1 ]]; then
RETVAL=0
else
RETVAL=1
fi
}
+function check_status_of_pid() {
+ if [[ $DEBUG == y ]]; then
+ echo "-- ${FUNCNAME[0]} --"
+ set -x
+ fi
-function check_status_of_pid ()
-{
- if [ -n "$1" ] && kill -0 $1 2>/dev/null ; then
+ if [ -n "$1" ] && kill -0 $1 2>/dev/null; then
_STATUS="$SNAME (pid $1) is running"
_RUNNING=1
else
@@ -153,30 +212,43 @@ function check_status_of_pid ()
fi
}
-function remove_pid_file ()
-{
- if [ -f "${_PIDFILE}" ]; then
- rm "${_PIDFILE}"
- fi
+function remove_pid_file() {
+ if [[ $DEBUG == y ]]; then
+ echo "-- ${FUNCNAME[0]} --"
+ set -x
+ fi
+
+ if [ -f "${_PIDFILE}" ]; then
+ rm "${_PIDFILE}"
+ fi
}
function update_monitor() {
- STATUS=$1
- if [[ -f ${POLICY_HOME}/etc/monitor/monitor.cfg ]]; then
- /bin/sed -i.bak \
- -e "s/^${CONTROLLER}=.*/${CONTROLLER}=${STATUS}/g" \
- ${POLICY_HOME}/etc/monitor/monitor.cfg
- fi
-}
+ if [[ $DEBUG == y ]]; then
+ echo "-- ${FUNCNAME[0]} --"
+ set -x
+ fi
+ STATUS=$1
+ if [[ -f ${POLICY_HOME}/etc/monitor/monitor.cfg ]]; then
+ /bin/sed -i.bak \
+ -e "s/^${CONTROLLER}=.*/${CONTROLLER}=${STATUS}/g" \
+ ${POLICY_HOME}/etc/monitor/monitor.cfg
+ fi
+}
# main
+if [[ ${DEBUG} == y ]]; then
+ echo "-- $0 $* --"
+ set -x
+fi
+
_DIR=${POLICY_HOME}
_LOGS=${POLICY_LOGS}
if [[ -z ${POLICY_LOGS} ]]; then
- _LOGS="${POLICY_HOME}"/logs
+ _LOGS="${POLICY_HOME}"/logs
fi
CONTROLLER=policy-management-controller
@@ -186,38 +258,41 @@ RETVAL=0
_PIDFILE=${POLICY_HOME}/PID
case "$1" in
- status)
- status
- echo "$_STATUS"
- ;;
- start)
- if flock ${cfg} ; then
- start
- fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
- ;;
- umstart)
- um_start
- ;;
- stop)
- if flock ${cfg} ; then
- stop
- fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
- ;;
- umstop)
- um_stop
- ;;
- restart)
- if flock ${cfg} ; then
- stop
- sleep 2
- start
- fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
- ;;
- *)
- echo "error: invalid option $@"
- echo "Usage: $0 status|start|stop|restart"
- RETVAL=1
- ;;
+status)
+ status
+ echo "$_STATUS"
+ ;;
+start)
+ if flock ${cfg}; then
+ start
+ fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
+ ;;
+umstart)
+ um_start
+ ;;
+exec)
+ exec_start
+ ;;
+stop)
+ if flock ${cfg}; then
+ stop
+ fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
+ ;;
+umstop)
+ um_stop
+ ;;
+restart)
+ if flock ${cfg}; then
+ stop
+ sleep 2
+ start
+ fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
+ ;;
+*)
+ echo "error: invalid option $@"
+ echo "Usage: $0 status|start|stop|restart"
+ RETVAL=1
+ ;;
esac
exit ${RETVAL}