Fixing the remaining TODOs for #2410

- Settling on default path of control file: $HOME/.monitrc
  - Handling overwriting of control file interactively
- Save BigchainDB logs in the current directory i.e. from which
  BigchainDB is launched.
- Print default values in help
- Cleanup TBD items
This commit is contained in:
Ahmed Muawia Khan 2018-07-26 12:34:45 +02:00
parent 4b74e231cd
commit 8fc5c28b4a
2 changed files with 35 additions and 24 deletions

View File

@ -3,10 +3,10 @@ import logging
from bigchaindb.common.exceptions import ConfigurationError from bigchaindb.common.exceptions import ConfigurationError
from logging.config import dictConfig as set_logging_config from logging.config import dictConfig as set_logging_config
from os.path import expanduser, join import os
DEFAULT_LOG_DIR = expanduser('~') DEFAULT_LOG_DIR = os.getcwd()
BENCHMARK_LOG_LEVEL = 15 BENCHMARK_LOG_LEVEL = 15
@ -40,7 +40,7 @@ DEFAULT_LOGGING_CONFIG = {
}, },
'file': { 'file': {
'class': 'logging.handlers.RotatingFileHandler', 'class': 'logging.handlers.RotatingFileHandler',
'filename': join(DEFAULT_LOG_DIR, 'bigchaindb.log'), 'filename': os.path.join(DEFAULT_LOG_DIR, 'bigchaindb.log'),
'mode': 'w', 'mode': 'w',
'maxBytes': 209715200, 'maxBytes': 209715200,
'backupCount': 5, 'backupCount': 5,
@ -49,7 +49,7 @@ DEFAULT_LOGGING_CONFIG = {
}, },
'errors': { 'errors': {
'class': 'logging.handlers.RotatingFileHandler', 'class': 'logging.handlers.RotatingFileHandler',
'filename': join(DEFAULT_LOG_DIR, 'bigchaindb-errors.log'), 'filename': os.path.join(DEFAULT_LOG_DIR, 'bigchaindb-errors.log'),
'mode': 'w', 'mode': 'w',
'maxBytes': 209715200, 'maxBytes': 209715200,
'backupCount': 5, 'backupCount': 5,
@ -58,7 +58,7 @@ DEFAULT_LOGGING_CONFIG = {
}, },
'benchmark': { 'benchmark': {
'class': 'logging.handlers.RotatingFileHandler', 'class': 'logging.handlers.RotatingFileHandler',
'filename': 'bigchaindb-benchmark.log', 'filename': os.path.join(DEFAULT_LOG_DIR, 'bigchaindb-benchmark.log'),
'mode': 'w', 'mode': 'w',
'maxBytes': 209715200, 'maxBytes': 209715200,
'backupCount': 5, 'backupCount': 5,

View File

@ -11,12 +11,6 @@ if [[ -n "$NOUNSET" ]]; then
set -o nounset set -o nounset
fi fi
# TBD: Defaults to $HOME, otherwise if we want to address:
# pid path could be /etc/pid_path
# monit_script could be
# log_path /var/log/monit/
# exec path(for monitrc) could be /etc/monitrc, /usr/local/etc/monitrc
# Check if directory for monit logs exists # Check if directory for monit logs exists
if [ ! -d "$HOME/.bigchaindb-monit" ]; then if [ ! -d "$HOME/.bigchaindb-monit" ]; then
mkdir -p "$HOME/.bigchaindb-monit" mkdir -p "$HOME/.bigchaindb-monit"
@ -25,7 +19,7 @@ fi
monit_pid_path=${MONIT_PID_PATH:=$HOME/.bigchaindb-monit/monit_processes} monit_pid_path=${MONIT_PID_PATH:=$HOME/.bigchaindb-monit/monit_processes}
monit_script_path=${MONIT_SCRIPT_PATH:=$HOME/.bigchaindb-monit/monit_script} monit_script_path=${MONIT_SCRIPT_PATH:=$HOME/.bigchaindb-monit/monit_script}
monit_log_path=${MONIT_LOG_PATH:=$HOME/.bigchaindb-monit/logs} monit_log_path=${MONIT_LOG_PATH:=$HOME/.bigchaindb-monit/logs}
monit_exec_path=${MONIT_EXEC_PATH:=$HOME} monit_exec_path=${MONIT_EXEC_PATH:=$HOME/.monitrc}
function usage() { function usage() {
cat <<EOM cat <<EOM
@ -37,21 +31,21 @@ function usage() {
ENV[MONIT_PID_PATH] || --monit-pid-path PATH ENV[MONIT_PID_PATH] || --monit-pid-path PATH
Absolute path to directory where the the program's pid-file will reside. Absolute path to directory where the the program's pid-file will reside.
The pid-file contains the ID(s) of the process(es). The pid-file contains the ID(s) of the process(es). (default: ${monit_pid_path})
ENV[MONIT_SCRIPT_PATH] || --monit-script-path PATH ENV[MONIT_SCRIPT_PATH] || --monit-script-path PATH
Absolute path to the directory where the executable program or Absolute path to the directory where the executable program or
script is present. script is present. (default: ${monit_script_path})
ENV[MONIT_LOG_PATH] || --monit-log-path PATH ENV[MONIT_LOG_PATH] || --monit-log-path PATH
Absolute path to the directory where all the logs for processes Absolute path to the directory where all the logs for processes
monitored by Monit are stored. monitored by Monit are stored. (default: ${monit_log_path})
ENV[MONIT_EXEC_PATH] || --monit-exec-path PATH ENV[MONIT_EXEC_PATH] || --monit-exec-path PATH
Absolute path to the directory to run the script form. Absolute path to the directory to run the script form. (default: ${monit_exec_path})
-h|--help -h|--help
Show this help and exit. Show this help and exit.
@ -144,28 +138,45 @@ exit 0
EOF EOF
chmod +x ${monit_script_path} chmod +x ${monit_script_path}
# Handling overwriting of control file interactively
if [ -f "$monit_exec_path" ]; then
echo "$monit_exec_path already exists."
read -p "Overwrite[Y]? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Overriding $monit_exec_path/.monitrc"
else
read -p "Enter absolute path to store Monit control file: " monit_exec_path
eval monit_exec_path="$monit_exec_path"
if [ ! -d "$(dirname $monit_exec_path)" ]; then
echo "Failed to save monit control file '$monit_exec_path': No such file or directory."
exit 1
fi
fi
fi
# configure monitrc # configure monitrc
cat >${monit_exec_path}/.monitrc <<EOF cat >${monit_exec_path} <<EOF
set httpd set httpd
port 2812 port 2812
allow localhost allow localhost
check process bigchaindb check process bigchaindb
with pidfile ${monit_pid_path}/bigchaindb.pid with pidfile ${monit_pid_path}/bigchaindb.pid
start program "${monit_script_path} start_bigchaindb $monit_pid_path/bigchaindb.pid ${monit_log_path} ${monit_exec_path}" start program "${monit_script_path} start_bigchaindb $monit_pid_path/bigchaindb.pid ${monit_log_path} ${monit_log_path}"
restart program "${monit_script_path} start_bigchaindb $monit_pid_path/bigchaindb.pid ${monit_log_path} ${monit_exec_path}" restart program "${monit_script_path} start_bigchaindb $monit_pid_path/bigchaindb.pid ${monit_log_path} ${monit_log_path}"
stop program "${monit_script_path} stop_bigchaindb $monit_pid_path/bigchaindb.pid ${monit_log_path} ${monit_exec_path}" stop program "${monit_script_path} stop_bigchaindb $monit_pid_path/bigchaindb.pid ${monit_log_path} ${monit_log_path}"
check process tendermint check process tendermint
with pidfile ${monit_pid_path}/tendermint.pid with pidfile ${monit_pid_path}/tendermint.pid
start program "${monit_script_path} start_tendermint ${monit_pid_path}/tendermint.pid ${monit_log_path} ${monit_exec_path}" start program "${monit_script_path} start_tendermint ${monit_pid_path}/tendermint.pid ${monit_log_path} ${monit_log_path}"
restart program "${monit_script_path} start_bigchaindb ${monit_pid_path}/bigchaindb.pid ${monit_log_path} ${monit_exec_path}" restart program "${monit_script_path} start_bigchaindb ${monit_pid_path}/bigchaindb.pid ${monit_log_path} ${monit_log_path}"
stop program "${monit_script_path} stop_tendermint ${monit_pid_path}/tendermint.pid ${monit_log_path} ${monit_exec_path}" stop program "${monit_script_path} stop_tendermint ${monit_pid_path}/tendermint.pid ${monit_log_path} ${monit_log_path}"
depends on bigchaindb depends on bigchaindb
EOF EOF
# Setting permissions for control file # Setting permissions for control file
chmod 0700 ${monit_exec_path}/.monitrc chmod 0700 ${monit_exec_path}
# Kill background processes on exit # Kill background processes on exit
trap exit_trap EXIT trap exit_trap EXIT