技术解析

tomcat systemd service in ubuntu
0
2021-06-18 23:37:59
idczone
在自定义 tomcat 成系统服务时候出现了问题,
```
sudo service tomcat-ad status
● tomcat-ad.service - Ad Service
Loaded: loaded (/etc/systemd/system/tomcat-ad.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-01-07 15:27:00 CST; 1s ago
Process: 23931 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
Process: 23991 ExecStart=/home/hadoop/ad-server/apache-tomcat-7.0.82/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 24000 (java)
Tasks: 28
Memory: 375.8M
CPU: 4.753s
CGroup: /system.slice/tomcat-ad.service
└─24000 /usr/java/jdk1.8.0_151/bin/java -Djava.util.logging.config.file=/home/hadoop/ad-server/apache-tomcat-7.0.82/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager

Jan 07 15:27:00 node3 systemd[1]: Starting Ad Service...
Jan 07 15:27:00 node3 startup.sh[23991]: Tomcat started.
Jan 07 15:27:00 node3 systemd[1]: Started Ad Service.
```
status 查看是 active 但是我 stop 时候时候显示是 failed
```
tomcat-ad.service - Ad Service
Loaded: loaded (/etc/systemd/system/tomcat-ad.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2020-01-07 15:26:48 CST; 3s ago
Process: 23931 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
Process: 23826 ExecStart=/home/hadoop/ad-server/apache-tomcat-7.0.82/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 23835 (code=exited, status=143)

Jan 07 15:25:59 node3 systemd[1]: Starting Ad Service...
Jan 07 15:25:59 node3 startup.sh[23826]: Tomcat started.
Jan 07 15:25:59 node3 systemd[1]: Started Ad Service.
Jan 07 15:26:47 node3 systemd[1]: Stopping Ad Service...
Jan 07 15:26:48 node3 systemd[1]: tomcat-ad.service: Main process exited, code=exited, status=143/n/a
Jan 07 15:26:48 node3 systemd[1]: Stopped Ad Service.
Jan 07 15:26:48 node3 systemd[1]: tomcat-ad.service: Unit entered failed state.
Jan 07 15:26:48 node3 systemd[1]: tomcat-ad.service: Failed with result 'exit-code'.
```
为什么是 return status 143 呢?
顺便贴上 服务脚本是怎么写的
```
[Unit]
Description=Ad Service
[Service]
Type=forking
PIDFile=/home/hadoop/ad-server/apache-tomcat-7.0.82/bin/catalina.pid
Restart=on-failure
WorkingDirectory=/home/hadoop/ad-server/apache-tomcat-7.0.82/
ExecStart=/home/hadoop/ad-server/apache-tomcat-7.0.82/bin/startup.sh
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
```

tomcat 开启了 jmx

将 SuccessExitStatus=143 添加上 就可以,结贴

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服