Fixup screen
Change-Id: I655530c7f27f730d18e8e9d36e819e93ffd5a530
This commit is contained in:
parent
82c0a77f1d
commit
64247eaa35
@ -12,11 +12,14 @@ set -x
|
|||||||
# Keep track of this directory
|
# Keep track of this directory
|
||||||
SCRIPT_DIR=$(cd $(dirname "$0") && pwd)
|
SCRIPT_DIR=$(cd $(dirname "$0") && pwd)
|
||||||
BASE_DIR=${BASE_DIR:-$SCRIPT_DIR/..}
|
BASE_DIR=${BASE_DIR:-$SCRIPT_DIR/..}
|
||||||
|
CONFIG=${CONFIG:-$BASE_DIR/etc/billingstack/billingstack.conf}
|
||||||
|
|
||||||
SCREEN_NAME=${SCREEN_NAME:-billingstack}
|
SCREEN_NAME=${SCREEN_NAME:-billingstack}
|
||||||
SCREEN_LOGDIR=${SCREEN_LOGDIR:-$BASE_DIR/logs}
|
SCREEN_LOGDIR=${SCREEN_LOGDIR:-$BASE_DIR/logs}
|
||||||
|
SCREENRC=$BASE_DIR/$SCREEN_NAME-screenrc
|
||||||
|
USE_SCREEN=$(trueorfalse True $USE_SCREEN)
|
||||||
|
|
||||||
CONFIG=${CONFIG:-$BASE_DIR/etc/billingstack/billingstack.conf}
|
SERVICE_DIR=${SERVICE_DIR:-$BASE_DIR/status}
|
||||||
|
|
||||||
SERVICES="api,central,rater,biller,collector"
|
SERVICES="api,central,rater,biller,collector"
|
||||||
|
|
||||||
@ -91,9 +94,6 @@ function run_process() {
|
|||||||
# Helper to launch a service in a named screen
|
# Helper to launch a service in a named screen
|
||||||
# screen_it service "command-line"
|
# screen_it service "command-line"
|
||||||
function screen_it {
|
function screen_it {
|
||||||
SCREEN_NAME=${SCREEN_NAME:-stack}
|
|
||||||
SERVICE_DIR=${SERVICE_DIR:-$BASE_DIR/status}
|
|
||||||
USE_SCREEN=$(trueorfalse True $USE_SCREEN)
|
|
||||||
|
|
||||||
if is_service_enabled $1; then
|
if is_service_enabled $1; then
|
||||||
# Append the service to the screen rc file
|
# Append the service to the screen rc file
|
||||||
@ -126,8 +126,6 @@ function screen_it {
|
|||||||
# Screen rc file builder
|
# Screen rc file builder
|
||||||
# screen_rc service "command-line"
|
# screen_rc service "command-line"
|
||||||
function screen_rc {
|
function screen_rc {
|
||||||
SCREEN_NAME=${SCREEN_NAME:-stack}
|
|
||||||
SCREENRC=$BASE_DIR/$SCREEN_NAME-screenrc
|
|
||||||
if [[ ! -e $SCREENRC ]]; then
|
if [[ ! -e $SCREENRC ]]; then
|
||||||
# Name the screen session
|
# Name the screen session
|
||||||
echo "sessionname $SCREEN_NAME" > $SCREENRC
|
echo "sessionname $SCREEN_NAME" > $SCREENRC
|
||||||
@ -152,19 +150,29 @@ function is_service_enabled() {
|
|||||||
|
|
||||||
|
|
||||||
function screen_setup() {
|
function screen_setup() {
|
||||||
ensure_dir $SCREEN_LOGDIR
|
|
||||||
|
|
||||||
# Check to see if we are already running DevStack
|
# Set up logging of screen windows
|
||||||
# Note that this may fail if USE_SCREEN=False
|
# Set ``SCREEN_LOGDIR`` to turn on logging of screen windows to the
|
||||||
if type -p screen >/dev/null && screen -ls | egrep -q "[0-9].$SCREEN_NAME"; then
|
# directory specified in ``SCREEN_LOGDIR``, we will log to the the file
|
||||||
echo "You are already running a stack.sh session."
|
# ``screen-$SERVICE_NAME-$TIMESTAMP.log`` in that dir and have a link
|
||||||
echo "To rejoin this session type 'screen -x stack'."
|
# ``screen-$SERVICE_NAME.log`` to the latest log file.
|
||||||
echo "To destroy this session, type './unstack.sh'."
|
# Logs are kept for as long specified in ``LOGDAYS``.
|
||||||
exit 1
|
if [[ -n "$SCREEN_LOGDIR" ]]; then
|
||||||
|
|
||||||
|
# We make sure the directory is created.
|
||||||
|
if [[ -d "$SCREEN_LOGDIR" ]]; then
|
||||||
|
# We cleanup the old logs
|
||||||
|
find $SCREEN_LOGDIR -maxdepth 1 -name screen-\*.log -mtime +$LOGDAYS -exec rm {} \;
|
||||||
|
else
|
||||||
|
ensure_dir $SCREEN_LOGDIR
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -d "$SERVICE_DIR/$SCREEN_NAME" ]]; then
|
||||||
|
mkdir -p "$SERVICE_DIR/$SCREEN_NAME"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
USE_SCREEN=$(trueorfalse True $USE_SCREEN)
|
USE_SCREEN=$(trueorfalse True $USE_SCREEN)
|
||||||
echo $USE_SCREEN
|
|
||||||
if [[ "$USE_SCREEN" == "True" ]]; then
|
if [[ "$USE_SCREEN" == "True" ]]; then
|
||||||
# Create a new named screen to run processes in
|
# Create a new named screen to run processes in
|
||||||
screen -d -m -S $SCREEN_NAME -t shell -s /bin/bash
|
screen -d -m -S $SCREEN_NAME -t shell -s /bin/bash
|
||||||
@ -185,6 +193,18 @@ function screen_setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
screen_is_running() {
|
||||||
|
# Check to see if we are already running DevStack
|
||||||
|
# Note that this may fail if USE_SCREEN=False
|
||||||
|
if type -p screen >/dev/null && screen -ls | egrep -q "[0-9].$SCREEN_NAME"; then
|
||||||
|
echo "Already running a session."
|
||||||
|
echo "To rejoin this session type 'screen -x $SCREEN_NAME'."
|
||||||
|
echo "To destroy this session, type './$0 stop'."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function screen_destroy() {
|
function screen_destroy() {
|
||||||
SCREEN=$(which screen)
|
SCREEN=$(which screen)
|
||||||
if [[ -n "$SCREEN" ]]; then
|
if [[ -n "$SCREEN" ]]; then
|
||||||
@ -193,6 +213,8 @@ function screen_destroy() {
|
|||||||
screen -X -S $SESSION quit
|
screen -X -S $SESSION quit
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -f "$SERVICE_DIR/$SCREEN_NAME"/*.failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -203,8 +225,10 @@ function start_svc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
local svc=$1
|
local svc=$1
|
||||||
|
|
||||||
[ "$svc" == 'all' ] && {
|
[ "$svc" == 'all' ] && {
|
||||||
for s in $(echo "$SERVICES" | tr ',' ' '); do
|
for s in $(echo "$SERVICES" | tr ',' ' '); do
|
||||||
start_svc $s
|
start_svc $s
|
||||||
@ -217,6 +241,7 @@ function start() {
|
|||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
start)
|
start)
|
||||||
|
screen_is_running
|
||||||
screen_setup
|
screen_setup
|
||||||
|
|
||||||
svc=$2
|
svc=$2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user