码迷,mamicode.com
首页 > 其他好文 > 详细

tomcat autostart inti.d script

时间:2015-02-19 10:43:56      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

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

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 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. 

tomcat autostart inti.d script

标签:

原文地址:http://www.cnblogs.com/RuiYan/p/4296027.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!