Browse code

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

Tony Breeds authored on 2015/11/09 08:05:37
Showing 2 changed files
... ...
@@ -1366,7 +1366,7 @@ function run_process {
1366 1366
 
1367 1367
 # Helper to launch a process in a named screen
1368 1368
 # Uses globals ``CURRENT_LOG_TIME``, ```LOGDIR``, ``SCREEN_LOGDIR``, `SCREEN_NAME``,
1369
-# ``SERVICE_DIR``, ``USE_SCREEN``
1369
+# ``SERVICE_DIR``, ``USE_SCREEN``, ``SCREEN_IS_LOGGING``
1370 1370
 # screen_process name "command-line" [group]
1371 1371
 # Run a command in a shell in a screen window, if an optional group
1372 1372
 # is provided, use sg to set the group of the command.
... ...
@@ -1386,8 +1386,12 @@ function screen_process {
1386 1386
     echo "SCREEN_LOGDIR: $SCREEN_LOGDIR"
1387 1387
     echo "log: $real_logfile"
1388 1388
     if [[ -n ${LOGDIR} ]]; then
1389
-        screen -S $SCREEN_NAME -p $name -X logfile "$real_logfile"
1390
-        screen -S $SCREEN_NAME -p $name -X log on
1389
+        if [[ "$SCREEN_IS_LOGGING" == "True" ]]; then
1390
+            screen -S $SCREEN_NAME -p $name -X logfile "$real_logfile"
1391
+            screen -S $SCREEN_NAME -p $name -X log on
1392
+        fi
1393
+        # If logging isn't active then avoid a broken symlink
1394
+        touch "$real_logfile"
1391 1395
         ln -sf "$real_logfile" ${LOGDIR}/${name}.log
1392 1396
         if [[ -n ${SCREEN_LOGDIR} ]]; then
1393 1397
             # Drop the backward-compat symlink
... ...
@@ -1426,7 +1430,7 @@ function screen_process {
1426 1426
 }
1427 1427
 
1428 1428
 # Screen rc file builder
1429
-# Uses globals ``SCREEN_NAME``, ``SCREENRC``
1429
+# Uses globals ``SCREEN_NAME``, ``SCREENRC``, ``SCREEN_IS_LOGGING``
1430 1430
 # screen_rc service "command-line"
1431 1431
 function screen_rc {
1432 1432
     SCREEN_NAME=${SCREEN_NAME:-stack}
... ...
@@ -1446,7 +1450,7 @@ function screen_rc {
1446 1446
         echo "screen -t $1 bash" >> $SCREENRC
1447 1447
         echo "stuff \"$2$NL\"" >> $SCREENRC
1448 1448
 
1449
-        if [[ -n ${LOGDIR} ]]; then
1449
+        if [[ -n ${LOGDIR} ]] && [[ "$SCREEN_IS_LOGGING" == "True" ]]; then
1450 1450
             echo "logfile ${LOGDIR}/${1}.log.${CURRENT_LOG_TIME}" >>$SCREENRC
1451 1451
             echo "log on" >>$SCREENRC
1452 1452
         fi
... ...
@@ -103,6 +103,16 @@ HORIZON_APACHE_ROOT="/dashboard"
103 103
 # be disabled for automated testing by setting this value to False.
104 104
 USE_SCREEN=True
105 105
 
106
+# When using screen, should we keep a log file on disk?  You might
107
+# want this False if you have a long-running setup where verbose logs
108
+# can fill-up the host.
109
+# XXX: Ideally screen itself would be configured to log but just not
110
+# activate.  This isn't possible with the screerc syntax.  Temporary
111
+# logging can still be used by a developer with:
112
+#    C-a : logfile foo
113
+#    C-a : log on
114
+SCREEN_IS_LOGGING=$(trueorfalse True SCREEN_IS_LOGGING)
115
+
106 116
 # Passwords generated by interactive devstack runs
107 117
 if [[ -r $RC_DIR/.localrc.password ]]; then
108 118
     source $RC_DIR/.localrc.password