日期:2014-05-16  浏览次数:20634 次

linux为了可以更方便的启动|关闭|重启 tomcat,做个脚本
脚本路径 /etc/init.d/tomcat

首先执行: vi /etc/init.d/tomcat
按 a 编辑,将下面内容根据你自己的情况(主要是修改 /usr/local/tomcat6/bin/ )
修改后copy到编辑框中, esc 退出编辑,:wq 保存退出

------------------
-----脚本内容-----
------------------
	# !/bin/bash
	# Description: start or stop the tomcat
	# Usage:        tomcat [start|stop|reload|restart]
	#
	export PATH=$PATH:$HOME/bin
	export BASH_ENV=$HOME/.bashrc
	export USERNAME="root"

	case "$1" in
	start)
	#startup the tomcat
   	echo -n "tomcat start: "
		cd /usr/local/tomcat6/bin/
	./startup.sh
   	echo " Tomcat start finished"
	;;
	stop)
	# stop tomcat
  	 echo -n "tomcat stop:"
  	 ps -ef | grep "java" | grep -v grep | sed 's/ [ ]*/:/g'|cut -d: -f2| kill -9 `cat`
	cd /usr/local/tomcat6/work
	rm -rf Catalina
       	echo "finished"
    	;;
    	reload|restart)
        	$0 stop
        	$0 start
    	;;
    	*)
       	echo "Usage: tomcat [start|stop|reload|restart]"
       	exit 1
    	esac
    	exit 0

---------------------

更改tomcat脚本为可执行文件
引用
[root@localhost]# chmod +x /etc/init.d/tomcat


        为了在任意路径都可执行此脚本,需要添加到/usr/bin目录中
引用
[root@localhost]# cd /usr/bin
	[root@localhost]# ln -s /etc/init.d/tomcat .
1 楼 liujickson 2011-05-08  
支持,楼主太好了