tomcat autostart inti.d script

 

GIVE most of the credits to : http://lintut.com/how-to-install-tomcat-8-0-0-rc5-on-ubuntu-server/

OK, this post is gonna be an example to autostart tomcat when ubuntu starts. 

We know that if you create init.d script and place it in /etc/init.d/ directory, this application will autostart when ubuntu starts, and also can be used as a service to start/stop/restart. 

Here I am using a tomcat 6 running on ubuntu 10.04 LTS. 

I recommand you download tomcat extracted files rather than install in via command line. You can then unzip/extract the tomcat files and place it any directory you want. 

In my case, this tomcat6 resides in /usr/local/tomcat6. I think you also need to configure Tomcat6 before you use it, at least specifiy several environmental varibles. 
Here is a good reference : https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

And then you can create an empty file, and add the following content in: 

#!/bin/sh
### BEGIN INIT INFO
# Provides:          tomcat6
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Start/stop tomcat6 web server
### END INIT INFO
#
# tomcat6               This init.d script is used to start tomcat6.

export JAVA_HOME=/usr/lib/jvm/java-7-oracle # change this directory into your JAVA_HOME directory
export CATALINA_HOME=/usr/local/tomcat6 # change this directory with your tomcat location
case $1 in start) sh /usr/local/tomcat6/bin/startup.sh # change this directory with your tomcat startup script ;; stop) sh /usr/local/tomcat6/bin/shutdown.sh # chagne this directory with your tomcat shutdown script ;; restart) sh /usr/local/tomcat6/bin/shutdown.sh # change if needed sh /usr/local/tomcat6/bin/startup.sh # change if needed ;; esac exit 0

Save this file as Tomcat6, throw it into /etc/init.d/ directory, and modify file permissions: 

sudo chmod 755 /etc/init.d/tomcat6

And type the following to start tomcat service automatically during reboot: 

sudo update-rc.d tomcat6 defaults

 

and you are able to type the following in the terminal: 

sudo service tomcat6 start
sudo service tomcat6 shutdown
sudo service tomcat6 restart

as needed in the future. 

posted @ 2015-02-19 10:02  Rui Yan  阅读(551)  评论(0编辑  收藏  举报