963   Linux Shell Tomcat

有时tomcat运行shutdown.sh也无法停止,只能直接kill掉,又不想每次敲命令,所以用shell写了个restart.sh

#!/bin/bash

##
# function start
##

# 检查tomcat是否存在
function check_tomcat
{
	echo -e "\n"
	echo -e "Start : check_tomcat \n"
	ps -ef | grep 'tomcat' | grep -v grep
	echo -e "End : check_tomcat \n"
	
}
# kill 掉tomcat
function kill_tomcat
{
	echo -e "\n"
	echo -e "Start : kill_tomcat \n"
	# 查找tomcat的进程,并强制杀死
	ps -ef | grep 'tomcat' | grep -v grep | awk '{print $2}' | xargs kill -9
	# 等待进程死掉
	sleep 2
	echo -e "End : kill_tomcat \n"
}

# 启动tomcat
function start_tomcat
{
	echo -e "\n"
	echo -e "Start : start_tomcat \n"
	# 启动tomcat
	./startup.sh
	# 等待tomcat启动
	sleep 2
	echo -e "End : start_tomcat \n"
}


# 用于循环执行函数
function run_main
{
	check_tomcat
	kill_tomcat
	check_tomcat
	start_tomcat
}


##
# function end
##


##
# main start
##

run_main


##
# main end
##



Leave a Reply

Your email address will not be published. Required fields are marked *