Tomcat开机自启动和查看启动项命令(linux)
问题:每次CentOS重启后,都要手动cd到tomcat的目录下,进行./startup.sh启动tomcat
-
修改tomcat的catalina.sh文件
vi catalina.sh
添加以下中间行代码
[ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME" CATALINA_PID="$CATALINA_BASE/tomcat.pid"(这行是你新增加的,在上下两行之间) # Ensure that any user defined CLASSPATH variables are not used on startup,
:wq 修改保存退出
2. 添加或修改tomcat.service
vi /usr/lib/systemd/system/tomcat.service
修改成
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/local/java/jdk1.8" (填写自己jdk的路径)
PIDFile=/usr/local/tomcat/apache-tomcat-8.5.39/tomcat.pid (填写自己tomcat的路径)
ExecStart=/usr/local/tomcat/apache-tomcat-8.5.39/bin/startup.sh (填写自己tomcat的路径)
ExecStop=/bin/kill -s QUIT $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
:wq 修改保存退出
3. 重新载入修改后配置文件,让设置生效
systemctl daemon-reload
4. 启动tomcat.service
systemctl start tomcat.service
5. 查看tomcat.service运行状态
systemctl status tomcat.service
6. 将tomcat.service添加的自启动
systemctl enable tomcat.service
linnux查看开机启动项的命令
查看开机启动项
systemctl list-unit-files
查看单个服务开机启动状态
第一种方法
systemctl list-unit-files | grep 服务名称
第二种命令行
systemctl list-unit-files 服务名称.service