I have a spring boot application deployed on RHEL 8. The app creates log files in specific folder and files based on the setting in the logback.xml file.
I am deploying the app as a service and I see that the logs are not getting created with the below configuration. The below script file is invoked from systemd process where this file is referenced.
#!/bin/sh
SERVICE_NAME=My_Service_Name
PATH_TO_JAR=/usr/Name_of_User/MyJavaApplication.jar
PID_PATH_NAME=/tmp/My_Service_Name-pid
case $1 in
start)
echo "Starting $SERVICE_NAME ..."
if [ ! -f $PID_PATH_NAME ]; then
java -jar $PATH_TO_JAR
echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is already running ..."
fi
;;
stop)
if [ -f $PID_PATH_NAME ]; then
PID=$(cat $PID_PATH_NAME);
echo "$SERVICE_NAME stoping ..."
kill $PID;
echo "$SERVICE_NAME stopped ..."
rm $PID_PATH_NAME
else
echo "$SERVICE_NAME is not running ..."
fi
;;
restart)
if [ -f $PID_PATH_NAME ]; then
PID=$(cat $PID_PATH_NAME);
echo "$SERVICE_NAME stopping ...";
kill $PID;
echo "$SERVICE_NAME stopped ...";
rm $PID_PATH_NAME
echo "$SERVICE_NAME starting ..."
java -jar $PATH_TO_JAR
echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is not running ..."
fi ;;
esac
In the abovue script i even tried replacing
java -jar $PATH_TO_JAR
with
nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >>/dev/null &
but no luck.
If i dont use this script and run the app from terminal like java -jar MyApplication.jar
the log files do get created at the required location.