I’m trying to use this Ubuntu Upstart script to set up Play to run as a service, and, am having problems with log4j. The script essentially does:
start-stop-daemon --start --exec /home/ubuntu/programs/play/current/play
--chuid ubuntu:ubuntu -- start /home/ubuntu/myapp/src/ --%id
Play starts up ok, but it then fails to create the log4j file. I believe start-stop-daemon does not correctly sets the folder for log4j. Log4j is configured to create a log file at relative path logs/play.log, which translates to /home/ubuntu/myapp/logs/play.log. The folder /home/ubuntu/myapp/logs/ does exist, but I get this error when Play starts:
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: logs/play.log (No such file or
directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(FileOutputStream.java:212)
at java.io.FileOutputStream.(FileOutputStream.java:136)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
Meaning that the “current directory” for Play is not the play home dir, but rather something else. Now, I can change it by providing an absolute log4j path, but it seems like a hack, and I wonder if other components that rely on the Play current folder will exhibit similar problems.
So, how I can ensure Play’s current directory is identical to the app’s homedir?
The solution was adding
--chdir $HOMEto thestart-stop-daemonline. Quite trivial to be frank.