标签:
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