/2/5 Linux: Set tomcat to automatically start a server in the branch after startup. After restart, I always forget to start Tomcat. The developers asked me to set it to automatically start upon startup, however, it took some time to complete the modification. I have referenced several posts on the Internet, but none of them are very suitable. I still need to modify them by myself, probably as follows: [root @ appsit init. d] # pwd
/Etc/init. d
[Root @ appsit init. d] # Cat tomcatd
#! /Bin/sh
# Chkconfig: 345 99 10
# Description: auto-starts Tomcat
#/Etc/init. d/tomcatd
# Tomcat auto-start # source function library.
./Etc/init. d/functions # source networking configuration.
./Etc/sysconfig/networkretval = 0 # catalina_home = "/usr/apps/Apache/tomcat/jakarta-tomcat-4.0.4"
Export java_home =/tomcat/Java/jdk1.5.0 _ 09
Export catalina_home =/tomcat/Apache-Tomcat-5.5.20
Export catalina_base =/tomcat/Apache-Tomcat-5.5.20
Tomcatuser = tomcatstart ()
{
If [-F $ catalina_home/bin/startup. Sh];
Then
Echo $ "Starting Tomcat"
/Bin/su $ tomcatuser-C $ catalina_home/bin/startup. Sh
Retval =$?
Echo "OK"
Return $ retval
Fi
} STOP ()
{
If [-F $ catalina_home/bin/shutdown. Sh];
Then
Echo $ "Stopping Tomcat"
/Bin/su $ tomcatuser-C $ catalina_home/bin/shutdown. Sh
Retval =$?
Sleep 1
PS-fwwu Tomcat | grep APACHE-Tomcat | grep-V grep | grep-v pid | awk '{print $2}' | xargs kill-9
Echo "OK"
# [$ Retval-EQ 0] & Rm-F/var/lock /...
Return $ retval
Fi
} Case "$1" in
Start)
Start
; Stop)
Stop
;;
Restart)
Echo $ "restaring Tomcat"
$0 stop
Sleep 1
$0 start
;;
*)
Echo $ "Usage: $0 {START | stop | restart }"
Exit 1
;;
Esacexit $ retval [root @ appsit init. d] # chmod U + x tomcatd
[Root @ appsit init. d] # chkconfig -- add tomcatd [root @ appsit init. d] # chkconfig -- list tomcatd
Tomcatd 0: off 1: off 2: off 3: On 4: On 5: on 6: off [root @ appsit init. d] # service tomcatd stop Delete: [root @ appsit init. d] # chkconfig -- del tomcatd
Not fully written yet. For example, the Tomcat user uses a variable instead of retval =$? To return the exit status of the last command ,...
These remain for future improvement You can also refer to this: http://nio.infor96.com/archives/86