Answer the question
In order to leave comments, you need to log in
Modifying/automating the spring_boot script, dc-jmx-1.1.9?
Hello everyone,
help a novice Unix driver to deal with the modification of scriptab where the tasks are stacked like this:
# 1. function procces_State
# Initial - check: not starting, not ready for processing
# Running - running
# Stopped - standing still
# Suspend - processing completed
# Write the status to a variable for further processing
# 2. function start_DC_Procces
# Start processing if the application is in status "Initial" or "Stopped"
# 3. function stop_DC_Procces
# Stop processing if application is in "Running" status
#!/bin/bash
# File containing the pid (beaware that this file name defaults to application.pid by spring convention.
# If the variable is changed here you need to add the property "spring.pidfile" too
PIDFile="application.pid"
# JAR to be started
JAR=`ls ./jar/`
# Load the environment properties
source ./config/environment.properties
# check the JAVA_HOME path
if [ ! -e $JAVA_HOME/bin/java ]
then
echo "[ERROR] Invalid path. No java executable found at JAVA_HOME=$JAVA_HOME"
exit 1
else
echo "[OK] Found java binary..."
fi
# check if the application.pid file exists
check_if_pid_file_exists(){
if [ ! -f $PIDFile ]
then
echo "Process not running"
exit 1
fi
}
# check if the process mentioned in the pid file is still running
check_if_process_is_running(){
if ps -p "$(print_process)" > /dev/null
then
return 0
else
return 1
fi
}
# check the status
status(){
check_if_pid_file_exists
if check_if_process_is_running
then
echo "$(print_process) is running"
else
echo "PIDFile=$PIDFile does not exist"
fi
}
# stop the application
stop() {
# first of all check if the process is still running
if [ ! -f $PIDFile ] || ! check_if_process_is_running
then
echo "Process "$(print_process)" not running"
rm -f $PIDFile
exit 0
fi
# Term the process if it's still running
kill -TERM "$(print_process)"
echo -ne "Waiting for process to stop"
NOT_KILLED=1
for i in {1..20}; do
if [ -f $PIDFile ] && check_if_process_is_running
then
echo -ne "."
sleep 1
else
NOT_KILLED=0
fi
done
echo
# Maybe the process was not terminated. Info and exit. Someone needs to check that.
if [ $NOT_KILLED = 1 ]
then
echo "Cannot kill process "$(print_process)" "
exit 1
fi
echo "Process stopped"
rm -f $PIDFile
}
# start the application
start() {
if [ -f $PIDFile ] && check_if_process_is_running
then
echo "Process "$(print_process)" already running"
exit 1
fi
echo "nohup $JAVA_HOME/bin/java $JAVA_OPTS $2 -jar ./jar/*.jar > ./log/nohup.log 2>&1 &"
nohup $JAVA_HOME/bin/java $JAVA_OPTS $2 -jar ./jar/*.jar > ./log/nohup.log 2>&1 &
sleep 5
echo -e "\nProcess started:" `cat $PIDFile`
}
# start the application
docker_start() {
if [ -f $PIDFile ] && check_if_process_is_running
then
echo "Process "$(print_process)" already running"
exit 1
fi
echo "nohup $JAVA_HOME/bin/java $JAVA_OPTS $2 -jar ./jar/*.jar > ./log/nohup.log 2>&1"
nohup $JAVA_HOME/bin/java $JAVA_OPTS $2 -jar ./jar/*.jar > ./log/nohup.log 2>&1
sleep 5
echo -e "\nProcess started:" `cat $PIDFile`
}
# print the pid
print_process(){
echo "$(cat $PIDFile)"
}
# evaluate options: start, stop, status ...
evaluate_option() {
case "$1" in
status)
status
;;
stop)
stop
exit 0
;;
start)
start
exit 0
;;
pid)
print_process
;;
dump)
exec "./tools/heapdump.sh"
;;
memmap)
exec "./tools/memmap.sh"
;;
tdump)
exec "./tools/threaddump.sh"
;;
Quit)
exit 0
;;
Docker)
docker_start
exit 0;
;;
*)
clear
echo "Invalid action. Please select between start|stop|status|pid|dump|memmap|tdump"
esac
}
# Evaluate the command line argument (script works with and without command line arguments)
if ! [ -z $1 ]
then
# evaluate command line option
evaluate_option $1
else
# show menu
OPTIONS="status stop start pid dump memmap tdump Quit Docker"
select opt in $OPTIONS
do
evaluate_option $opt
done
fi
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question