nohup not writing to nohup.out on CodeDeploy

56 Views Asked by At

I have a Spring Boot Java20 application that I have set up to run on a Linux server using AWS CodeDeploy. Everything works as expected, except when CodeDeploy runs the following command from the deploy.sh:

nohup java -jar -Dspring.profiles.active=uat target/pow-wow-0.0.2-SNAPSHOT.jar &

Problem

It does not create an expected nohup.out file.

When I run the deploy.sh manually it does create the nohup.out file.

Question

How do I get the deploy.sh to create the nohup.out file?

More Info

When CodeDeploy executes the deploy.sh it does so using the root user. When I run it manually, I use my own user.

deploy.sh

echo "about to deploy to pow-wow ($USER) ..."
export JAVA_HOME=/home/jboss/.sdkman/candidates/java/current
echo $JAVA_HOME
export PATH=$JAVA_HOME/bin:$PATH
cd /home/jboss/bitbucket/pow-wow
pwd
echo "stopping pow-wow ..."
echo | lsof -t -i tcp:8080
kill -9 $(lsof -t -i tcp:8080)
mv pow-wow-0.0.2-SNAPSHOT.jar target/
echo "Sorting logs  ..."
cd /home/jboss/bitbucket/pow-wow/logs
pwd
if [ -e nohup.out ]
then
  cat nohup.out >> nohup-$(date --iso).out
  echo "archive logs to nohup-date.out and remove nohup.out"
  rm nohup.out
else
  echo "could not find /home/jboss/bitbucket/pow-wow/logs/nohup.out"
  ls
fi
echo "starting pow-wow ..."
cd /home/jboss/bitbucket/pow-wow
nohup java -jar -Dspring.profiles.active=uat target/pow-wow-0.0.2-SNAPSHOT.jar &
if [ -e nohup.out ]
then
  mv nohup.out logs/
  echo "Created /home/jboss/bitbucket/pow-wow/logs/nohup.out"
else
  echo "Could not find nohup.out that should have been created from nohup java -jar"
  pwd
  ls
fi
echo "Run Start pow-wow."

Output

[stdout]Could not find nohup.out that should have been created from nohup java -jar
0

There are 0 best solutions below