以centos爲例apache
建立一個tomcat文件,內容以下centos
#!/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.77 startup=$tomcat/bin/startup.sh shutdown=$tomcat/bin/shutdown.sh start() { 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 options case "$1" in start) start ;; stop) stop ;; status) status ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|restart|status}" exit 1 esac exit 0
將tomcat文件複製到/etc/init.d目錄下tomcat
受權bash
cd /etc/init.d chmod u+x tomcat
設置tomcat爲一個服務rest
chkconfig --add tomcat
設置tomcat自啓動code
chkconfig tomcat on
嘗試以下命令吧ip
service tomcat start service tomcat status service tomcat restart service tomcat stop