1

I have installed tomcat in /opt/tomcat6 and made one of it's instance in ~/tomcatHost directory.The /opt/tomcat6 is owned by user tomcat and group tomcat. Unix "ls -l" produce following -

drwxr-xr-x 9 tomcat tomcat 4096 Dec 15 03:37 tomcat6

In this case, to run tomcat instance in ~/tomcatHost I need to do the following steps -

  • Copy conf, webapps, logs from /opt/tomcat6 to ~/tomcatHost. Make some changes server.xml in ~tomcatHost/conf (eg- changing the port number in "Connector" element)
  • give execute permission to ~/tocatHost for all user by chmod -

$ chmod -R 777 tomcatHost

  • and run the following commands -

$ export CATALINA_BASE=/home/guestUser/tomcatHost
$ su tomcat
$ cd /opt/tomcat6/bin
$ sh startup.sh

Now the tomcat is start at the port configured in server.xml. I'm trying to write a shell script which do the task performed above. I'm new in shell scripting and can not able to solve this problem. I think there is an ownership issue, can anyone tell me how can I handle the ownership issue in shell script? Or, how can I write a script to run "startup.sh" (owned by tomcat user) from other user. Can you suggest any good tutorial for this?

Razib
  • 10,965
  • 11
  • 53
  • 80

1 Answers1

1

I have get a solution to this. Probably it is not the best solution but it works pretty good. I have write the following code (based on this.) on a file named 'start.sh' -

export CATALINA_BASE=/home/razib/tomcat_host  
echo "CATALINA_BASE is set..."  
echo "Password for 'tomcat' - "  
su -c "sh /opt/tomcat6/bin/startup.sh" -s /bin/sh tomcat

Then from terminal I just run the 'start.sh' scrip

Community
  • 1
  • 1
Razib
  • 10,965
  • 11
  • 53
  • 80