|
lintel 0.2.0
|
#include <SingleInstanceBootstrapPlugin.h>
Public Member Functions | |
| SingleInstanceBootstrapPlugin (const std::shared_ptr< DatabaseConnectionConfigurations > &connectionConfigurations, std::shared_ptr< Configuration > configuration, std::shared_ptr< ProcessName > processName) | |
| ~SingleInstanceBootstrapPlugin () override | |
| void | onStart () override |
| BootstrapSequence | getPriority () override |
Public Member Functions inherited from lintel::BootstrapPlugin | |
| BootstrapPlugin ()=default | |
| virtual | ~BootstrapPlugin ()=default |
Bootstrap plugin that guarantees that a process with a database connection (the server) only runs once.
The plugin acquires an exclusive operating system file lock on <shared memory path>/<process name>.lock and holds it for the lifetime of the process. A second instance of the same process detects the conflict on startup and aborts fatally. The lock is released automatically by the operating system when the process exits or crashes, so no stale locks accumulate.
Processes without a default database connection (e.g. worker processes) are intentionally not restricted and skip the lock entirely.
| lintel::SingleInstanceBootstrapPlugin::SingleInstanceBootstrapPlugin | ( | const std::shared_ptr< DatabaseConnectionConfigurations > & | connectionConfigurations, |
| std::shared_ptr< Configuration > | configuration, | ||
| std::shared_ptr< ProcessName > | processName | ||
| ) |
Construct a SingleInstanceBootstrapPlugin.
| connectionConfigurations | database connection configurations |
| configuration | application configuration containing the shared memory path used for the lock file location |
| processName | the process name of the running process |
|
override |
|
overridevirtual |
Returns the priority for ordering this plugin in the bootstrap sequence.
Implements lintel::BootstrapPlugin.
|
overridevirtual |
Acquire the single instance lock unless no database connection exists.
Implements lintel::BootstrapPlugin.