创建脚本
脚本创建路径 /etc/init.d/tomcat
首先执行: vi /etc/init.d/tomcat
按 i 编辑,将下面内容根据你自己的情况(修改/opt/tomcat8为你的tomcat路径)
修改后copy到编辑框中, esc 退出编辑,:wq 保存退出
# !/bin/bash
# Description: start or stop the tomcat
# Usage: tomcat [start|stop|restart|catalina]
#
export PATH=$PATH:$HOME/bin
export BASH_ENV=$HOME/.bashrc
export USERNAME="root"
case "$1" in
start)
#startup the tomcat
cd /opt/tomcat8/bin
./startup.sh
;;
stop)
# stop tomcat
cd /opt/tomcat8/bin
./shutdown.sh
echo "Tomcat Stoped"
;;
catalina)
#tomcat catalina
cd /opt/tomcat8/logs
tail -f catalina.out
echo "Tomcat catalina"
;;
#
restart)
$0 stop
$0 start
脚本添加执行权限
执行命令 chmod +x /etc/init.d/tomcat
创建软连接
执行下面两条命令
cd /usr/bin
ln -s /etc/init.d/tomcat .
测试
好了,用下面的命令愉快的去玩耍吧
tomcat start
tomcat stop
tomcat restart
tomcat catalina
原文:https://www.cnblogs.com/le-le/p/12359479.html