Qt Application like daemon. How?
-
Hello!
Is there any example of how to develop daemon application with Qt 6? Can't find anything. Is it the same like with Qt 5.
Need to develop application that will be working on Windows, Linux and MacOS like daemon. Is there in-box solution for it in Qt? The functionality for this application looks like:
- passing some commands from console while it's working and handling them in application
- running it like daemon on all desktop (Windows, Linux and MacOS) or server
-
I don't think there's an abstraction for cross-platform 'daemons' or services. Anyhow, I understand the difference between a normal (console) program and a daemon is mostly in the setup / installation; so I don't see any issues with using Qt in such executables.
-
Hello!
Is there any example of how to develop daemon application with Qt 6? Can't find anything. Is it the same like with Qt 5.
Need to develop application that will be working on Windows, Linux and MacOS like daemon. Is there in-box solution for it in Qt? The functionality for this application looks like:
- passing some commands from console while it's working and handling them in application
- running it like daemon on all desktop (Windows, Linux and MacOS) or server
@bogong said in Qt Application like daemon. How?:
passing some commands from console while it's working and handling them in application
Daemons as executables can get command line arguments upon start. Anyhow, if you want to establish some communication to a running daemon, you can't IMO work with terminal I/O, as daemons typically do not have a terminal.
Instead, you typically would use local sockets (e.g. QLocalSocket).
-
@bogong said in Qt Application like daemon. How?:
passing some commands from console while it's working and handling them in application
Daemons as executables can get command line arguments upon start. Anyhow, if you want to establish some communication to a running daemon, you can't IMO work with terminal I/O, as daemons typically do not have a terminal.
Instead, you typically would use local sockets (e.g. QLocalSocket).
@kkoehne What is the best practice if there need to develop kind of server application that will be working on any platform? Maybe there are mistakenly used term "daemon". There were for me 99 percents of mobile application with Qt. For now need to create application that will be working like server. Will be in memory keeping running listener of the port. Is there any examples?
For example:
- command to start application
./application start
- command to stop application
./application stop
- command to change state of application
./application state 1
- command to handle anything
./application do_anything
While application running need to have an ability to pass arguments and if application already running to handle arguments.
-
@kkoehne What is the best practice if there need to develop kind of server application that will be working on any platform? Maybe there are mistakenly used term "daemon". There were for me 99 percents of mobile application with Qt. For now need to create application that will be working like server. Will be in memory keeping running listener of the port. Is there any examples?
For example:
- command to start application
./application start
- command to stop application
./application stop
- command to change state of application
./application state 1
- command to handle anything
./application do_anything
While application running need to have an ability to pass arguments and if application already running to handle arguments.
@bogong said in Qt Application like daemon. How?:
What is the best practice if there need to develop kind of server application that will be working on any platform?
I don't think there is anything much for a server/daemon across different platforms, as they all work differently. For example, although I don't develop for mobile/Android, I believe you have to do something Android-specific to make an application run as a daemon in the background.
As @kkoehne said, you usually cannot do anything like re-run an application with a new command line argument as that would invoke a new instance of the application. You usually communicate with a running program via a socket message or something similar.
-
@kkoehne What is the best practice if there need to develop kind of server application that will be working on any platform? Maybe there are mistakenly used term "daemon". There were for me 99 percents of mobile application with Qt. For now need to create application that will be working like server. Will be in memory keeping running listener of the port. Is there any examples?
For example:
- command to start application
./application start
- command to stop application
./application stop
- command to change state of application
./application state 1
- command to handle anything
./application do_anything
While application running need to have an ability to pass arguments and if application already running to handle arguments.
@bogong , you want to split things up in two executables: One 'control' application (in your case called
application
that is the interface to the user, and the actual server (let's call itserver
). Both can be command line applications; that is , they don't typically link against Qt GUI, and useQCoreApplication
in their main.cpp.I'm not aware of any example that does exactly what you want (though it might be a nice addition in the future). But there's examples how client and serve communicate, take e.g. https://doc.qt.io/qt-6/qtdbus-pingpong-example.html .
@bogong said in Qt Application like daemon. How?:
For example:
command to start application
[...]Well, such custom commands for managing a service's state is not the 'usual' paradigm for services. On Windows, people are used to start and stop services from the GUI, or via
sc
. On Linux, you'd typically rather use something likesystemctrl
to start and stop services.Think about the following scenarios:
- Should the server continue to run when the console / terminal you launched
application
from is closed? - Can there be multiple servers running at the same time?
- Should the server be started again after the OS reboots?
If you check all these boxes, you most certainly implement a 'real' server (so a Windows Service, for instance). If you check only the first or maybe the second option, you might get away with a normal executable that 'just' is detaches from the parent process.
-
@bogong , you want to split things up in two executables: One 'control' application (in your case called
application
that is the interface to the user, and the actual server (let's call itserver
). Both can be command line applications; that is , they don't typically link against Qt GUI, and useQCoreApplication
in their main.cpp.I'm not aware of any example that does exactly what you want (though it might be a nice addition in the future). But there's examples how client and serve communicate, take e.g. https://doc.qt.io/qt-6/qtdbus-pingpong-example.html .
@bogong said in Qt Application like daemon. How?:
For example:
command to start application
[...]Well, such custom commands for managing a service's state is not the 'usual' paradigm for services. On Windows, people are used to start and stop services from the GUI, or via
sc
. On Linux, you'd typically rather use something likesystemctrl
to start and stop services.Think about the following scenarios:
- Should the server continue to run when the console / terminal you launched
application
from is closed? - Can there be multiple servers running at the same time?
- Should the server be started again after the OS reboots?
If you check all these boxes, you most certainly implement a 'real' server (so a Windows Service, for instance). If you check only the first or maybe the second option, you might get away with a normal executable that 'just' is detaches from the parent process.
@kkoehne said in Qt Application like daemon. How?:
On Windows, people are used to start and stop services [from the GUI,] or via
sc
.And just so @bogong knows, this works only because Windows services/
sc
sends a message to your already-running daemon for further commands like "stop" or "pause". And you have to write your application as a service to support this. And of course it's quite Windows-specific. - Should the server continue to run when the console / terminal you launched
-
@bogong , you want to split things up in two executables: One 'control' application (in your case called
application
that is the interface to the user, and the actual server (let's call itserver
). Both can be command line applications; that is , they don't typically link against Qt GUI, and useQCoreApplication
in their main.cpp.I'm not aware of any example that does exactly what you want (though it might be a nice addition in the future). But there's examples how client and serve communicate, take e.g. https://doc.qt.io/qt-6/qtdbus-pingpong-example.html .
@bogong said in Qt Application like daemon. How?:
For example:
command to start application
[...]Well, such custom commands for managing a service's state is not the 'usual' paradigm for services. On Windows, people are used to start and stop services from the GUI, or via
sc
. On Linux, you'd typically rather use something likesystemctrl
to start and stop services.Think about the following scenarios:
- Should the server continue to run when the console / terminal you launched
application
from is closed? - Can there be multiple servers running at the same time?
- Should the server be started again after the OS reboots?
If you check all these boxes, you most certainly implement a 'real' server (so a Windows Service, for instance). If you check only the first or maybe the second option, you might get away with a normal executable that 'just' is detaches from the parent process.
@kkoehne said in Qt Application like daemon. How?:
Should the server continue to run when the console / terminal you launched applicationfrom is closed?
Yes it should be running after terminal closed
@kkoehne said in Qt Application like daemon. How?:
Can there be multiple servers running at the same time?
From begin there are no this kind of requirements. Just one instance of application on one physical or virtual server
@kkoehne said in Qt Application like daemon. How?:
Should the server be started again after the OS reboots?
Yes it should be starting after server reboot within the last state of the server.
- Should the server continue to run when the console / terminal you launched
-
@bogong , you want to split things up in two executables: One 'control' application (in your case called
application
that is the interface to the user, and the actual server (let's call itserver
). Both can be command line applications; that is , they don't typically link against Qt GUI, and useQCoreApplication
in their main.cpp.I'm not aware of any example that does exactly what you want (though it might be a nice addition in the future). But there's examples how client and serve communicate, take e.g. https://doc.qt.io/qt-6/qtdbus-pingpong-example.html .
@bogong said in Qt Application like daemon. How?:
For example:
command to start application
[...]Well, such custom commands for managing a service's state is not the 'usual' paradigm for services. On Windows, people are used to start and stop services from the GUI, or via
sc
. On Linux, you'd typically rather use something likesystemctrl
to start and stop services.Think about the following scenarios:
- Should the server continue to run when the console / terminal you launched
application
from is closed? - Can there be multiple servers running at the same time?
- Should the server be started again after the OS reboots?
If you check all these boxes, you most certainly implement a 'real' server (so a Windows Service, for instance). If you check only the first or maybe the second option, you might get away with a normal executable that 'just' is detaches from the parent process.
@kkoehne said in Qt Application like daemon. How?:
I'm not aware of any example that does exactly what you want (though it might be a nice addition in the future). But there's examples how client and serve communicate, take e.g. https://doc.qt.io/qt-6/qtdbus-pingpong-example.html .
This is what been seeking. Technically it looks like 2 different applications communicating between each other. And one in role of User Interface and the second in role of Server. Is there any way to prohibit running application within Server role from direct running? Is there way to run server only from User Interface application?
- Should the server continue to run when the console / terminal you launched
-
@kkoehne said in Qt Application like daemon. How?:
Should the server continue to run when the console / terminal you launched applicationfrom is closed?
Yes it should be running after terminal closed
@kkoehne said in Qt Application like daemon. How?:
Can there be multiple servers running at the same time?
From begin there are no this kind of requirements. Just one instance of application on one physical or virtual server
@kkoehne said in Qt Application like daemon. How?:
Should the server be started again after the OS reboots?
Yes it should be starting after server reboot within the last state of the server.
@bogong
As far as I know you will need to take different platform-specific actions for this for each of your target OSes.Yes it should be starting after server reboot within the last state of the server.
For sure that requires at least special installation for each OS. And as for "restoring whatever the last state" means to you, you will have to code for this, e.g. by saving state to a file.
-
@bogong
As far as I know you will need to take different platform-specific actions for this for each of your target OSes.Yes it should be starting after server reboot within the last state of the server.
For sure that requires at least special installation for each OS. And as for "restoring whatever the last state" means to you, you will have to code for this, e.g. by saving state to a file.
@JonB said in Qt Application like daemon. How?:
And as for "restoring whatever the last state" means to you, you will have to code for this, e.g. by saving state to a file.
Thx for reply. How to save the states - well known for me. But don't know how to run Qt application properly in background.
-
@JonB said in Qt Application like daemon. How?:
And as for "restoring whatever the last state" means to you, you will have to code for this, e.g. by saving state to a file.
Thx for reply. How to save the states - well known for me. But don't know how to run Qt application properly in background.
Btw, just found https://code.qt.io/cgit/qt-solutions/qt-solutions.git/tree/qtservice :) Looks like it at least compiles with Qt 5.15, so it might be a good template.
-
Btw, just found https://code.qt.io/cgit/qt-solutions/qt-solutions.git/tree/qtservice :) Looks like it at least compiles with Qt 5.15, so it might be a good template.
@kkoehne said in Qt Application like daemon. How?:
Btw, just found https://code.qt.io/cgit/qt-solutions/qt-solutions.git/tree/qtservice :) Looks like it at least compiles with Qt 5.15, so it might be a good template.
Wow! It looks like of what been seeking. Will test it out with Qt 6 and unite with D-Bus example if needed. Will reply here with results of experiments.
-
@kkoehne said in Qt Application like daemon. How?:
Btw, just found https://code.qt.io/cgit/qt-solutions/qt-solutions.git/tree/qtservice :) Looks like it at least compiles with Qt 5.15, so it might be a good template.
Wow! It looks like of what been seeking. Will test it out with Qt 6 and unite with D-Bus example if needed. Will reply here with results of experiments.
-
@kkoehne said in Qt Application like daemon. How?:
Btw, just found https://code.qt.io/cgit/qt-solutions/qt-solutions.git/tree/qtservice :) Looks like it at least compiles with Qt 5.15, so it might be a good template.
Wow! It looks like of what been seeking. Will test it out with Qt 6 and unite with D-Bus example if needed. Will reply here with results of experiments.
-
J JonB referenced this topic on