#!/bin/bash
readonly app_path="/test/test01"
readonly proc_name="app01"
readonly daemon="app01-0.0.1.war"
readonly proc_pid="app01.pid"
start()
{
echo "Starting ${proc_name}..."
local pid=$(get_status)
if [ -n "${pid}" ]; then
echo "${proc_name} is already running}"
exit 0
fi
nohup java -jar "${app_path}/${daemon}" > /dev/null 2>&1 &
local pid=${!}
if [ -n ${pid} ]; then
echo " - Starting..."
echo " - Created Process ID in ${proc_pid}"
echo " - pid : ${pid}"
echo " - proc_pid : ${proc_pid}"
echo ${pid} > ${proc_pid}
else
echo "- failed to start."
fi
}
stop()
{
if [ -e ${proc_pid} ]; then
local pid=$(get_status)
echo " - Stopping ${proc_name}..."
echo " - pid : ${pid} "
if [ ${pid} -lt 3 ]; then
echo " - ${proc_name} was not running."
else
kill $pid
rm -f $proc_pid
echo " - Shutdown ...."
fi
else
echo " - ${proc_name} was not running."
fi
}
status()
{
if [ -e ${proc_pid} ]; then
local pid=$(get_status)
if [ -n "${pid}" ]; then
echo " - pid : ${pid}"
echo " - ${proc_name} is running"
else
echo " - ${proc_name} is stopped"
fi
else
echo " - ${proc_name} was not running."
fi
}
get_status()
{
ps -ef | grep ${proc_name} | grep -v grep | awk '{print $2}'
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
get_status)
get_status
;;
*)
echo "Usage: $0 {start | stop | status}"
esac
exit 0
카테고리 없음2021. 10. 14. 14:25
반응형