1.腳本路徑 /etc/init.d/tomcat
首先執(zhí)行: vi /etc/init.d/tomcat
將下面內(nèi)容根據(jù)你自己的情況(主要是修改 /usr/local/tomcat7 )
修改后copy到編輯框中, esc 退出編輯,:wq 保存退出
# !/bin/bash
# Description: start or stop the tomcat
# Usage: tomcat [start|stop|restart]
#
export PATH=$PATH:$HOME/bin
export BASH_ENV=$HOME/.bashrc
export USERNAME="root"
tomcatHome=/usr/local/tomcat7
case "$1" in
start)
#startup the tomcat
cd ${tomcatHome}/bin
./startup.sh
;;
stop)
# stop tomcat
cd ${tomcatHome}/bin
./shutdown.sh
echo "Tomcat Stoped"
;;
restart)
$0 stop
$0 start
;;
serconf)
cd ${tomcatHome}/conf
vim ./server.xml
;;
catconf)
vim ${tomcatHome}/bin/catalina.sh
;;
log)
cd ${tomcatHome}/logs
cat ./catalina.out
;;
clearlog)
cd ${tomcatHome}/logs
rm -rf ./*
;;
state)
ps -aux|grep tomcat
;;
*)
echo "tomcat: usage: tomcat [start|stop|restart|serconf|catconf|log|tail|clearlog|state]"
exit 1
esac
exit 0
2.更改tomcat腳本為可執(zhí)行文件
chmod +x /etc/init.d/tomcat
3.為了在任意路徑都可執(zhí)行此腳本坦冠,需要添加到/usr/bin目錄中
cd /usr/bin
ln -s /etc/init.d/tomcat