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. 

转载于:https://www.cnblogs.com/RuiYan/p/4296027.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值