Provide for daemons (applications running as services under docker as an example) to limit themselves to a single instance per "name".
- C++20
- Useful for running "daemons" under docker where you may not always have or wish for a true service under the operating system.
- Use the nuget SiddiqSoft.DaemonLockfile
- You can also git submodule:
git submodule add https://github.com/SiddiqSoft/DaemonLockfile.git
- Copy paste..whatever works.
Example (when using nuget to add the header in the solution)
#include "siddiqsoft/DaemonLockfile.hpp"
// Example daemon host structure
struct MyDaemonType
{
siddiqsoft::DaemonLockfile myLockfile{"MyDaemonType", true}; //force acquire
..
..
};
// The "daemon" will hold the lock and when the application exits the lock will be released.
static MyDaemonType daemon;
int main(int argc, char *argv[])
{
// Bailout immediately if we do not have a lock--this implies some other instance is running
if(!daemon.myLockfile.isLocked) return 1;
..
..
// We have the exclusice lock
}
© 2021 Siddiq Software LLC. All rights reserved.