Всем здрасти,
помогите начинающему юниксоводу разботраться с модификацией скриптаб где задачи стаят таким образом:
# 1. function procces_State
# Initial - проверка: не стартует, не готов к обработке
# Running - работает
# Stopped - стоит
# Suspend - обработка закончена
# Статус записываем в переменную для дальнейшей обработки
# 2. function start_DC_Procces
# Запускаем обработку если апликация в статусе "Initial" или "Stopped"
# 3. function stop_DC_Procces
# Останавливаем обработку если апликация в статусе "Running"
Проблема в том, что ни разу не сталкивался с шелом, в юниксе могу cd и ls -l.
Может кто-нить пожалуйста глянуть и показать как правильно собрать эти функции...
Заранее спасибо огромное.
В заключение скину оригинальный скрипт
#!/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