-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ncr: TM-693: log rotation script (#1111)
* add archive logs script * update var * fix * fix * fix * fix
- Loading branch information
1 parent
23b72c6
commit 920d92f
Showing
9 changed files
with
162 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
# Managed in code modernisation-platform-configuration-management repo, ncr-bip role | ||
# To dryrun, run like this: DRYRUN=1 ./archive-logs.sh | ||
|
||
BOBJEDIR="{{ sap_bip_installation_directory }}/sap_bobj" | ||
BOBJUSER="bobj" | ||
CURRENTUSER=$(whoami) | ||
DATESTAMP=$(date +%Y%m%d_%H%M) | ||
ARCHLOGDIR="{{ sap_bip_archived_logs_directory }}/Archived_Logs_${DATESTAMP}" | ||
DRYRUN=${DRYRUN:-0} | ||
|
||
if [[ "$BOBJUSER" != "$CURRENTUSER" ]]; then | ||
echo "ERROR: This script must be run as $BOBJUSER" | ||
[[ $DRYRUN == 0 ]] && exit 1 | ||
fi | ||
|
||
if pgrep -u bobj java > /dev/null; then | ||
echo "ERROR: Please stop bobj processes before running" | ||
[[ $DRYRUN == 0 ]] && exit 1 | ||
fi | ||
|
||
mv_files() { | ||
files=$(find "$1" -name "$2" 2>/dev/null) | ||
if [[ -n $files ]]; then | ||
if [[ ! -d $ARCHLOGDIR ]]; then | ||
echo "Creating log file archive $ARCHLOGDIR" | ||
[[ $DRYRUN == 0 ]] && mkdir -p "$ARCHLOGDIR" | ||
fi | ||
num_files=$(wc -l <<< "$files") | ||
echo "Moving $num_files files from $1/$2 to $ARCHLOGDIR/" | ||
[[ $DRYRUN == 0 ]] && mv "$1/"$2 "$ARCHLOGDIR/" | ||
fi | ||
} | ||
|
||
if [[ -d $ARCHLOGDIR ]]; then | ||
echo "Not archiving logs as $ARCHLOGDIR already exists" | ||
else | ||
mv_files "$BOBJEDIR/logging" "*.*" | ||
mv_files "$BOBJEDIR/tomcat/logs" "*.*" | ||
mv_files "$BOBJEDIR/tomcat/bin" "TraceLog_*" | ||
mv_files ~ "SBOPWebapp_*" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/bin/bash | ||
# Managed in code modernisation-platform-configuration-management repo, ncr-bip role | ||
# This script stops SAP processes (Tomcat/CCM), archives logs, and then restarts SAP processes | ||
|
||
BOBJEDIR="{{ sap_bip_installation_directory }}/sap_bobj" | ||
BOBJUSER="bobj" | ||
CURRENTUSER=$(whoami) | ||
DRYRUN=${DRYRUN:-0} | ||
|
||
stop_processes() { | ||
if [ -f "$BOBJEDIR"/ccm.config ]; then | ||
if [[ $DRYRUN != 0 ]]; then | ||
echo "DRYRUN: Stopping servers" | ||
else | ||
"$BOBJEDIR"/ccm.sh -stop all | ||
logger -p daemon.info -t bobj "Stopped servers" | ||
fi | ||
fi | ||
if [ -d "$BOBJEDIR"/tomcat ]; then | ||
if [[ $DRYRUN != 0 ]]; then | ||
echo "DRYRUN: Stopping Tomcat" | ||
else | ||
"$BOBJEDIR"/tomcatshutdown.sh | ||
logger -p daemon.info -t bobj "Stopped Tomcat" | ||
fi | ||
fi | ||
} | ||
|
||
archive_logs() { | ||
if [[ -x /home/$BOBJUSER/archive_logs.sh ]]; then | ||
if [[ $DRYRUN != 0 ]]; then | ||
DRYRUN=$DRYRUN /home/$BOBJUSER/archive_logs.sh | ||
else | ||
echo "Archiving Logs" | ||
/home/$BOBJUSER/archive_logs.sh | logger -p daemon.info -t bobj | ||
fi | ||
fi | ||
} | ||
|
||
start_processes() { | ||
if [ -d "$BOBJEDIR"/tomcat ]; then | ||
if [[ $DRYRUN != 0 ]]; then | ||
echo "DRYRUN: Starting Tomcat" | ||
else | ||
"$BOBJEDIR"/tomcatstartup.sh | ||
logger -p daemon.info -t bobj "Started Tomcat" | ||
fi | ||
fi | ||
if [ -f "$BOBJEDIR"/ccm.config ]; then | ||
if [[ $DRYRUN != 0 ]]; then | ||
echo "DRYRUN: Starting servers" | ||
else | ||
"$BOBJEDIR"/ccm.sh -start all | ||
logger -p daemon.info -t bobj "Started servers" | ||
fi | ||
fi | ||
} | ||
|
||
if [[ "$BOBJUSER" != "$CURRENTUSER" ]]; then | ||
echo "ERROR: This script must be run as $BOBJUSER" | ||
[[ $DRYRUN == 0 ]] && exit 1 | ||
fi | ||
|
||
if pgrep -u bobj java > /dev/null; then | ||
stop_processes | ||
fi | ||
archive_logs | ||
start_processes |
51 changes: 3 additions & 48 deletions
51
ansible/roles/ncr-bip/templates/home/bobj/tomcat_restart.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,5 @@ | ||
#!/bin/bash | ||
# Version 2 | ||
# Managed in code modernisation-platform-configuration-management repo, ncr-bip role | ||
# Scheduled to run periodically via bobj cron | ||
. /home/bobj/.bash_profile | ||
|
||
BOBJEDIR={{ sap_bip_installation_directory }}/sap_bobj/ | ||
LOGDIR=${BOBJEDIR}logging/Tomcat_Restart_Logs/ | ||
BOBJUSER=bobj | ||
BOXNAME={{ ec2.tags['Name'] }} | ||
CURRENTUSER=`id | sed -e 's|).*$||' -e 's|^.*(||' ` | ||
DATESTAMP=`date +%Y%m%d_%H%M` | ||
LOGFILE=${LOGDIR}TomcatRestart_${BOXNAME}_${DATESTAMP}.log | ||
ARCHLOGDIR={{ sap_web_archived_logs_directory }}/Archived_Logs_${DATESTAMP}/ | ||
export LOGDIR BOBJEDIR BOXNAME LOGFILE BOBJUSER | ||
|
||
mkdir -p $LOGDIR 2>&1 | tee -a $LOGFILE | ||
mkdir -p $ARCHLOGDIR 2>&1 | tee -a $LOGFILE | ||
|
||
echo "Restarting Tomcat on server -" $BOXNAME | tee -a $LOGFILE | ||
echo "Log file:" $LOGFILE | ||
echo "Current user:" $CURRENTUSER | tee -a $LOGFILE | ||
|
||
if [ "$BOBJUSER" -a "$BOBJUSER" != "$CURRENTUSER" ]; then | ||
echo "ERROR: This script must be run as" $BOBJUSER | tee -a $LOGFILE | ||
exit 1 | ||
fi | ||
|
||
TOMCATPID=`ps -aux | grep tomcat | grep -v grep | grep -v $(basename -- "$0") | awk '{print $2}'` | ||
if [ -n "$TOMCATPID" ]; then | ||
echo "Stopping Tomcat (PID = ${TOMCATPID})..." | tee -a $LOGFILE | ||
exec ${BOBJEDIR}tomcatshutdown.sh | tee -a $LOGFILE | ||
|
||
TOMCATPID=`ps -aux | grep tomcat | grep -v grep | grep -v $(basename -- "$0") | awk '{print $2}'` | ||
if [ -n "$TOMCATPID" ]; then | ||
echo "Tomcat is still running. Attempting to kill PID =" $TOMCATPID | ||
kill -9 $TOMCATPID | ||
fi | ||
echo "Tomcat stopped" | tee -a $LOGFILE | ||
else | ||
echo "Tomcat is not running" | tee -a $LOGFILE | ||
fi | ||
|
||
echo "Moving log files to " $ARCHLOGDIR | tee -a $LOGFILE | ||
mv ~/SBOPWebapp_* $ARCHLOGDIR 2>&1 | tee -a $LOGFILE | ||
mv $BOBJEDIR/tomcat/logs/*.* $ARCHLOGDIR 2>&1 | tee -a $LOGFILE | ||
mv $BOBJEDIR/tomcat/bin/TraceLog_* $ARCHLOGDIR 2>&1 | tee -a $LOGFILE | ||
|
||
echo "Starting Tomcat..." | tee -a $LOGFILE | ||
exec ${BOBJEDIR}tomcatstartup.sh | tee -a $LOGFILE | ||
echo "Tomcat has been started" | tee -a $LOGFILE | ||
|
||
/home/bobj/sap_restart.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters