|
...
|
...
|
@@ -1251,7 +1251,7 @@ function run_process {
|
|
1251
|
1251
|
|
|
1252
|
1252
|
if is_service_enabled $service; then
|
|
1253
|
1253
|
if [[ "$USE_SCREEN" = "True" ]]; then
|
|
1254
|
|
- screen_service "$service" "$command" "$group"
|
|
|
1254
|
+ screen_process "$service" "$command" "$group"
|
|
1255
|
1255
|
else
|
|
1256
|
1256
|
# Spawn directly without screen
|
|
1257
|
1257
|
_run_process "$service" "$command" "$group" &
|
|
...
|
...
|
@@ -1259,14 +1259,14 @@ function run_process {
|
|
1259
|
1259
|
fi
|
|
1260
|
1260
|
}
|
|
1261
|
1261
|
|
|
1262
|
|
-# Helper to launch a service in a named screen
|
|
|
1262
|
+# Helper to launch a process in a named screen
|
|
1263
|
1263
|
# Uses globals ``CURRENT_LOG_TIME``, ``SCREEN_NAME``, ``SCREEN_LOGDIR``,
|
|
1264
|
1264
|
# ``SERVICE_DIR``, ``USE_SCREEN``
|
|
1265
|
|
-# screen_service service "command-line" [group]
|
|
|
1265
|
+# screen_process name "command-line" [group]
|
|
1266
|
1266
|
# Run a command in a shell in a screen window, if an optional group
|
|
1267
|
1267
|
# is provided, use sg to set the group of the command.
|
|
1268
|
|
-function screen_service {
|
|
1269
|
|
- local service=$1
|
|
|
1268
|
+function screen_process {
|
|
|
1269
|
+ local name=$1
|
|
1270
|
1270
|
local command="$2"
|
|
1271
|
1271
|
local group=$3
|
|
1272
|
1272
|
|
|
...
|
...
|
@@ -1274,38 +1274,36 @@ function screen_service {
|
|
1274
|
1274
|
SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}
|
|
1275
|
1275
|
USE_SCREEN=$(trueorfalse True $USE_SCREEN)
|
|
1276
|
1276
|
|
|
1277
|
|
- if is_service_enabled $service; then
|
|
1278
|
|
- # Append the service to the screen rc file
|
|
1279
|
|
- screen_rc "$service" "$command"
|
|
1280
|
|
-
|
|
1281
|
|
- screen -S $SCREEN_NAME -X screen -t $service
|
|
1282
|
|
-
|
|
1283
|
|
- if [[ -n ${SCREEN_LOGDIR} ]]; then
|
|
1284
|
|
- screen -S $SCREEN_NAME -p $service -X logfile ${SCREEN_LOGDIR}/screen-${service}.${CURRENT_LOG_TIME}.log
|
|
1285
|
|
- screen -S $SCREEN_NAME -p $service -X log on
|
|
1286
|
|
- ln -sf ${SCREEN_LOGDIR}/screen-${service}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${service}.log
|
|
1287
|
|
- fi
|
|
|
1277
|
+ # Append the process to the screen rc file
|
|
|
1278
|
+ screen_rc "$name" "$command"
|
|
1288
|
1279
|
|
|
1289
|
|
- # sleep to allow bash to be ready to be send the command - we are
|
|
1290
|
|
- # creating a new window in screen and then sends characters, so if
|
|
1291
|
|
- # bash isn't running by the time we send the command, nothing happens
|
|
1292
|
|
- sleep 3
|
|
|
1280
|
+ screen -S $SCREEN_NAME -X screen -t $name
|
|
1293
|
1281
|
|
|
1294
|
|
- NL=`echo -ne '\015'`
|
|
1295
|
|
- # This fun command does the following:
|
|
1296
|
|
- # - the passed server command is backgrounded
|
|
1297
|
|
- # - the pid of the background process is saved in the usual place
|
|
1298
|
|
- # - the server process is brought back to the foreground
|
|
1299
|
|
- # - if the server process exits prematurely the fg command errors
|
|
1300
|
|
- # and a message is written to stdout and the service failure file
|
|
1301
|
|
- #
|
|
1302
|
|
- # The pid saved can be used in stop_process() as a process group
|
|
1303
|
|
- # id to kill off all child processes
|
|
1304
|
|
- if [[ -n "$group" ]]; then
|
|
1305
|
|
- command="sg $group '$command'"
|
|
1306
|
|
- fi
|
|
1307
|
|
- screen -S $SCREEN_NAME -p $service -X stuff "$command & echo \$! >$SERVICE_DIR/$SCREEN_NAME/${service}.pid; fg || echo \"$service failed to start\" | tee \"$SERVICE_DIR/$SCREEN_NAME/${service}.failure\"$NL"
|
|
|
1282
|
+ if [[ -n ${SCREEN_LOGDIR} ]]; then
|
|
|
1283
|
+ screen -S $SCREEN_NAME -p $name -X logfile ${SCREEN_LOGDIR}/screen-${name}.${CURRENT_LOG_TIME}.log
|
|
|
1284
|
+ screen -S $SCREEN_NAME -p $name -X log on
|
|
|
1285
|
+ ln -sf ${SCREEN_LOGDIR}/screen-${name}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${name}.log
|
|
|
1286
|
+ fi
|
|
|
1287
|
+
|
|
|
1288
|
+ # sleep to allow bash to be ready to be send the command - we are
|
|
|
1289
|
+ # creating a new window in screen and then sends characters, so if
|
|
|
1290
|
+ # bash isn't running by the time we send the command, nothing happens
|
|
|
1291
|
+ sleep 3
|
|
|
1292
|
+
|
|
|
1293
|
+ NL=`echo -ne '\015'`
|
|
|
1294
|
+ # This fun command does the following:
|
|
|
1295
|
+ # - the passed server command is backgrounded
|
|
|
1296
|
+ # - the pid of the background process is saved in the usual place
|
|
|
1297
|
+ # - the server process is brought back to the foreground
|
|
|
1298
|
+ # - if the server process exits prematurely the fg command errors
|
|
|
1299
|
+ # and a message is written to stdout and the process failure file
|
|
|
1300
|
+ #
|
|
|
1301
|
+ # The pid saved can be used in stop_process() as a process group
|
|
|
1302
|
+ # id to kill off all child processes
|
|
|
1303
|
+ if [[ -n "$group" ]]; then
|
|
|
1304
|
+ command="sg $group '$command'"
|
|
1308
|
1305
|
fi
|
|
|
1306
|
+ screen -S $SCREEN_NAME -p $name -X stuff "$command & echo \$! >$SERVICE_DIR/$SCREEN_NAME/${name}.pid; fg || echo \"$name failed to start\" | tee \"$SERVICE_DIR/$SCREEN_NAME/${name}.failure\"$NL"
|
|
1309
|
1307
|
}
|
|
1310
|
1308
|
|
|
1311
|
1309
|
# Screen rc file builder
|
|
...
|
...
|
@@ -1412,12 +1410,12 @@ function service_check {
|
|
1412
|
1412
|
|
|
1413
|
1413
|
# Tail a log file in a screen if USE_SCREEN is true.
|
|
1414
|
1414
|
function tail_log {
|
|
1415
|
|
- local service=$1
|
|
|
1415
|
+ local name=$1
|
|
1416
|
1416
|
local logfile=$2
|
|
1417
|
1417
|
|
|
1418
|
1418
|
USE_SCREEN=$(trueorfalse True $USE_SCREEN)
|
|
1419
|
1419
|
if [[ "$USE_SCREEN" = "True" ]]; then
|
|
1420
|
|
- screen_service "$service" "sudo tail -f $logfile"
|
|
|
1420
|
+ screen_process "$name" "sudo tail -f $logfile"
|
|
1421
|
1421
|
fi
|
|
1422
|
1422
|
}
|
|
1423
|
1423
|
|
|
...
|
...
|
@@ -1476,7 +1474,7 @@ function screen_it {
|
|
1476
|
1476
|
screen_rc "$1" "$2"
|
|
1477
|
1477
|
|
|
1478
|
1478
|
if [[ "$USE_SCREEN" = "True" ]]; then
|
|
1479
|
|
- screen_service "$1" "$2"
|
|
|
1479
|
+ screen_process "$1" "$2"
|
|
1480
|
1480
|
else
|
|
1481
|
1481
|
# Spawn directly without screen
|
|
1482
|
1482
|
old_run_process "$1" "$2" >$SERVICE_DIR/$SCREEN_NAME/$1.pid
|