我已经在我的evn中设置JAVA_HOME
并在cammand行中运行catalina.sh run
,tomcat开始成功。但我使用systemctl start tomcat.service
我收到错误。
11月 04 22:13:02 iZwz90squb7zj67pw5hyizZ systemd[1]: Starting tomcat...
11月 04 22:13:02 iZwz90squb7zj67pw5hyizZ startup.sh[1058]: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
11月 04 22:13:02 iZwz90squb7zj67pw5hyizZ startup.sh[1058]: At least one of these environment variable is needed to run this program
11月 04 22:13:02 iZwz90squb7zj67pw5hyizZ systemd[1]: tomcat.service: main process exited, code=exited, status=1/FAILURE
11月 04 22:13:02 iZwz90squb7zj67pw5hyizZ systemd[1]: Failed to start tomcat.
11月 04 22:13:02 iZwz90squb7zj67pw5hyizZ systemd[1]: Unit tomcat.service entered failed state.
11月 04 22:13:02 iZwz90squb7zj67pw5hyizZ systemd[1]: tomcat.service failed.
这是我的tomcat.service
。
[Unit]
Description=tomcat
After=network.target
[Service]
Type=oneshot
Environment=CATALINA_PID=/var/run/tomcat.pid
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
ExecReload=/usr/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
答案 0 :(得分:2)
在JAVA_HOME
文件的JRE_HOME
部分添加Service
或tomcat.service
环境变量。
Systemd不会使用shell实例的环境变量,因此您需要将它们添加到配置中。
例如:
[Unit]
Description=tomcat
After=network.target
[Service]
Type=oneshot
Environment=JAVA_HOME=/path/to/jre
Environment=CATALINA_PID=/var/run/tomcat.pid
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
ExecReload=/usr/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
您需要运行systemctl daemon-reload
以加载服务文件的更新。您可以使用systemctl cat tomcat.service
验证单元文件是否已进行更改。