Skip to content

Commit

Permalink
Tweaks to manage_chit script
Browse files Browse the repository at this point in the history
  • Loading branch information
DanaMaxfield committed Aug 27, 2021
1 parent daa60de commit bb76a14
Showing 1 changed file with 44 additions and 25 deletions.
69 changes: 44 additions & 25 deletions src/main/resources/utilities/manage_chit
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#! /bin/bash
# shellcheck disable=SC2155

## TO DO
## - When chitstop is started, make a file with the running PID. Use this file for status, stop, start

EXEC_OPTION="HELP"
CHIT_JAR=""
Expand All @@ -7,7 +11,8 @@ CHIT_PID=""
CHIT_PID_OWNER=""
CHIT_RUNNING=""
CHIT_STATUS_MSG=""
LOG_DIR="/srv/hot_chit/logs"
LOG_DIR="$(pwd)/logs"
LOG_BASENAME="chit_log."
SCRIPT_RUNNER=$(whoami)

function _chit_start() {
Expand All @@ -24,11 +29,11 @@ function _chit_start() {

fullChitCmd="nohup java -jar ${CHIT_JAR}${CHIT_JAR_ARGS}"
loggingDate=$(date +%s)
logFile="${LOG_DIR}/chit_log.${loggingDate}"
logFile="${LOG_DIR}/${LOG_BASENAME}${loggingDate}"

echo "Starting the chit: ${fullChitCmd}"
echo "Logs will be sent to: ${logFile}"
set -x

${fullChitCmd} 1> "${logFile}" 2>&1 &
}

Expand All @@ -41,37 +46,46 @@ function _chit_status() {
function _chit_stop() {
_chit_status

if [[ "${CHIT_RUNNING}" == "NO" ]]; then
exit 0
elif [[ "${CHIT_RUNNING}" == "ERROR" ]]; then
if [[ "${CHIT_RUNNING}" == "ERROR" ]]; then
echo "ERROR: Must identify and kill process manually"
exit 1
elif [[ "${CHIT_RUNNING}" == "YES" ]]; then

if [[ "${SCRIPT_RUNNER}" != "${CHIT_PID_OWNER}" ]]; then
echo "ERROR: A different user has started the application, you must kill manually."
exit 1
fi

_kill_the_chit
_chit_status

if [[ "${CHIT_RUNNING}" != "NO" ]]; then
echo "ERROR: Something went wrong and the process is still running"
_display_running_chit
exit 1
else
echo "Application successfully stopped"
fi
fi
}

if [[ "${SCRIPT_RUNNER}" != "${CHIT_PID_OWNER}" ]]; then
echo "ERROR: A different user has started the application, you must kill manually."
exit 1
fi

_kill_the_chit
_chit_status
function _chit_log() {
local lastLogFile=$(find "${LOG_DIR}"/${LOG_BASENAME}* | sort | tail -1)

if [[ "${CHIT_RUNNING}" != "NO" ]]; then
echo "ERROR: Something went wrong and the process is still running"
_display_running_chit
exit 1
else
echo "Application successfully stopped"
fi
echo "The last log found is: ${lastLogFile}"
echo ""
cat "${lastLogFile}"
}

function _chit_help() {
echo -e "
This process supports 3 options:
$0 START - This will use nohup and & to start the process in the background
$0 STATUS - Displays any running instances
$0 STOP - This will use pgrep -f to find the pid and kill it
This process supports 5 options:
$0 START - This will use nohup and & to start the process in the background
$0 STATUS - Displays any running instances
$0 STOP - This will use pgrep -f to find the pid and kill it
$0 LOG - This will show the contents of the last log file in the directory: ${LOG_DIR}
$0 BOUNCE - This will run STOP then run START
Things to note:
\t* Run this from the directory which contains the jar, it won't work otherwise.
Expand Down Expand Up @@ -135,7 +149,7 @@ shopt -s nocasematch
while [[ $# -gt 0 ]]; do
myArg="${1}"
case "${myArg}" in
start|stop|status)
start|stop|status|restart|bounce|log|logs)
EXEC_OPTION=${myArg^^}
;;
--*=*)
Expand All @@ -155,6 +169,11 @@ elif [[ "${EXEC_OPTION}" == "STATUS" ]]; then
_chit_status
elif [[ "${EXEC_OPTION}" == "STOP" ]]; then
_chit_stop
elif [[ "${EXEC_OPTION}" =~ ^"LOG" ]]; then
_chit_log
elif [[ "${EXEC_OPTION}" =~ (RESTART|BOUNCE) ]]; then
_chit_stop
_chit_start
elif [[ "${EXEC_OPTION}" == "HELP" ]]; then
_chit_help
fi

0 comments on commit bb76a14

Please sign in to comment.