diff --git a/src/MicroService.cpp b/src/MicroService.cpp index 8d38982..4508404 100644 --- a/src/MicroService.cpp +++ b/src/MicroService.cpp @@ -451,12 +451,25 @@ namespace uCentral { return false; } + void MicroService::SavePID() { + try { + std::ofstream O; + O.open(Daemon()->DataDir() + "/pidfile",std::ios::binary | std::ios::trunc); + O << Poco::Process::id(); + O.close(); + } catch (...) + { + std::cout << "Could not save system ID" << std::endl; + } + } + int MicroService::main(const ArgVec &args) { MyErrorHandler ErrorHandler(*this); Poco::ErrorHandler::set(&ErrorHandler); if (!HelpRequested_) { + SavePID(); Poco::Logger &logger = Poco::Logger::get(DAEMON_APP_NAME); logger.notice(Poco::format("Starting %s version %s.",DAEMON_APP_NAME, Version())); diff --git a/src/MicroService.h b/src/MicroService.h index 26654f7..8bed9f3 100644 --- a/src/MicroService.h +++ b/src/MicroService.h @@ -22,6 +22,7 @@ #include "Poco/Crypto/Cipher.h" #include "Poco/SHA2Engine.h" #include "Poco/Net/HTTPServerRequest.h" +#include "Poco/Process.h" #include "uCentralTypes.h" #include "SubSystemServer.h" @@ -129,6 +130,9 @@ namespace uCentral { [[nodiscard]] MicroServiceMetaVec GetServices(); [[nodiscard]] bool IsValidAPIKEY(const Poco::Net::HTTPServerRequest &Request); + void SavePID(); + inline uint64_t GetPID() { return Poco::Process::id(); }; + private: bool HelpRequested_ = false; std::string LogDir_; diff --git a/stop.sh b/stop.sh new file mode 100755 index 0000000..f7992a2 --- /dev/null +++ b/stop.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +pidfilename="${UCENTRALSEC_ROOT}/data/pidfile" + +if [[ -f "${pidfilename}" ]] +then + kill -9 $(cat ${pidfilename}) +fi