diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b28ca8..9fb4ef4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to the Zlux App Server package will be documented in this file. ## v3.0.0 -- Bugfix: ommiting `zowe.logDirectory` forces the app-server to log into the `zowe.runtimeDirectory`. (#317) +- Enhancement: if no `zowe.logDirectory` is defined in config, logging is disabled. (#317) ## v2.17.0 - Enhancement: app-server can now use Zowe's standardized and simplified AT-TLS configuration simply by toggling `zowe.network.server.tls.attls: true` or `components.app-server.zowe.network.server.tls.attls: true`. If you wish to control client tls separately from server tls, you can also use `zowe.network.client.tls.attls` or `components.app-server.zowe.network.client.tls.attls`. (#300) (#303) diff --git a/bin/utils/setup-logs.sh b/bin/utils/setup-logs.sh index 4fb4438..f5d4306 100644 --- a/bin/utils/setup-logs.sh +++ b/bin/utils/setup-logs.sh @@ -7,99 +7,118 @@ # # Copyright Contributors to the Zowe Project. -ZWED_TMP_MSGID='zlux-app-server/bin/utils/setup-logs.sh:' - -if [ -n "$ZWED_NODE_LOG_FILE" ]; then - if [ -n "$ZWED_NODE_LOG_DIR" ]; then - echo "${ZWED_TMP_MSGID} ZWED_NODE_LOG_FILE set (value $ZWED_NODE_LOG_FILE). Ignoring ZWED_NODE_LOG_DIR." +if [ -n "$ZWED_NODE_LOG_FILE" ] +then + if [ -n "$ZWED_NODE_LOG_DIR" ] + then + echo "ZWED_NODE_LOG_FILE set (value $ZWED_NODE_LOG_FILE). Ignoring ZWED_NODE_LOG_DIR." fi else # _FILE was not specified; default filename, and check and maybe default _DIR - if [ -z "$ZWED_NODE_LOG_DIR" ]; then - if [ -d "$ZWE_zowe_logDirectory" ]; then - ZWED_NODE_LOG_DIR=${ZWE_zowe_logDirectory} + if [ -z "$ZWED_NODE_LOG_DIR" ] + then + if [ -d "$ZWE_zowe_logDirectory" ] + then + ZWED_NODE_LOG_DIR=${ZWE_zowe_logDirectory} elif [ -n "${HOME}" ]; then ZWED_NODE_LOG_DIR="${HOME}/.zowe/logs" else - echo "${ZWED_TMP_MSGID} Cannot determine the log directory. Logging disabled." - ZWED_NODE_LOG_FILE="/dev/null" - ZWED_NODE_LOG_DIR= + if [ -z "${ZWE_zowe_runtimeDirectory}" ]; then + ZWED_NODE_LOG_DIR="../log" + else + echo "Cannot determine the log directory. Logging disabled." + ZWED_NODE_LOG_DIR= + ZWED_NODE_LOG_FILE=/dev/null + fi fi fi - if [ -f "$ZWED_NODE_LOG_DIR" ]; then + if [ -f "$ZWED_NODE_LOG_DIR" ] + then ZWED_NODE_LOG_FILE=$ZWED_NODE_LOG_DIR - elif [ ! -d "$ZWED_NODE_LOG_DIR" ] && [ ! -z "$ZWED_NODE_LOG_DIR" ]; then - echo "${ZWED_TMP_MSGID} Will make log directory $ZWED_NODE_LOG_DIR" - mkdir -p $ZWED_NODE_LOG_DIR - if [ $? -ne 0 ]; then - echo "${ZWED_TMP_MSGID} Cannot make log directory. Logging disabled." - ZWED_NODE_LOG_FILE=/dev/null + elif [ ! -d "$ZWED_NODE_LOG_DIR" ] + then + if [ -n "${ZWED_NODE_LOG_DIR}" ]; then + echo "Will make log directory $ZWED_NODE_LOG_DIR" + mkdir -p $ZWED_NODE_LOG_DIR + if [ $? -ne 0 ]; then + echo "Cannot make log directory. Logging disabled." + ZWED_NODE_LOG_FILE=/dev/null + fi fi fi ZLUX_ROTATE_LOGS=0 - if [ -d "$ZWED_NODE_LOG_DIR" ] && [ -z "$ZWED_NODE_LOG_FILE" ]; then + if [ -d "$ZWED_NODE_LOG_DIR" ] && [ -z "$ZWED_NODE_LOG_FILE" ] + then ZWED_NODE_LOG_FILE="$ZWED_NODE_LOG_DIR/appServer-`date +%Y-%m-%d-%H-%M`.log" - if [ -z "$ZWED_NODE_LOGS_TO_KEEP" ]; then + if [ -z "$ZWED_NODE_LOGS_TO_KEEP" ] + then ZWED_NODE_LOGS_TO_KEEP=5 fi echo $ZWED_NODE_LOGS_TO_KEEP|egrep '^\-?[0-9]+$' >/dev/null - if [ $? -ne 0 ]; then - echo "${ZWED_TMP_MSGID} ZWED_NODE_LOGS_TO_KEEP not a number. Defaulting to 5." + if [ $? -ne 0 ] + then + echo "ZWED_NODE_LOGS_TO_KEEP not a number. Defaulting to 5." ZWED_NODE_LOGS_TO_KEEP=5 fi - if [ $ZWED_NODE_LOGS_TO_KEEP -ge 0 ]; then + if [ $ZWED_NODE_LOGS_TO_KEEP -ge 0 ] + then ZLUX_ROTATE_LOGS=1 fi fi #Clean up excess logs, if appropriate. - if [ $ZLUX_ROTATE_LOGS -ne 0 ]; then - for f in `ls -r -1 $ZWED_NODE_LOG_DIR/appServer-*.log 2>/dev/null | tail +$ZWED_NODE_LOGS_TO_KEEP`; do - echo "${ZWED_TMP_MSGID} Removing ${f}" + if [ $ZLUX_ROTATE_LOGS -ne 0 ] + then + for f in `ls -r -1 $ZWED_NODE_LOG_DIR/appServer-*.log 2>/dev/null | tail +$ZWED_NODE_LOGS_TO_KEEP` + do + echo nodeServer.sh removing $f rm -f $f done fi fi ZLUX_NODE_CHECK_DIR="$(dirname "$ZWED_NODE_LOG_FILE")" -if [ ! -d "$ZLUX_NODE_CHECK_DIR" ]; then - echo "${ZWED_TMP_MSGID} ZWED_NODE_LOG_FILE contains nonexistent directories. Creating '${ZLUX_NODE_CHECK_DIR}'" +if [ ! -d "$ZLUX_NODE_CHECK_DIR" ] +then + echo "ZWED_NODE_LOG_FILE contains nonexistent directories. Creating $ZLUX_NODE_CHECK_DIR" mkdir -p $ZLUX_NODE_CHECK_DIR - if [ $? -ne 0 ]; then - echo "${ZWED_TMP_MSGID} Cannot make log directory. Logging disabled." + if [ $? -ne 0 ] + then + echo "Cannot make log directory. Logging disabled." ZWED_NODE_LOG_FILE=/dev/null fi fi #Now sanitize final log filename: if it is relative, make it absolute before cd to js -if [ "$ZWED_NODE_LOG_FILE" != "/dev/null" ]; then +if [ "$ZWED_NODE_LOG_FILE" != "/dev/null" ] +then ZLUX_NODE_CHECK_DIR=$(cd "$(dirname "$ZWED_NODE_LOG_FILE")"; pwd) ZWED_NODE_LOG_FILE=$ZLUX_NODE_CHECK_DIR/$(basename "$ZWED_NODE_LOG_FILE") fi -echo "${ZWED_TMP_MSGID} ZWED_NODE_LOG_FILE=${ZWED_NODE_LOG_FILE}" -if [ ! -z $(echo "${ZWED_NODE_LOG_FILE}" | grep "^${ZWE_zowe_runtimeDirectory}") ]; then - echo "${ZWED_TMP_MSGID} Logging into zowe.runtimeDirectory not allowed. Logging disabled." - ZWED_NODE_LOG_FILE=/dev/null -fi +echo ZWED_NODE_LOG_FILE=${ZWED_NODE_LOG_FILE} -if [ ! -e $ZWED_NODE_LOG_FILE ]; then +if [ ! -e $ZWED_NODE_LOG_FILE ] +then touch $ZWED_NODE_LOG_FILE - if [ $? -ne 0 ]; then - echo "${ZWED_TMP_MSGID} Cannot make log file. Logging disabled." + if [ $? -ne 0 ] + then + echo "Cannot make log file. Logging disabled." ZWED_NODE_LOG_FILE=/dev/null fi else - if [ -d $ZWED_NODE_LOG_FILE ]; then - echo "${ZWED_TMP_MSGID} '${ZWED_NODE_LOG_FILE}' is a directory. Must be a file. Logging disabled." + if [ -d $ZWED_NODE_LOG_FILE ] + then + echo "ZWED_NODE_LOG_FILE is a directory. Must be a file. Logging disabled." ZWED_NODE_LOG_FILE=/dev/null fi fi -if [ ! -w "$ZWED_NODE_LOG_FILE" ]; then - echo "${ZWED_TMP_MSGID} File '${ZWED_NODE_LOG_FILE}' is not writable. Logging disabled." +if [ ! -w "$ZWED_NODE_LOG_FILE" ] +then + echo file "$ZWED_NODE_LOG_FILE" is not writable. Logging disabled. ZWED_NODE_LOG_FILE=/dev/null fi