]> granicus.if.org Git - icinga2/commitdiff
Implement ApiListener status file removal on shutdown
authorMichael Friedrich <michael.friedrich@icinga.com>
Thu, 9 Aug 2018 09:54:34 +0000 (11:54 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 9 Aug 2018 09:54:34 +0000 (11:54 +0200)
lib/remote/apilistener.cpp
lib/remote/apilistener.hpp

index 84931086ff1afa18af36c7c66c6b710857fc5253..bcfa296800874c8601b526f1b02486414291ba44 100644 (file)
@@ -264,8 +264,12 @@ void ApiListener::Stop(bool runtimeDeleted)
        Log(LogInformation, "ApiListener")
                << "'" << GetName() << "' stopped.";
 
-       boost::mutex::scoped_lock lock(m_LogLock);
-       CloseLogFile();
+       {
+               boost::mutex::scoped_lock lock(m_LogLock);
+               CloseLogFile();
+       }
+
+       RemoveStatusFile();
 }
 
 ApiListener::Ptr ApiListener::GetInstance()
@@ -1482,3 +1486,17 @@ void ApiListener::UpdateStatusFile(TcpSocket::Ptr socket)
                {"port", details.second}
        }));
 }
+
+void ApiListener::RemoveStatusFile()
+{
+       String path = Application::GetConst("CacheDir") + "/api-state.json";
+
+       if (Utility::PathExists(path)) {
+               if (unlink(path.CStr()) < 0 && errno != ENOENT) {
+                       BOOST_THROW_EXCEPTION(posix_error()
+                               << boost::errinfo_api_function("unlink")
+                               << boost::errinfo_errno(errno)
+                               << boost::errinfo_file_name(path));
+               }
+       }
+}
index 8b46c4cb37e40d81d43480f2ad21f6ac4df2c77e..27d236eaaad39740605147a776b5a53a868b8b6e 100644 (file)
@@ -114,8 +114,6 @@ protected:
        void Start(bool runtimeCreated) override;
        void Stop(bool runtimeDeleted) override;
 
-       void UpdateStatusFile(TcpSocket::Ptr socket);
-
        void ValidateTlsProtocolmin(const Lazy<String>& lvalue, const ValidationUtils& utils) override;
 
 private:
@@ -165,6 +163,9 @@ private:
 
        static void CopyCertificateFile(const String& oldCertPath, const String& newCertPath);
 
+       void UpdateStatusFile(TcpSocket::Ptr socket);
+       void RemoveStatusFile();
+
        /* filesync */
        static ConfigDirInformation LoadConfigDir(const String& dir);
        static Dictionary::Ptr MergeConfigUpdate(const ConfigDirInformation& config);