Subscribe to
Posts
Comments

Since Siusic.com is now sitting on its own dedicated Linux server I have to learn a lot of Linux shell commands to manage the Linux server myself. One of the thing that I wanted

to do after installing Tomcat was to make it start running automatically as a user other then root. In order to do that a shell script has to be written to take a parameter either “start” or “stop” to start or stop Tomcat.

When the shell script is put into the /ect/int.d directory it will be called by the system at boot time and passed “start” as parameter. That is how Linux start a program automatically at boot time. It is analogous to add programs to the Windows registry \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run in order to start a program automatically when Windows boot up.

I wrote my first ever Linux shell script “tomcat” to do that. I post the script here because I didn’t find a straight forward answer when I Google it or Baidu it. Hopefully it will help some new Tomcat and Linux users.

ARGV=”$@”
STARTTOMCAT=’Tomcat_Installation_Path/bin/startup.sh’
STOPTOMCAT=’Tomcat_Installation_Path/bin/shutdown.sh’
source /What_Ever_Path/tomcat.env
case $ARGV in
start)
echo $”Starting Tomcat”
su tomcat $STARTTOMCAT
ERROR=$?
;;
stop)
echo $”Stopping Tomcat2″
su tomcat $STOPTOMCAT
ERROR=$?
;;
esac
exit $ERROR

That is it. The script first store the start-up and shut-down script for Tomcat in variable
It then execute the command in tomcat.env to set environment variables. The tomcat.env file is like this

export JAVA_HOME=Java_Installation_Path
export PATH=$JAVA_HOME/bin:$PATH
export CATALINA_HOME=Tomcat_Installation_Path
export CATALINA_BASE=Tomcat_Instance_Path

After that the script execute the start-up or shut down script using user Tomcat. So prior to that you will have to create a user called tomcat which has proper permission to the tomcat installation directory and the tomcat instance directory.

Put the tomcat script file into /etc/init.d directory. Make it executable using the chmod command. Don’t forgot to create a link to the tomcat file in the /etc/rc5.d directory. After that Tomcat will start automatically at on boot time as user tomcat.


Related Posts:

  • IPTables Port Forwarding on Virtual IP Doesn’t Work For Tomcat
  • VB Script to Rename All Files in a Folder
  • Open Source vs. Microsoft
  • The Best Way to Backup SQL Server
  • The Best Way to Grant Execution Right on xp_cmdshell and Cross Database Ownership Chaining


  • 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...

    RSS feed | Trackback URI

    1 Comment »

    Comment by Bert
    2010-12-03 00:03:05
    MyAvatars 0.2

    i cant copy or paste or even save in the init.d file directory.

     
    Name (required)
    E-mail (required - never shown publicly)
    URI
    Subscribe to comments via email
    Your Comment (smaller size | larger size)
    You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.