systemctl stop 不停止 Redhat 中的所有进程

systemctl stop 不停止 Redhat 中的所有进程

我正在使用 systemctl 启动服务,但我面临着在 Redhat 系统中停止服务的问题。

我正在创建的服务文件:

[Unit]
Description=/home/agenttest
After=syslog.target

[Service]
ExecStart=/bin/bash /home/agenttest/service/test.sh
SuccessExitStatus=143
TimeoutStopSec=10
KillMode=mixed

[Install]
WantedBy=multi-user.target

在 test.sh 中我使用以下命令:

sudo /home/ec2-user/jdk1.8.0_211/jre/bin/java -jar /home/agenttest/service/agent.jar --spring.config.location=classpath:/test.properties,/home/agenttest/service/test.properties --server.port=8081

服务成功启动:

在此输入图像描述

但是当我使用命令停止服务时systemctl stop <service_name>,所有进程都没有停止。

我使用以下命令停止服务:

sudo systemctl stop ConnectOnceAgent_8081_PROD_SYSTEMCTL

sudo systemctl disable ConnectOnceAgent_8081_PROD_SYSTEMCTL

但尽管服务显示已停止,但所有进程仍在运行:

4     0 10166 10129  20   0 3466036 296488 -    Sl   ?          3:58 /home/ec2-user/jdk1.8.0_211/jre/bin/java -jar /home/agenttest/service/agent.jar -
4     0 10167 10135  20   0 3463436 517428 -    Sl   ?          2:00 /home/ec2-user/jdk1.8.0_211/jre/bin/java -jar /home/agenttest/service/agent.jar -
4     0 10168 10140  20   0 3460760 514544 -    Sl   ?          2:01 /home/ec2-user/jdk1.8.0_211/jre/bin/java -jar /home/agenttest/service/agent.jar -
4     0 10169 10142  20   0 3460760 531220 -    Sl   ?          2:03 /home/ec2-user/jdk1.8.0_211/jre/bin/java -jar /home/agenttest/service/agent.jar -
4     0 10170 10141  20   0 3460684 515260 -    Sl   ?          2:02 /home/ec2-user/jdk1.8.0_211/jre/bin/java -jar /home/agentt

当我运行时ps -ef | grep -i 8081,它显示以下日志:

root     10140     1  0 Sep18 ?        00:00:00 sudo /home/ec2-user/jdk1.8.0_211/jre/bin/java -jar /home/agenttest/service/agent.jar --spring.config.location=classpath:/executorService.properties,/home/agenttest/service/ConnectOnceAgent_8081_PROD.properties --server.port=8081
root     10168 10140  0 Sep18 ?        00:02:01 /home/ec2-user/jdk1.8.0_211/jre/bin/java -jar /home/agenttest/service/agent.jar --spring.config.location=classpath:/executorService.properties,/home/agenttest/service/ConnectOnceAgent_8081_PROD.properties --server.port=8081
ec2-user 17230 17186  0 10:44 pts/0    00:00:00 grep --color=auto -i 8081

我只在 redhat 中看到这个问题。对于其他 Linux 系统,它工作正常。

但所有进程仍在运行,尽管服务显示已停止:

此外,我还更改了KillMode=mixed其他属性,例如控制组、进程、混合,但没有注意到工作正常。

请帮忙。

提前致谢!

答案1

systemctl 正在停止主进程 3714。但是创建的子进程/home/agenttest/service/test.sh仍处于活动状态。

考虑改变关注

ExecStart=/bin/bash /home/agenttest/service/test.sh

到以下

ExecStart=/home/ec2-user/jdk1.8.0_211/jre/bin/java -jar /home/agenttest/service/agent.jar --spring.config.location=classpath:/test.properties,/home/agenttest/service/test.properties --server.port=8081

相关内容