Authored by fangyeqing

ADD:添加启动停止脚本

#conf
cp src/main/resources/application.properties.online src/main/resources/application.properties
cp src/main/resources/public/index.html.online src/main/resources/public/index.html
#path
project_path=$(cd `dirname $0`; cd ..; pwd)
log_path=${project_path}/log
pid_file=${project_path}/bin/pid
echo "INFO: project_path=${project_path}"
echo "INFO: log_path=${log_path}"
echo "INFO: pid_file=${pid_file}"
#mkdir log
if [ -d ${log_path} ];then
echo "INFO: log/ exit"
else
echo "INFO: log/ not exit,create path log/"
mkdir ${log_path}
fi
# Check pid file
if [[ -f $pid_file ]]; then
echo "Error: Service may be already started. Check the status first.";
exit 1;
fi
# start
nohup mvn spring-boot:run >${log_path}/xkl.out &
# write down the pid
pid=$!;
if [[ -z $pid ]]; then
echo "Error: cannot start the service."
exit 1
fi
echo ${pid} > ${pid_file}
echo "INFO: start newstat service"
... ...
#path
project_path=$(cd `dirname $0`; cd ..; pwd)
pid_file=${project_path}/bin/pid
echo "INFO: project_path=${project_path}"
echo "INFO: pid_file=${pid_file}"
if [[ -f $pid_file ]]; then
pid=$(cat $pid_file);
else
echo "INFO: STOPPED";
echo "INFO: The service is already stopped. Cannot find the file $pid_file.";
exit 0;
fi
if [[ -z "$pid" || ! -d /proc/$pid ]]; then
echo "INFO: STOPPED";
echo "INFO: The service' is already stopped. Cannot find its process.";
rm -rf $pid_file;
exit 0;
fi
if [[ ! -O /proc/$pid ]]; then
echo "Error: the process with id $pid of the service is not owned by the user $USER." > /dev/stderr;
exit 1;
fi
if kill -9 $pid; then
rm -rf $pid_file;
echo "INFO:service STOPPED";
else
echo "Error when stopping the service." > /dev/stderr;
exit 1;
fi
... ...