Skip to content

Commit dde41d0

Browse files
author
Dean Troyer
committed
Deprecate SCREEN_LOGDIR in favor of LOGDIR
This is the first step in the log file cleanup. If SCREEN_LOGDIR is still set, symlinks will be created in the old screen log directory so things like the devstack-gate log collector continues to work. bp:logging-and-service-names Change-Id: I3ac796e322a18dbd0b8b2310a08310ca159d7613
1 parent 9e84d09 commit dde41d0

5 files changed

Lines changed: 95 additions & 35 deletions

File tree

doc/source/configuration.rst

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,19 @@ Enable Logging
200200

201201
LOG_COLOR=False
202202

203-
Logging the Screen Output
204-
-------------------------
205-
206-
| *Default: ``SCREEN_LOGDIR=""``*
207-
| By default DevStack runs the OpenStack services using ``screen``
208-
which is useful for watching log and debug output. However, in
209-
automated testing the interactive ``screen`` sessions may not be
210-
available after the fact; setting ``SCREEN_LOGDIR`` enables logging
211-
of the ``screen`` sessions in the specified directory. There will be
212-
one file per ``screen`` session named for the session name and a
213-
timestamp.
203+
Logging the Service Output
204+
--------------------------
205+
206+
| *Default: ``LOGDIR=""``*
207+
| DevStack will log the stdout output of the services it starts.
208+
When using ``screen`` this logs the output in the screen windows
209+
to a file. Without ``screen`` this simply redirects stdout of
210+
the service process to a file in ``LOGDIR``.
214211
|
215212
216213
::
217214

218-
SCREEN_LOGDIR=$DEST/logs/screen
215+
LOGDIR=$DEST/logs
219216

220217
*Note the use of ``DEST`` to locate the main install directory; this
221218
is why we suggest setting it in ``local.conf``.*
@@ -413,8 +410,8 @@ Examples
413410
FIXED_RANGE=10.254.1.0/24
414411
NETWORK_GATEWAY=10.254.1.1
415412
LOGDAYS=1
416-
LOGFILE=$DEST/logs/stack.sh.log
417-
SCREEN_LOGDIR=$DEST/logs/screen
413+
LOGDIR=$DEST/logs
414+
LOGFILE=$LOGDIR/stack.sh.log
418415
ADMIN_PASSWORD=quiet
419416
DATABASE_PASSWORD=$ADMIN_PASSWORD
420417
RABBIT_PASSWORD=$ADMIN_PASSWORD

functions-common

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ function err {
319319
set +o xtrace
320320
local msg="[ERROR] ${BASH_SOURCE[2]}:$1 $2"
321321
echo $msg 1>&2;
322-
if [[ -n ${SCREEN_LOGDIR} ]]; then
323-
echo $msg >> "${SCREEN_LOGDIR}/error.log"
322+
if [[ -n ${LOGDIR} ]]; then
323+
echo $msg >> "${LOGDIR}/error.log"
324324
fi
325325
$xtrace
326326
return $exitcode
@@ -372,8 +372,8 @@ function warn {
372372
set +o xtrace
373373
local msg="[WARNING] ${BASH_SOURCE[2]}:$1 $2"
374374
echo $msg 1>&2;
375-
if [[ -n ${SCREEN_LOGDIR} ]]; then
376-
echo $msg >> "${SCREEN_LOGDIR}/error.log"
375+
if [[ -n ${LOGDIR} ]]; then
376+
echo $msg >> "${LOGDIR}/error.log"
377377
fi
378378
$xtrace
379379
return $exitcode
@@ -1261,8 +1261,8 @@ function zypper_install {
12611261
# _run_process() is designed to be backgrounded by run_process() to simulate a
12621262
# fork. It includes the dirty work of closing extra filehandles and preparing log
12631263
# files to produce the same logs as screen_it(). The log filename is derived
1264-
# from the service name and global-and-now-misnamed ``SCREEN_LOGDIR``
1265-
# Uses globals ``CURRENT_LOG_TIME``, ``SCREEN_LOGDIR``, ``SCREEN_NAME``, ``SERVICE_DIR``
1264+
# from the service name.
1265+
# Uses globals ``CURRENT_LOG_TIME``, ``LOGDIR``, ``SCREEN_LOGDIR``, ``SCREEN_NAME``, ``SERVICE_DIR``
12661266
# If an optional group is provided sg will be used to set the group of
12671267
# the command.
12681268
# _run_process service "command-line" [group]
@@ -1277,9 +1277,14 @@ function _run_process {
12771277
exec 3>&-
12781278
exec 6>&-
12791279

1280-
if [[ -n ${SCREEN_LOGDIR} ]]; then
1281-
exec 1>&${SCREEN_LOGDIR}/screen-${service}.log.${CURRENT_LOG_TIME} 2>&1
1282-
ln -sf ${SCREEN_LOGDIR}/screen-${service}.log.${CURRENT_LOG_TIME} ${SCREEN_LOGDIR}/screen-${service}.log
1280+
local real_logfile="${LOGDIR}/${service}.log.${CURRENT_LOG_TIME}"
1281+
if [[ -n ${LOGDIR} ]]; then
1282+
exec 1>&"$real_logfile" 2>&1
1283+
ln -sf "$real_logfile" ${LOGDIR}/${service}.log
1284+
if [[ -n ${SCREEN_LOGDIR} ]]; then
1285+
# Drop the backward-compat symlink
1286+
ln -sf "$real_logfile" ${SCREEN_LOGDIR}/screen-${service}.log
1287+
fi
12831288

12841289
# TODO(dtroyer): Hack to get stdout from the Python interpreter for the logs.
12851290
export PYTHONUNBUFFERED=1
@@ -1343,7 +1348,7 @@ function run_process {
13431348
}
13441349

13451350
# Helper to launch a process in a named screen
1346-
# Uses globals ``CURRENT_LOG_TIME``, ``SCREEN_NAME``, ``SCREEN_LOGDIR``,
1351+
# Uses globals ``CURRENT_LOG_TIME``, ```LOGDIR``, ``SCREEN_LOGDIR``, `SCREEN_NAME``,
13471352
# ``SERVICE_DIR``, ``USE_SCREEN``
13481353
# screen_process name "command-line" [group]
13491354
# Run a command in a shell in a screen window, if an optional group
@@ -1362,10 +1367,18 @@ function screen_process {
13621367

13631368
screen -S $SCREEN_NAME -X screen -t $name
13641369

1365-
if [[ -n ${SCREEN_LOGDIR} ]]; then
1366-
screen -S $SCREEN_NAME -p $name -X logfile ${SCREEN_LOGDIR}/screen-${name}.log.${CURRENT_LOG_TIME}
1370+
local real_logfile="${LOGDIR}/${name}.log.${CURRENT_LOG_TIME}"
1371+
echo "LOGDIR: $LOGDIR"
1372+
echo "SCREEN_LOGDIR: $SCREEN_LOGDIR"
1373+
echo "log: $real_logfile"
1374+
if [[ -n ${LOGDIR} ]]; then
1375+
screen -S $SCREEN_NAME -p $name -X logfile "$real_logfile"
13671376
screen -S $SCREEN_NAME -p $name -X log on
1368-
ln -sf ${SCREEN_LOGDIR}/screen-${name}.log.${CURRENT_LOG_TIME} ${SCREEN_LOGDIR}/screen-${name}.log
1377+
ln -sf "$real_logfile" ${LOGDIR}/${name}.log
1378+
if [[ -n ${SCREEN_LOGDIR} ]]; then
1379+
# Drop the backward-compat symlink
1380+
ln -sf "$real_logfile" ${SCREEN_LOGDIR}/screen-${1}.log
1381+
fi
13691382
fi
13701383

13711384
# sleep to allow bash to be ready to be send the command - we are
@@ -1410,8 +1423,8 @@ function screen_rc {
14101423
echo "screen -t $1 bash" >> $SCREENRC
14111424
echo "stuff \"$2$NL\"" >> $SCREENRC
14121425

1413-
if [[ -n ${SCREEN_LOGDIR} ]]; then
1414-
echo "logfile ${SCREEN_LOGDIR}/screen-${1}.log.${CURRENT_LOG_TIME}" >>$SCREENRC
1426+
if [[ -n ${LOGDIR} ]]; then
1427+
echo "logfile ${LOGDIR}/${1}.log.${CURRENT_LOG_TIME}" >>$SCREENRC
14151428
echo "log on" >>$SCREENRC
14161429
fi
14171430
fi

lib/dstat

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ DSTAT_FILE=${DSTAT_FILE:-"dstat.log"}
2727
function start_dstat {
2828
# A better kind of sysstat, with the top process per time slice
2929
DSTAT_OPTS="-tcmndrylpg --top-cpu-adv --top-io-adv"
30-
if [[ -n ${SCREEN_LOGDIR} ]]; then
31-
screen_it dstat "cd $TOP_DIR; dstat $DSTAT_OPTS | tee $SCREEN_LOGDIR/$DSTAT_FILE"
30+
if [[ -n ${LOGDIR} ]]; then
31+
screen_it dstat "cd $TOP_DIR; dstat $DSTAT_OPTS | tee $LOGDIR/$DSTAT_FILE"
32+
if [[ -n ${SCREEN_LOGDIR} ]]; then
33+
# Drop the backward-compat symlink
34+
ln -sf $LOGDIR/$DSTAT_FILE ${SCREEN_LOGDIR}/$DSTAT_FILE
35+
fi
3236
else
3337
screen_it dstat "dstat $DSTAT_OPTS"
3438
fi

stack.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,8 @@ fi
373373
# Append '.xxxxxxxx' to the given name to maintain history
374374
# where 'xxxxxxxx' is a representation of the date the file was created
375375
TIMESTAMP_FORMAT=${TIMESTAMP_FORMAT:-"%F-%H%M%S"}
376-
if [[ -n "$LOGFILE" || -n "$SCREEN_LOGDIR" ]]; then
377-
LOGDAYS=${LOGDAYS:-7}
378-
CURRENT_LOG_TIME=$(date "+$TIMESTAMP_FORMAT")
379-
fi
376+
LOGDAYS=${LOGDAYS:-7}
377+
CURRENT_LOG_TIME=$(date "+$TIMESTAMP_FORMAT")
380378

381379
if [[ -n "$LOGFILE" ]]; then
382380
# Clean up old log files. Append '.*' to the user-specified
@@ -428,6 +426,7 @@ fi
428426
# ``screen-$SERVICE_NAME-$TIMESTAMP.log`` in that dir and have a link
429427
# ``screen-$SERVICE_NAME.log`` to the latest log file.
430428
# Logs are kept for as long specified in ``LOGDAYS``.
429+
# This is deprecated....logs go in ``LOGDIR``, only symlinks will be here now.
431430
if [[ -n "$SCREEN_LOGDIR" ]]; then
432431

433432
# We make sure the directory is created.

stackrc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,53 @@ USE_SSL=$(trueorfalse False USE_SSL)
705705

706706
# Following entries need to be last items in file
707707

708+
# Compatibility bits required by other callers like Grenade
709+
710+
# Old way was using SCREEN_LOGDIR to locate those logs and LOGFILE for the stack.sh trace log.
711+
# LOGFILE SCREEN_LOGDIR output
712+
# not set not set no log files
713+
# set not set stack.sh log to LOGFILE
714+
# not set set screen logs to SCREEN_LOGDIR
715+
# set set stack.sh log to LOGFILE, screen logs to SCREEN_LOGDIR
716+
717+
# New way is LOGDIR for all logs and LOGFILE for stack.sh trace log, but if not fully-qualified will be in LOGDIR
718+
# LOGFILE LOGDIR output
719+
# not set not set (new) set LOGDIR from default
720+
# set not set stack.sh log to LOGFILE, (new) set LOGDIR from LOGFILE
721+
# not set set screen logs to LOGDIR
722+
# set set stack.sh log to LOGFILE, screen logs to LOGDIR
723+
724+
# For compat, if SCREEN_LOGDIR is set, it will be used to create back-compat symlinks to the LOGDIR
725+
# symlinks to SCREEN_LOGDIR (compat)
726+
727+
728+
# Set up new logging defaults
729+
if [[ -z "${LOGDIR:-}" ]]; then
730+
default_logdir=$DEST/logs
731+
if [[ -z "${LOGFILE:-}" ]]; then
732+
# Nothing is set, we need a default
733+
LOGDIR="$default_logdir"
734+
else
735+
# Set default LOGDIR
736+
LOGDIR="${LOGFILE%/*}"
737+
logfile="${LOGFILE##*/}"
738+
if [[ -z "$LOGDIR" || "$LOGDIR" == "$logfile" ]]; then
739+
# LOGFILE had no path, set a default
740+
LOGDIR="$default_logdir"
741+
fi
742+
743+
# Check for duplication
744+
if [[ "${SCREEN_LOGDIR:-}" == "${LOGDIR}" ]]; then
745+
# We don't need the symlinks since it's the same directory
746+
unset SCREEN_LOGDIR
747+
fi
748+
fi
749+
unset default_logdir logfile
750+
fi
751+
752+
# LOGDIR is always set at this point so it is not useful as a 'enable' for service logs
753+
# SCREEN_LOGDIR may be set, it is useful to enable the compat symlinks
754+
708755
# Local variables:
709756
# mode: shell-script
710757
# End:

0 commit comments

Comments
 (0)