Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        3年前关闭。
                                                                                            
                
        
我们在应用程序中使用Apache Zookeeper Client C绑定。客户端库版本为3.5.1。当Zookeeper连接断开连接时,该应用程序配置为退出,错误代码为116。

Systemd用于自动启动/停止应用程序。单位文件不会覆盖KillMode的默认设置,即send SIGTERM to the application

当使用systemctl stop指令停止该进程时,Zookeeper客户端线程似乎正在尝试重新连接到Zookeeper:

2016-04-12 22:34:45,799:4506(0xf14f7b40):ZOO_ERROR@handle_socket_error_msg@2363: Socket [128.0.0.4:61758] zk retcode=-4, errno=112(Host is down): failed while receiving a server response
2016-04-12 22:34:45,799:4506(0xf14f7b40):ZOO_INFO@check_events@2345: initiated connection to server [128.0.0.4:61758]
Apr 12 22:34:45 main thread:   zookeeperWatcher: event type ZOO_SESSION_EVENT state ZOO_CONNECTING_STATE path
2016-04-12 22:34:45,801:4506(0xf14f7b40):ZOO_INFO@check_events@2397: session establishment complete on server [128.0.0.4:61758], sessionId=0x40000015b8d0077, negotiated timeout=20000
2016-04-12 22:34:46,476:4506(0xf14f7b40):ZOO_WARN@zookeeper_interest@2191: Delaying connection after exhaustively trying all servers [128.0.0.4:61758]
2016-04-12 22:34:46,810:4506(0xf14f7b40):ZOO_INFO@check_events@2345: initiated connection to server [128.0.0.4:61758]
2016-04-12 22:34:46,811:4506(0xf14f7b40):ZOO_ERROR@handle_socket_error_msg@2382: Socket [128.0.0.4:61758] zk retcode=-112, errno=116(Stale file handle): sessionId=0x40000015b8d0077 h


因此,该过程正在退出,并显示错误代码。 Systemd在退出时会看到失败代码,并且不会尝试重新启动应用程序。有谁知道为什么客户端断开连接?

我知道我可以通过在单位文件中设置SuccessExitStatus=116来解决此问题,但是我不想掩盖真正的错误。我尝试为SIGTERM注册信号处理程序,并在处理程序中关闭Zookeeper客户端。但是,当我发出systemctl stop时,处理程序代码似乎从未受到攻击。

编辑:未调用处理程序,因为我使它异步-它没有在接收到信号后立即执行。 OTOH,在Zookeeper断开连接后,该过程立即退出。

最佳答案

当您为SIGTERM加载处理程序并发出systemctrl stop时会发生什么?
如果什么也没发生,那么您可能有一个遮罩,阻止了信号(我想不是)。
如果应用程序始终退出并显示相同的错误代码,则建议您确保正确加载了信号处理程序。

10-07 19:16
查看更多