Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

CORTX-33043: Update motr log rotate scripts with proper PVC log path and removing rgw startup log file #124

Merged
merged 9 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/rgw/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
FREQUENCY='hourly'
CRON_DIR = f'/etc/cron.{FREQUENCY}'
CRON_LOGROTATE = f'{CRON_DIR}/logrotate'
M0TRACE_LOG_ROTATE_FILE = f'{CRON_DIR}/m0trace_logrotate.sh'
ADDB_LOG_ROTATE_FILE = f'{CRON_DIR}/m0addb_logrotate.sh'

REQUIRED_RPMS = ['cortx-hare', 'cortx-py-utils', 'ceph-radosgw']
ADMIN_PARAMETERS = {'MOTR_ADMIN_FID':'motr admin fid', 'MOTR_ADMIN_ENDPOINT':'motr admin endpoint', 'RGW_FRONTENDS': 'rgw frontends'}

Expand Down
6 changes: 2 additions & 4 deletions src/rgw/setup/radosgw_start
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

INDEX=$1
CONFIG_FILE=$2
LOG_FILE=$3
RGW_CWD=$4
RGW_CWD=$3

[ -z "$RGW_CWD" ] && RGW_CWD="$PWD"

echo "Change RGW CWD to dir $RGW_CWD, to retain core files in there"
cd $RGW_CWD

set -o pipefail;
/usr/bin/radosgw -f --name client.rgw-$INDEX -c $CONFIG_FILE --no-mon-config 2>&1 \
| while read line; do printf "%s %s\n" "$(date +'[%Y-%m-%d %H:%M:%S,%03N]')" "$line"; done | tee $LOG_FILE
cdeshmukh marked this conversation as resolved.
Show resolved Hide resolved
/usr/bin/radosgw -f --name client.rgw-$INDEX -c $CONFIG_FILE --no-mon-config
exit $?
59 changes: 57 additions & 2 deletions src/rgw/setup/rgw.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ def start(conf: MappedConf, index: str):
os.makedirs(rgw_core_dir, exist_ok=True)

Log.info('Starting radosgw service.')
log_file = os.path.join(log_path, f'{const.COMPONENT_NAME}_startup.log')

RgwService.start(conf, config_file, log_file, motr_trace_dir, addb_dir, rgw_core_dir, index)
RgwService.start(conf, config_file, motr_trace_dir, addb_dir, rgw_core_dir, index)
Log.info("Started radosgw service.")

return 0
Expand Down Expand Up @@ -832,13 +831,69 @@ def _logrotate_generic(conf: MappedConf):
except Exception as e:
Log.error(f"Failed to configure core file's logrotate for {const.COMPONENT_NAME}. ERROR:{e}")

Rgw._update_motr_log_rotate_scripts(conf, log_file_path)
# start cron.d service
try:
os.system(f"chmod +x {const.CRON_LOGROTATE}")
os.system("/usr/sbin/crond start")
except Exception as e:
Log.error(f"Failed to start the crond service for {const.COMPONENT_NAME}. ERROR:{e}")

@staticmethod
def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str):
""""Update correct PVC path of m0trace, addb log directory for motr log rotate script"""
config_file = Rgw._get_rgw_config_path(conf)
confstore_url = const.CONFSTORE_FILE_HANDLER + config_file
Rgw._load_rgw_config(Rgw._conf_idx, confstore_url)

motr_addb_file_fid = Conf.get(Rgw._conf_idx, const.MOTR_ADMIN_FID_KEY)
addb_log_dir_path = os.path.join(svc_log_dir, f'addb_files-{motr_addb_file_fid}')
motr_trace_log_path = os.path.join(svc_log_dir, 'motr_trace_files')

if not os.path.exists(const.ADDB_LOG_ROTATE_FILE) or \
not os.path.exists(const.M0TRACE_LOG_ROTATE_FILE):
Log.info(f'WARNING:: {const.CRON_DIR} does not has addb/m0trace motr log rotate scripts.')
return
# Handle m0trace log rotate script path.
try:
with open(const.M0TRACE_LOG_ROTATE_FILE, 'r') as f:
lines = f.readlines()
tmp_file = os.path.join(const.CRON_DIR, 'tmp_m0trace.sh')
with open(tmp_file, 'w') as tmp_fout:
for idx, line in enumerate(lines):
if line.startswith("M0TR_M0D_TRACE_DIR="):
trace_key_name = line.split("=")[0]
updated_line = trace_key_name + "=" + f'\"{motr_trace_log_path}\"' + "\n"
lines[idx] = updated_line
tmp_fout.write(lines[idx])

shutil.copyfile(tmp_file, const.M0TRACE_LOG_ROTATE_FILE)
os.remove(tmp_file)
Log.info(f'{const.M0TRACE_LOG_ROTATE_FILE} file updated with log path {motr_trace_log_path}')
except Exception as e:
Log.error(f"Failed to update m0trace log rotation script path. ERROR:{e}")

# Handle addb trace log rotate script path.
try:
with open(const.ADDB_LOG_ROTATE_FILE, 'r') as f:
lines = f.readlines()
tmp_file = os.path.join(const.CRON_DIR, 'tmp_m0addb_log.sh')
with open(tmp_file, 'w') as tmp_fout:
for idx, line in enumerate(lines):
if line.startswith("ADDB_RECORD_DIR="):
addb_dir_key = line.split("=")[0]
updated_line = addb_dir_key + "=" + f'\"{addb_log_dir_path}\"' + "\n"
lines[idx] = updated_line
tmp_fout.write(lines[idx])

shutil.copyfile(tmp_file, const.ADDB_LOG_ROTATE_FILE)
os.remove(tmp_file)

Log.info(f'{const.ADDB_LOG_ROTATE_FILE} file updated with log path {addb_log_dir_path}')
except Exception as e:
Log.error(f"Failed to update m0addb log rotation script path. ERROR:{e}")


@staticmethod
def _verify_backend_store_value(conf: MappedConf):
"""Verify backed store value as motr."""
Expand Down
4 changes: 2 additions & 2 deletions src/rgw/setup/rgw_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class RgwService:
"""Entrypoint class for RGW."""

@staticmethod
def start(conf: MappedConf, config_file, log_file, motr_trace_dir, addb_dir, rgw_cwd, index: str = '1',):
def start(conf: MappedConf, config_file, motr_trace_dir, addb_dir, rgw_cwd, index: str = '1',):
"""Start rgw service independently."""
try:
os.environ['M0_TRACE_DIR'] = motr_trace_dir
os.environ['M0_CLIENT_ADDB_DIR'] = addb_dir
cmd = os.path.join(INSTALL_PATH, COMPONENT_NAME, 'bin/radosgw_start')
sys.stdout.flush()
sys.stderr.flush()
os.execl(cmd, cmd, index, config_file, log_file, rgw_cwd)
os.execl(cmd, cmd, index, config_file, rgw_cwd)
except OSError as e:
Log.error(f"Failed to start radosgw service:{e}")
raise SetupError(e.errno, "Failed to start radosgw service. %s", e)
Expand Down