使用systemctl stop nacos命令关闭nacos时,nacos.service进入失败状态

问题描述:
安装完成nacos后,编写启动脚本,使用systemctl start nacos服务运行正常

● nacos.service - nacos
   Loaded: loaded (/etc/systemd/system/nacos.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2022-07-12 08:31:20 CST; 54s ago
  Process: 2136 ExecStop=/usr/local/nacos/bin/shutdown.sh (code=exited, status=0/SUCCESS)
  Process: 2158 ExecStart=/usr/local/nacos/bin/startup.sh -m standalone (code=exited, status=0/SUCCESS)
 Main PID: 2181 (java)
    Tasks: 119
   Memory: 501.8M
   CGroup: /system.slice/nacos.service
           └─2181 /home/soft/java/jdk1.8.0_331/bin/java -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Djava.ext.dirs=/home/soft/java/jdk1.8.0_331/jre/lib/ext...

7月 12 08:31:20 centos7 systemd[1]: Starting nacos...
7月 12 08:31:20 centos7 startup.sh[2158]: /home/soft/java/jdk1.8.0_331/bin/java  -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Djava.ext.dirs=/h...XX:+PrintGCD
7月 12 08:31:20 centos7 startup.sh[2158]: nacos is starting with standalone
7月 12 08:31:20 centos7 startup.sh[2158]: nacos is starting,you can check the /usr/local/nacos/logs/start.out
7月 12 08:31:20 centos7 systemd[1]: Started nacos.
Hint: Some lines were ellipsized, use -l to show in full.

使用systemctl stop nacos关闭服务时,出现

● nacos.service - nacos
   Loaded: loaded (/etc/systemd/system/nacos.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 二 2022-07-12 08:45:24 CST; 4s ago
  Process: 2361 ExecStop=/usr/local/nacos/bin/shutdown.sh (code=exited, status=0/SUCCESS)
  Process: 2158 ExecStart=/usr/local/nacos/bin/startup.sh -m standalone (code=exited, status=0/SUCCESS)
 Main PID: 2181 (code=exited, status=143)

7月 12 08:31:20 centos7 startup.sh[2158]: nacos is starting with standalone
7月 12 08:31:20 centos7 startup.sh[2158]: nacos is starting,you can check the /usr/local/nacos/logs/start.out
7月 12 08:31:20 centos7 systemd[1]: Started nacos.
7月 12 08:45:00 centos7 systemd[1]: Stopping nacos...
7月 12 08:45:00 centos7 shutdown.sh[2361]: The nacosServer(2181) is running...
7月 12 08:45:00 centos7 shutdown.sh[2361]: Send shutdown request to nacosServer(2181) OK
7月 12 08:45:24 centos7 systemd[1]: nacos.service: main process exited, code=exited, status=143/n/a
7月 12 08:45:24 centos7 systemd[1]: Stopped nacos.
7月 12 08:45:24 centos7 systemd[1]: Unit nacos.service entered failed state.
7月 12 08:45:24 centos7 systemd[1]: nacos.service failed.

可以看到status=143,Unit nacos.service entered failed state。
原因:
退出码143意味着程序接收到SIGTERM信号来指示它退出。JVM捕获信号,执行干净的关闭,即它运行所有注册的shutdown hooks,但仍然以143的退出代码退出。
解决:
可以通过在单元文件中添加退出代码作为“success”退出状态来抑制这种情况。修改nacos.service文件添加

[Service]
SuccessExitStatus=143

结果:

● nacos.service - nacos
   Loaded: loaded (/etc/systemd/system/nacos.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

7月 12 09:14:01 centos7 systemd[1]: Stopped nacos.
7月 12 09:14:14 centos7 systemd[1]: Starting nacos...
7月 12 09:14:14 centos7 startup.sh[2858]: /home/soft/java/jdk1.8.0_331/bin/java  -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Djava.ext.dirs=/h...XX:+PrintGCD
7月 12 09:14:14 centos7 startup.sh[2858]: nacos is starting with standalone
7月 12 09:14:14 centos7 startup.sh[2858]: nacos is starting,you can check the /usr/local/nacos/logs/start.out
7月 12 09:14:14 centos7 systemd[1]: Started nacos.
7月 12 09:14:17 centos7 systemd[1]: Stopping nacos...
7月 12 09:14:17 centos7 shutdown.sh[2918]: The nacosServer(2881) is running...
7月 12 09:14:17 centos7 shutdown.sh[2918]: Send shutdown request to nacosServer(2881) OK
7月 12 09:14:20 centos7 systemd[1]: Stopped nacos.
Hint: Some lines were ellipsized, use -l to show in full.

来源:
https://serverfault.com/questions/695849/services-remain-in-failed-state-after-stopped-with-systemctl/695863#695863

你可能感兴趣的:(笔记,java,服务器,linux)