Linux开机启动Tomcat
- 需求背景
Linux重启后要手动执行"startup.sh"启动Tomcat,比较麻烦,想要Linux开机启动Tomcat。
- 开机启动
#----------------------------------------------------------
sudo tee /usr/bin/tomcat.sh <<-'EOF'
#! /bin/bash
nohup /opt/tomcat/bin/startup.sh > /opt/tomcat/nohup.log &
EOF
chmod +x /usr/bin/tomcat.sh
#----------------------------------------------------------
sudo tee /etc/systemd/system/tomcat.service <<-'EOF'
[Unit]
Description=tomcat
After=syslog.target network.target
[Service]
Environment="JAVA_HOME=/opt/jdk"
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/tomcat.sh
[Install]
WantedBy=multi-user.target
EOF
#----------------------------------------------------------
systemctl enable tomcat
#----------------------------------------------------------
# 启动tomcat
systemctl start tomcat
# 停止tomcat
systemctl stop tomcat
# 重启tomcat
systemctl restart tomcat
# 查看tomcat状态
systemctl status tomcat
- 注意事项
#----------------------------------------------------------
"tomcat.service"不添加Environment="JAVA_HOME=/opt/jdk"报错如下
#----------------------------------------------------------
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
#----------------------------------------------------------
解决方法:"startup.sh"首行添加"export JAVA_HOME=/opt/jdk"可解决
#----------------------------------------------------------
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/66016.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!