Patronum/README.md

134 lines
3.6 KiB
Markdown
Raw Permalink Normal View History

2020-04-17 11:24:01 +03:00
# Patronum
2021-04-28 23:55:54 +03:00
2021-05-14 11:11:53 +03:00
<p align="center"><img src="res/Banner_web.jpg" alt="Credits"></p>
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
2021-10-13 16:08:24 +03:00
* install - deploys your daemon into your host system. This command deploy service for root user if you want to deploy service for specify user just use **-install <UserName>** command (root right required)
* unistall - removes old deployed daemon. (root right required)
2021-05-01 14:49:50 +03:00
* 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
}
2021-09-28 13:05:36 +03:00
void onStart() override {
2020-04-19 00:22:55 +03:00
// call on server started
}
2021-09-28 13:05:36 +03:00
void onStop() override {
2020-04-19 00:22:55 +03:00
// call on server stoped
}
2021-09-28 13:05:36 +03:00
bool handleReceive(const Patronum::Feature &data) override {
2021-04-28 23:55:54 +03:00
if (data.cmd() == "ping") {
sendResuylt("Pong");
} else if (data.cmd() == "state") {
sendResuylt("application status");
}
return true;
}
2020-04-19 00:22:55 +03:00
2021-09-28 13:05:36 +03:00
QSet<Patronum::Feature> supportedFeatures() override {
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.