Allow screen without logging to disk
In some niche setups it is desirable to run OpenStack services under
screen, but undesirable to automatically keep a persistent log from
each service.
Add a new variable SCREEN_IS_LOGGING that controls if screen logs each
window to disk automatically.
Ideally screen itself would be configured to log but just not activate.
This isn't possible with the screerc syntax. Temporary logging can still
be used by a developer with:
C-a : logfile foo
C-a : log on
Change-Id: I2a3abf15dea95ae99ddbdfe1309382df601b7d93
diff --git a/functions-common b/functions-common
index ca0543d..ba3c791 100644
--- a/functions-common
+++ b/functions-common
@@ -1366,7 +1366,7 @@
# Helper to launch a process in a named screen
# Uses globals ``CURRENT_LOG_TIME``, ```LOGDIR``, ``SCREEN_LOGDIR``, `SCREEN_NAME``,
-# ``SERVICE_DIR``, ``USE_SCREEN``
+# ``SERVICE_DIR``, ``USE_SCREEN``, ``SCREEN_IS_LOGGING``
# screen_process name "command-line" [group]
# Run a command in a shell in a screen window, if an optional group
# is provided, use sg to set the group of the command.
@@ -1386,8 +1386,12 @@
echo "SCREEN_LOGDIR: $SCREEN_LOGDIR"
echo "log: $real_logfile"
if [[ -n ${LOGDIR} ]]; then
- screen -S $SCREEN_NAME -p $name -X logfile "$real_logfile"
- screen -S $SCREEN_NAME -p $name -X log on
+ if [[ "$SCREEN_IS_LOGGING" == "True" ]]; then
+ screen -S $SCREEN_NAME -p $name -X logfile "$real_logfile"
+ screen -S $SCREEN_NAME -p $name -X log on
+ fi
+ # If logging isn't active then avoid a broken symlink
+ touch "$real_logfile"
ln -sf "$real_logfile" ${LOGDIR}/${name}.log
if [[ -n ${SCREEN_LOGDIR} ]]; then
# Drop the backward-compat symlink
@@ -1426,7 +1430,7 @@
}
# Screen rc file builder
-# Uses globals ``SCREEN_NAME``, ``SCREENRC``
+# Uses globals ``SCREEN_NAME``, ``SCREENRC``, ``SCREEN_IS_LOGGING``
# screen_rc service "command-line"
function screen_rc {
SCREEN_NAME=${SCREEN_NAME:-stack}
@@ -1446,7 +1450,7 @@
echo "screen -t $1 bash" >> $SCREENRC
echo "stuff \"$2$NL\"" >> $SCREENRC
- if [[ -n ${LOGDIR} ]]; then
+ if [[ -n ${LOGDIR} ]] && [[ "$SCREEN_IS_LOGGING" == "True" ]]; then
echo "logfile ${LOGDIR}/${1}.log.${CURRENT_LOG_TIME}" >>$SCREENRC
echo "log on" >>$SCREENRC
fi