以centos为例
-
创建一个tomcat文件,内容如下
#!/bin/bash## Startup script for the tomcat# chkconfig: 2345 90 60# source function library. /etc/rc.d/init.d/functions# 这里的tomcat地址修改成你的tomcat地址tomcat=/apache-tomcat-7.0.77startup=$tomcat/bin/startup.shshutdown=$tomcat/bin/shutdown.shstart() { echo -n $"Starting Tomcat service: " sh $startup echo $?}stop() { echo -n $"Stopping Tomcat service: " sh $shutdown echo $?}restart() { stop start}status() { ps -aef | grep apache-tomcat | grep -v grep}# Handle the different input optionscase "$1" instart) start ;;stop) stop ;;status) status ;;restart) restart ;;*) echo $"Usage: $0 {start|stop|restart|status}" exit 1esacexit 0
将tomcat文件复制到/etc/init.d目录下
-
授权
cd /etc/init.dchmod u+x tomcat
-
设置tomcat为一个服务
chkconfig --add tomcat
-
设置tomcat自启动
chkconfig tomcat on
-
尝试如下命令吧
service tomcat startservice tomcat statusservice tomcat restartservice tomcat stop