Reputation: 406
I am trying to create a service for tomcat on Ubuntu 12.10 using upstart.
So, i created a tomcat.conf file in /etc/init
description "Tomcat Server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
# run as non privileged user
# add user with this command:
## adduser --system --ingroup www-data --home /opt/apache-tomcat apache-tomcat
# Ubuntu 12.04: (use 'exec sudo -u apache-tomcat' when using 10.04)
setuid tomcat
setgid tomcat
pre-start script
. /etc/default/tomcat
end script
exec $CATALINA_HOME/bin/catalina.sh run
# cleanup temp directory after stop
post-stop script
rm -rf $CATALINA_HOME/temp/*
end script
The /etc/default/tomcat file contains env variables, which i need to set before starting the service.
However, sourcing the file has no effect. When I source the /etc/default/tomcat file form command line, it works fine. But when I include it in the script, it has no effect.
What could be wrong?
Upvotes: 3
Views: 7050
Reputation: 530
Nested scripts in upstart (e.g. pre-start) inherit the environment set in the enclosing file, but any changes made within the nested script will have no effect on the enclosing script's envrionment.
Source: http://upstart.ubuntu.com/cookbook/#environment-variables (see the long example near the end of that section)
Upvotes: 1
Reputation: 64690
You'll probably need to do export each of the environment variables piecemeal. Something like this:
script
. /etc/default/tomcat
export CATALINA_HOME
exec $CATALINA_HOME/bin/catalina.sh run
end script
should result in CATALINA_HOME being available to the catalina.sh file.
Upvotes: 1