A Library to create background applications with simple, automated foreground control.
In short, with this library you can easly create cross platform applications, that are ment to run in the background, without any UI. This however, is fairly easy and would not require a library. This one however adds a few things, that make it much more comfortable to use those.
Have a look at the features.
SIGINTThe QtBackgroundProcess is a library for console applications. It is not intended to be used with GUI-Apps or similar, and probably won't work with them. If you are looking for simply a "singleton instance", i.e. a library that will make shure only one instance of your application runs at a time, have a look at QSingleInstance.
There are multiple ways to install the Qt module, sorted by preference:
~/Qt/MaintenanceTool)Add or remove components and click on the Settings buttonRepositories, scroll to the bottom, select User defined repositories and press AddOk, make shure Add or remove components is still selected, and continue the install (Next >)Qt > Qt 5.8 > Skycoder42 Qt modules)Qt Background Processqmakemake qmake_allmakemake installqmake && make install once againHowever, if you want to create an application to run silently in the background, and only interact with it to "control" it, you're at the right place.
The background process is provided as a Qt module. Thus, all you have to do is add the module, and then, in your project, add QT += backgroundprocess to your .pro file!
All you need to do in your code is to use QtBackgroundProcess::App instead of QCoreApplication and put your code in the startup function or extend it.
The following example is a very simple background application, that logs all command arguments that have been passed by the terminals. In addition to that, it will send all debug output to all terminals.
The first few commands (i.e. Version number) are done for every instance, including the terminals. The part inside of setStartupFunction will be executed on the master only.
To find out what you can do with this application, simply call <path_to>/myApp --help - this will show the command line arguments that can be used. Use start to start the master process and stop to stop it. Please remember the the master process will continue to run, even after you have closed all terminals. Use the stop command to stop it. For a demo app, see examples/backgroundprocess/DemoApp.
Since all of the application logic is happening in the master process, debugging the terminals does not really help. However, with "normal" commands you can only start terminals, not the master, and thus not debug it. If you need to debug the master, it can be helpful to start the master process directly, instead of using a terminal. To do so, all you need to do is launch it with a special first argument:
If your normal command looks for example like this: ./myApp start some arguments
You can directly start the master process by using: `./myApp '__qbckgrndprcss$start::master~' some arguments`
The master process is not meant to be directly run. Thus, it will for example, not show a console window, disconnect stdin/stdout, etc. This makes it hard to get the debug without a terminal. You can try the following options, depending on what suits you needs:
-L "" --keep-console as additional parameters for the master to enable this.tail -f logfile. To get the location, run --help and see the -L parameter. You can use terminals normallyThe documentation is available on github pages. It was created using doxygen. The HTML-documentation and Qt-Help files are shipped together with the module for both the custom repository and the package on the release page. Please note that doxygen docs do not perfectly integrate with QtCreator/QtAssistant.
The project is prepared for translation. But since I speak only english and german, those are the only languages I can provide translations for. However, you can easily create the translations yourself. The file src/backgroundprocess/translations/qtbackgroundprocess_template.ts is a ready-made TS file. Just rename it (e.g. to qtbackgroundprocess_jp.ts) and open it with the QtLinguist to create the translations.
Please not, that this library does not create a real daemon/service. It merely creates a background process, with advanced terminal connections. This approach allows more flexibility and an easier cross-platform implementation. In addition to that, interaction with the process becomes possible everywhere, without any additional code.
1.8.13