Tomcat 重启时启动:init.d 脚本不成功
Tomcat Start on Reboot: init.d script unsuccessful
我需要 tomcat 在 linux OS 重新启动后启动。我无法通过重启 init.d 正常运行。
OS 和版本:
JRE: 1.8.0
JAVA: 1.8.0
Tomcat: 8.5.34
Linux: Amazon Linux 2
****以 ROOT 身份完成所有步骤
TOMCAT部署配置:
1) Install tomcat 8.5.34 using a tar.gz gzip file
2) configure /{$TOMCAT}/conf/server.xml to use 443 connectors
3) Deploy MicroStrategy application through deploying a .war file on restart
4) configure SSL keys using Java Key Store
5) configure microstrategy webapp for SAML authentication using PING
init.d 脚本部署配置
注意:我已经通过 /etc/init.d/tomcat 和 chkconfig 实用程序尝试了各种脚本。
1) 使用 vi 创建 tomcat
2)插入脚本(我试过很多脚本,但是这个似乎
最接近我所需要的,也是最明确的)
3) chmod 755 /etc/init.d/tomcat
4) chkconfig --add tomcat
5) chkconfig --level 2345 tomcat on (此命令不成功)
6) chkconfig --list tomcat (returns tomcat 0:off 1:off 2:off 3:on 4:on 5:on 6:off)
此脚本测试成功:
./etc/init.d/tomcat start
./etc/init.d/tomcat stop
./etc/init.d/tomcat restart
已确认 chkconfig 创建了链接:
/etc/rc1.d K20tomcat
/etc/rc2.d K20tomcat
/etc/rc3.d S82tomcat
/etc/rc4.d S82tomcat
/etc/rc5.d S82tomcat
/etc/rc6.d K20tomcat
Tomcat
的脚本文件
#!/bin/sh
#
# chkconfig: 345 82 20
#
# description: Tomcat Service
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
JRE_HOME=/usr/lib/jvm/jre-1.8.0-openjdk
CATALINA_HOME=/opt/apache-tomcat-8.5.34
export JAVA_HOME JRE_HOME CATALINA_HOME
case in
start)
cd $CATALINA_HOME/bin
./startup.sh
;;
stop)
cd $CATALINA_HOME/bin
./shutdown.sh
;;
restart)
cd $CATALINA_HOME/bin
./shutdown.sh
./startup.sh
;;
*)
echo "Usage: [=16=] {start|stop|restart}"
exit 1
esac
exit 0
预期
我希望 URL 位于 {$TOMCAT}/webapps/ROOT 的基础 URL 可以在重启后从指向此设备的 Public URL 访问. tomcat 服务在重启后仍处于停止状态。
有什么建议吗?
Amazon Linux 2 使用 systemd
服务管理器,它应该向后兼容 systemv
初始化脚本 提供 执行 systemd-sysv-generator
从 /etc/init.d
脚本中生成 服务单元 (我认为不推荐在你的情况下)。
由于您是自己编写脚本,因此建议您编写适当的 service unit.
用于安装 tomcat.
的 tar.gz 上可能已经存在这样的 *.service 文件
启用 tomcat 使用 systemd 而不是 systemv
描述
使用的脚本比较简单,因为它唯一的作用就是在重启时启动服务器。我已经使用 TOMCAT bin 中的 setenv.sh 建立了所有必需的环境变量。
变量
- 测试:任何字母数字值
- TOMCAT_INSTALL_PATH:你安装的位置TOMCAT
步骤
- 在/etc/systemd/system
中创建文件tomcat@.service
- 可以在 /etc/systemd/system/multi-user.target.wants/tomcat.service
中找到模板
tomcat@.service
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment="CATALINA_HOME={TOMCAT_INSTALL_PATH}"
ExecStart=/opt/apache-tomcat-8.5.34/bin/startup.sh
ExecStop=$CATALINA_HOME/bin/shutdown.sh
SuccessExitStatus=143
User=root
[Install]
WantedBy=multi-user.target
- 创建空 tomcat.pid 文件(我的在 {TOMCAT_INSTALL_PATH}/conf
- 在 {TOMCAT_INSTALL_PATH}/箱
- systemctl daemon-reload
- systemctl 启用 tomcat@test.service
- systemctl 启动tomcat@test.service
疑难解答
systemctl 状态 tomcat@test.service -l
-此命令将向控制台提供日志输出,控制台显示的输出也写入 systemctl 日志。我在初始设置时收到错误,因为 tomcat 无法解释哪个是主要的 tomcat 进程,并且会在读取其他进程的末尾时关闭。这是通过在 /conf 文件夹中创建一个 pid 文件并在 setenv.sh 中设置 CATALINA_PID 变量来解决的。
我需要 tomcat 在 linux OS 重新启动后启动。我无法通过重启 init.d 正常运行。
OS 和版本:
JRE: 1.8.0
JAVA: 1.8.0
Tomcat: 8.5.34
Linux: Amazon Linux 2
****以 ROOT 身份完成所有步骤
TOMCAT部署配置:
1) Install tomcat 8.5.34 using a tar.gz gzip file
2) configure /{$TOMCAT}/conf/server.xml to use 443 connectors
3) Deploy MicroStrategy application through deploying a .war file on restart
4) configure SSL keys using Java Key Store
5) configure microstrategy webapp for SAML authentication using PING
init.d 脚本部署配置
注意:我已经通过 /etc/init.d/tomcat 和 chkconfig 实用程序尝试了各种脚本。
1) 使用 vi 创建 tomcat
2)插入脚本(我试过很多脚本,但是这个似乎
最接近我所需要的,也是最明确的)
3) chmod 755 /etc/init.d/tomcat
4) chkconfig --add tomcat
5) chkconfig --level 2345 tomcat on (此命令不成功)
6) chkconfig --list tomcat (returns tomcat 0:off 1:off 2:off 3:on 4:on 5:on 6:off)
此脚本测试成功:
./etc/init.d/tomcat start
./etc/init.d/tomcat stop
./etc/init.d/tomcat restart
已确认 chkconfig 创建了链接:
/etc/rc1.d K20tomcat
/etc/rc2.d K20tomcat
/etc/rc3.d S82tomcat
/etc/rc4.d S82tomcat
/etc/rc5.d S82tomcat
/etc/rc6.d K20tomcat
Tomcat
的脚本文件#!/bin/sh
#
# chkconfig: 345 82 20
#
# description: Tomcat Service
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
JRE_HOME=/usr/lib/jvm/jre-1.8.0-openjdk
CATALINA_HOME=/opt/apache-tomcat-8.5.34
export JAVA_HOME JRE_HOME CATALINA_HOME
case in
start)
cd $CATALINA_HOME/bin
./startup.sh
;;
stop)
cd $CATALINA_HOME/bin
./shutdown.sh
;;
restart)
cd $CATALINA_HOME/bin
./shutdown.sh
./startup.sh
;;
*)
echo "Usage: [=16=] {start|stop|restart}"
exit 1
esac
exit 0
预期
我希望 URL 位于 {$TOMCAT}/webapps/ROOT 的基础 URL 可以在重启后从指向此设备的 Public URL 访问. tomcat 服务在重启后仍处于停止状态。
有什么建议吗?
Amazon Linux 2 使用 systemd
服务管理器,它应该向后兼容 systemv
初始化脚本 提供 执行 systemd-sysv-generator
从 /etc/init.d
脚本中生成 服务单元 (我认为不推荐在你的情况下)。
由于您是自己编写脚本,因此建议您编写适当的 service unit.
用于安装 tomcat.
启用 tomcat 使用 systemd 而不是 systemv
描述
使用的脚本比较简单,因为它唯一的作用就是在重启时启动服务器。我已经使用 TOMCAT bin 中的 setenv.sh 建立了所有必需的环境变量。
变量
- 测试:任何字母数字值
- TOMCAT_INSTALL_PATH:你安装的位置TOMCAT
步骤
- 在/etc/systemd/system 中创建文件tomcat@.service
- 可以在 /etc/systemd/system/multi-user.target.wants/tomcat.service
tomcat@.service
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment="CATALINA_HOME={TOMCAT_INSTALL_PATH}"
ExecStart=/opt/apache-tomcat-8.5.34/bin/startup.sh
ExecStop=$CATALINA_HOME/bin/shutdown.sh
SuccessExitStatus=143
User=root
[Install]
WantedBy=multi-user.target
- 创建空 tomcat.pid 文件(我的在 {TOMCAT_INSTALL_PATH}/conf
- 在 {TOMCAT_INSTALL_PATH}/箱
- systemctl daemon-reload
- systemctl 启用 tomcat@test.service
- systemctl 启动tomcat@test.service
疑难解答
systemctl 状态 tomcat@test.service -l
-此命令将向控制台提供日志输出,控制台显示的输出也写入 systemctl 日志。我在初始设置时收到错误,因为 tomcat 无法解释哪个是主要的 tomcat 进程,并且会在读取其他进程的末尾时关闭。这是通过在 /conf 文件夹中创建一个 pid 文件并在 setenv.sh 中设置 CATALINA_PID 变量来解决的。