Linux设置tomcat开机自启
一、创建 tomcat 服务配置文件
cd /etc/init.d/ 目录下创建
添加以下内容
注:JAVA_HOME、CATALINA_HOME改成自己本地对应的路径
#!/bin/sh #chkconfig: 345 99 10 # description: Auto-starts tomcat # /etc/init.d/tomcatd # Tomcat auto-start # Source function library. . /etc/init.d/functions # source networking configuration. . /etc/sysconfig/network RETVAL=0 export JAVA_HOME=/usr/local/java/jdk1.8.0_161 export CATALINA_HOME=/usr/local/tomcat export CATALINA_BASE=/usr/local/tomcat start() { if [ -f $CATALINA_HOME/bin/startup.sh ]; then echo $"Starting Tomcat" $CATALINA_HOME/bin/startup.sh RETVAL=$? echo " OK" return $RETVAL fi } stop() { if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then echo $"Stopping Tomcat" $CATALINA_HOME/bin/shutdown.sh RETVAL=$? sleep 1 ps -fwwu tomcat | grep apache-tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9 echo " OK" # [ $RETVAL -eq 0 ] && rm -f /var/lock/... return $RETVAL fi } case "$1" in start) start ;; stop) stop ;; restart) echo $"Restaring Tomcat" $0 stop sleep 1 $0 start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 ;; esac exit $RETVAL
二、给文件授权
chmod a+x /etc/init.d/tomcat
三、添加到服务列表
chkconfig --add tomcat
5.设置开机启动
chkconfig tomcat on
四、查看服务列表
chkconfig --list
[root@arcgis bin]# chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2,3,4,5都是开表示随系统而启动
五、启动 tomcat命令
service tomcat start

浙公网安备 33010602011771号