diff options
-rw-r--r-- | packages/base/src/files/bin/policy | 231 | ||||
-rw-r--r-- | packages/docker/src/main/docker/pdpd-entrypoint.sh | 5 | ||||
-rw-r--r-- | policy-management/src/main/server-gen/bin/policy-management-controller | 291 |
3 files changed, 316 insertions, 211 deletions
diff --git a/packages/base/src/files/bin/policy b/packages/base/src/files/bin/policy index b02ac3d9..aa48a994 100644 --- a/packages/base/src/files/bin/policy +++ b/packages/base/src/files/bin/policy @@ -18,89 +18,97 @@ # limitations under the License. # ============LICENSE_END========================================================= -source ${POLICY_HOME}/etc/profile.d/env.sh - function usage() { - echo -n "syntax: $(basename $0) " - echo -n "[--debug] " - echo "status|start|stop" + echo -n "syntax: $(basename $0) " + echo -n "[--debug] " + echo "status|start|stop" } function check_x_file() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi - FILE=$1 - if [[ ! -f ${FILE} || ! -x ${FILE} ]]; then + FILE=$1 + if [[ ! -f ${FILE} || ! -x ${FILE} ]]; then return 1 - fi + fi - return 0 + return 0 } function policy_op() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - operation=$1 - - cd $POLICY_HOME - echo "[drools-pdp-controllers]" - binScript="bin/policy-management-controller" - if check_x_file "${binScript}"; then - trap "rm -f /tmp/out$$" EXIT - ${binScript} ${operation} >/tmp/out$$ - echo " L [${controller}]: $(sed ':a;N;$!ba;s/\n/ /g' /tmp/out$$)" - else - echo " L [${controller}]: -" - fi + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + operation=$1 + + cd $POLICY_HOME + echo "[drools-pdp-controllers]" + if check_x_file "${BIN_SCRIPT}"; then + trap "rm -f /tmp/out$$" EXIT + ${BIN_SCRIPT} ${operation} >/tmp/out$$ + echo " L [${controller}]: $(sed ':a;N;$!ba;s/\n/ /g' /tmp/out$$)" + else + echo " L [${controller}]: -" + fi } function policy_status() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - echo - policy_op "status" - - NUM_CRONS=$(crontab -l 2> /dev/null | wc -l) - echo " ${NUM_CRONS} cron jobs installed." - - echo - echo "[features]" - features status - - local databases=$(ls -d "${POLICY_HOME}"/etc/db/migration/*/ 2> /dev/null) - if [[ -n ${databases} ]]; then - echo "[migration]" - db-migrator -s ALL -o ok - fi - + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + echo + policy_op "status" + + NUM_CRONS=$(crontab -l 2>/dev/null | wc -l) + echo " ${NUM_CRONS} cron jobs installed." + + echo + echo "[features]" + features status + + local databases=$(ls -d "${POLICY_HOME}"/etc/db/migration/*/ 2>/dev/null) + if [[ -n ${databases} ]]; then + echo "[migration]" + db-migrator -s ALL -o ok + fi + } function policy_start() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - policy_op "start" + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + policy_op "start" } +function policy_exec() { + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + cd $POLICY_HOME + if check_x_file "${BIN_SCRIPT}"; then + ${BIN_SCRIPT} "exec" + fi +} function policy_stop() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - policy_op "stop" + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + policy_op "stop" } ######################################################################### @@ -109,56 +117,77 @@ function policy_stop() { ## ######################################################################### -DEBUG=n +source ${POLICY_HOME}/etc/profile.d/env.sh + +if [[ ${DEBUG} == y ]]; then + echo "-- $0 $* --" + set -x +fi + +BIN_SCRIPT="bin/policy-management-controller" OPERATION=none until [[ -z "$1" ]]; do - case $1 in - -d|--debug|debug) DEBUG=y - set -x - ;; - -i|--status|status) OPERATION=status - ;; - -s|--start|start) OPERATION=start - ;; - -h|--stop|stop|--halt|halt) OPERATION=halt - ;; - *) usage - exit 1 - ;; - esac - shift + case $1 in + -d | --debug | debug) + DEBUG=y + set -x + ;; + -i | --status | status) + OPERATION=status + ;; + -s | --start | start) + OPERATION=start + ;; + -x | --exec | exec) + OPERATION=exec + ;; + -h | --stop | stop | --halt | halt) + OPERATION=halt + ;; + *) + usage + exit 1 + ;; + esac + shift done # operation validation case $OPERATION in - status) ;; - start) ;; - halt) ;; - *) echo "invalid operation \(${OPERATION}\): must be in {status|start|stop}"; - usage - exit 1 - ;; +status) ;; +start) ;; +exec) ;; +halt) ;; +*) + echo "invalid operation \(${OPERATION}\): must be in {status|start|stop}" + usage + exit 1 + ;; esac if [[ -z ${POLICY_HOME} ]]; then - echo "error: POLICY_HOME is unset." - exit 1 + echo "error: POLICY_HOME is unset." + exit 1 fi # operation validation case $OPERATION in - status) - policy_status - ;; - start) - policy_start - ;; - halt) - policy_stop - ;; - *) echo "invalid operation \(${OPERATION}\): must be in {status|start|stop}"; - usage - exit 1 - ;; +status) + policy_status + ;; +start) + policy_start + ;; +exec) + policy_exec + ;; +halt) + policy_stop + ;; +*) + echo "invalid operation \(${OPERATION}\): must be in {status|start|stop}" + usage + exit 1 + ;; esac diff --git a/packages/docker/src/main/docker/pdpd-entrypoint.sh b/packages/docker/src/main/docker/pdpd-entrypoint.sh index 1f7b3109..fb98e86a 100644 --- a/packages/docker/src/main/docker/pdpd-entrypoint.sh +++ b/packages/docker/src/main/docker/pdpd-entrypoint.sh @@ -234,9 +234,10 @@ function dockerBoot { set -e - vmBoot + configure - tail -f /dev/null + source "${POLICY_HOME}"/etc/profile.d/env.sh + policy exec } if [[ ${DEBUG} == y ]]; then 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} |