Patronum/README.md

132 lines
3.3 KiB
Markdown
Raw Normal View History

2020-04-17 11:24:01 +03:00
# Patronum
2021-04-28 23:55:54 +03:00
2021-05-01 14:56:38 +03:00
This is extension libraries for control your daemons and rervices. This library will save you the time you spend building and deploying server daemons or services.
If you want to get more inforamtion about library see our [documentation](https://quasarapp.ddns.net:3031/docs/QuasarApp/Patronum/latest/)
2020-04-17 11:29:38 +03:00
2020-04-17 21:55:54 +03:00
### Why is Patronum?
2021-04-28 23:55:54 +03:00
2020-04-17 21:55:54 +03:00
Becouse This library offers easy interface to control your demons likewise the magic of Harry Potter controls dementors
2020-04-17 12:02:33 +03:00
2020-04-17 11:29:38 +03:00
## Main features
2020-06-20 11:09:12 +03:00
* Support linux systemd daemons.
2021-05-01 14:43:37 +03:00
* Deploy and install your services on the host.
2020-04-17 11:29:38 +03:00
* Auto create a Service from your server or yor daemon utility.
* Auto create a Controller of your Service.
2020-04-17 12:02:33 +03:00
2021-05-01 14:49:50 +03:00
## Deffault sopprted commands
* install - deploys your daemon into your host system.
* unistall - removes old deployed daemon.
* start - starts your service
* stop - stops ypur service
* pause - sends pause command to your daemon
* upause (resume) - sends resume coomand to your daemon
2020-04-19 00:22:55 +03:00
## Include
### For cmake projects
* cd yourRepo
* git submodule add https://github.com/QuasarApp/Patronum.git # add the repository of Patronum into your repo like submodule
* git submodule update --init --recursive
* Include in your CMakeLists.txt file the main CMakeLists.txt file of Patronum library
2021-04-28 23:55:54 +03:00
```cmake
2020-06-02 19:32:13 +03:00
add_subdirectory(Patronum)
2020-04-19 00:22:55 +03:00
```
* Rebuild yuor project
2020-09-15 18:20:51 +03:00
## Usage
2020-04-19 00:22:55 +03:00
2021-04-28 23:55:54 +03:00
### Service
```cpp
2020-04-19 00:22:55 +03:00
#include <patronum.h>
class MyserviceApp : public Patronum::Service<QCoreApplication>
{
public:
MyserviceApp(int argc, char **argv):
2021-04-28 23:55:54 +03:00
Patronum::Service<QCoreApplication>(argc, argv) {
2020-04-19 00:22:55 +03:00
}
void start() {
// call on server started
}
void stop() {
// call on server stoped
}
2021-04-28 23:55:54 +03:00
bool HanoiService::handleReceive(const Patronum::Feature &data) {
if (data.cmd() == "ping") {
sendResuylt("Pong");
} else if (data.cmd() == "state") {
sendResuylt("application status");
}
return true;
}
2020-04-19 00:22:55 +03:00
QList<Feature> supportedFeatures() {
2021-04-28 23:55:54 +03:00
QSet<Patronum::Feature> data;
data << Patronum::Feature("ping", "This is description of the ping command");
data << Patronum::Feature("state", "return state");
2020-04-19 00:22:55 +03:00
2021-04-28 23:55:54 +03:00
return data;
2020-04-19 00:22:55 +03:00
}
};
int main(int argc, char **argv) {
2021-04-28 23:55:54 +03:00
QCoreApplication::setApplicationName("MyServiceName"); // <--
QCoreApplication::setOrganizationName("MyCompany"); // <--
2020-04-19 00:22:55 +03:00
MyserviceApp app;
return app.exec();
}
```
2021-04-28 23:55:54 +03:00
2020-04-19 00:22:55 +03:00
### Controller
2021-04-28 23:55:54 +03:00
```cpp
2020-04-19 00:22:55 +03:00
#include <patronum.h>
class MyControllerApp : public Patronum::Controller
{
public:
MyControllerApp():
2021-04-28 23:55:54 +03:00
Patronum::Controller() {
2020-04-19 00:22:55 +03:00
}
};
int main(int argc, char **argv) {
2021-04-28 17:53:18 +03:00
QCoreApplication::setApplicationName("MyServiceName"); // <--
QCoreApplication::setOrganizationName("MyCompany"); // <--
2020-05-09 13:43:35 +03:00
QCoreApplcication app
MyControllerApp controller;
controller.send(argc, argv);
return app.exec();
2020-04-19 00:22:55 +03:00
}
```
2021-04-29 13:33:35 +03:00
### Wrapers of the service distributions
The Service class use own executable like a main path to service executable.
If your application has custom dependencies and do not work without costom envirement then you need to add **P_RUN_FILE** or **CQT_RUN_FILE** variavle with full path into the your wraper or launcher file.
#### Order of the search executable file of the service
1. **P_RUN_FILE** variable
2. **CQT_RUN_FILE** variable
3. Absalute path to executable.