Tomcat无法从centos7.2上的systemctl开始

时间:2016-11-04 14:20:30

标签: linux tomcat

  1. CentOS7.2
  2. Tomcat9
  3. JDK8
  4. 我已经在我的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
    

1 个答案:

答案 0 :(得分:2)

JAVA_HOME文件的JRE_HOME部分添加Servicetomcat.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验证单元文件是否已进行更改。