Hi Sascha,
Thanks
for the
great elaboration, but I still needs some clarification, So Sorry for
this.
The execute block will
start your process as that user, but I'm not positive that it will
source the user environment files. You are much better off putting the
JAVA_HOME, etc into your custom script.
I
have exported JAVA_HOME, etc in the script I am running. (where I am
extracting war and then starting the tomcat). Is this what you asked me
to do.
If you are going to make your script the authority, don't depend
on Chef
to do half the work, but ensure your script sources the files you need
or contains the environment variables it requires
OR
You
might consider reconstructing your script into a chef recipe/def
that will 1) download a remote file, 2) stop the tomcat app 3) deploy
the file 4) start the tomcat app
That is exactly what I need and am doing the same, through my default
recipe I am running a script.sh(which I have downloaded from remote
location) Inside this script basically I am extracting the war and then
starting the tomcat, I have also exported the variables in this script.
Here is the snippet:
execute "redeploy_apps" do
cwd "#{extract_path_scripts}"
user "ubuntu"
#environment 'JAVA_HOME' =>
"#{extract_path_java}/jdk1.6.0_45"
command "sh #{extract_path_scripts}/#{redeploy_apps_script}"
end
NOTE I tried with root user also.
In the redeploy_apps_script I have :
export JAVA_HOME=/home/ubuntu/jdk1.6.0_45
sudo
/home/ubuntu/scripts/apps_stop.sh > /home/ubuntu/scripts/stop.txt
echo
"Stopping APP Please Wait"
sleep 30
rm -rf
/home/ubuntu/tomcat/logs/*
rm -rf /home/ubuntu/tomcat/work/*
rm -rf
/home/ubuntu/tomcat/webapps/apps
mkdir
/home/ubuntu/tomcat/webapps/apps
rm -rf
/home/ubuntu/tomcat/webapps/static
mkdir
/home/ubuntu/tomcat/webapps/static
cd /home/ubuntu/tomcat/webapps/apps
echo "Extracting War"
/home/ubuntu/jdk1.6.0_45/bin/jar
-xf /home/ubuntu/war/apps.war
cd
/home/ubuntu/tomcat/webapps/static
/home/ubuntu/jdk1.6.0_45/bin/jar
-xf /home/ubuntu/war/apps.war
sudo /home/ubuntu/scripts/apps_start.sh >
/home/ubuntu/scripts/start.sh
Except
the lines in bold everything works.
You might
consider reconstructing your script into a chef recipe/def
that will 1) download a remote file, 2) stop the tomcat app 3)
deploy
the file 4) start the tomcat app
As I dont have
that much experience so may be I don't find where and how the service
will start from this. [Just to make a note here I an not
downloading/installing tomcat using the community "tomcat cookbook". In
my recipe I am downloading the tar of tomcat and extracting it.
Sorry If the above queries are too basic,
please bare it.