I'm trying to set up Tomcat to start with upstart. I find the following works:
description "Tomcat Server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
setuid tomcat
env JAVA_HOME=/usr/lib/jvm/default-java
env CATALINA_HOME=/opt/apache-tomcat-7.0.34
script
chdir $CATALINA_HOME
exec $CATALINA_HOME/bin/catalina.sh run
end script
But if I remove the chdir
, tomcat starts, but with plenty of FileNotFound
exceptions when my .wars
load. (That is: the .wars
themselves do load but they throw exceptions on load.)
Note this behavior is different from what I see when I invoke catalina.sh
from the command line. Invoking from the command line, I can run /opt/apache-tomcat-7.0.34/bin/catalina.sh run
from any directory (without chdiring) and everything's fine.
So why is the chdir
necessary in my upstart script? (How is the upstart environment different from my command-line environment?)
Example of the errors I'm seeing w/ upstart when I don't chdir:
Feb 22, 2013 3:00:11 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive my-war.war
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: my-war.log (Permission denied)
at java.io.FileOutputStream.open(Native Method)
/opt/apache-tomcat-7.0.34
, and if you remove that it will quite obviously get "file not found" errors as it's trying to run the script in some other directory./opt/apache-tomcat-7.0.34/bin/catalina.sh run
from anywhere, without chdiring, and things work fine? (Things only break when running from upstart without chdir).catalina.sh
via absolute path from anywhere. This is for my own understanding (since I'm obviously missing something about the environment upstart presents).${CATALINA_HOME}/bin/startup.sh
(without chdir). That script in turn execs catalina.sh.