Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Application like daemon. How?

Qt Application like daemon. How?

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 4 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • kkoehneK kkoehne

    @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).

    B Offline
    B Offline
    bogong
    wrote on last edited by bogong
    #4

    @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.

    JonBJ kkoehneK 2 Replies Last reply
    0
    • B bogong

      @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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #5

      @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.

      1 Reply Last reply
      2
      • B bogong

        @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.

        kkoehneK Offline
        kkoehneK Offline
        kkoehne
        Moderators
        wrote on last edited by kkoehne
        #6

        @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 it server). Both can be command line applications; that is , they don't typically link against Qt GUI, and use QCoreApplication 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 like systemctrl to start and stop services.

        Think about the following scenarios:

        • Should the server continue to run when the console / terminal you launched applicationfrom 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.

        Director R&D, The Qt Company

        JonBJ B 3 Replies Last reply
        0
        • kkoehneK kkoehne

          @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 it server). Both can be command line applications; that is , they don't typically link against Qt GUI, and use QCoreApplication 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 like systemctrl to start and stop services.

          Think about the following scenarios:

          • Should the server continue to run when the console / terminal you launched applicationfrom 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.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #7

          @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.

          1 Reply Last reply
          0
          • kkoehneK kkoehne

            @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 it server). Both can be command line applications; that is , they don't typically link against Qt GUI, and use QCoreApplication 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 like systemctrl to start and stop services.

            Think about the following scenarios:

            • Should the server continue to run when the console / terminal you launched applicationfrom 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.

            B Offline
            B Offline
            bogong
            wrote on last edited by
            #8

            @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.

            JonBJ 1 Reply Last reply
            0
            • kkoehneK kkoehne

              @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 it server). Both can be command line applications; that is , they don't typically link against Qt GUI, and use QCoreApplication 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 like systemctrl to start and stop services.

              Think about the following scenarios:

              • Should the server continue to run when the console / terminal you launched applicationfrom 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.

              B Offline
              B Offline
              bogong
              wrote on last edited by
              #9

              @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?

              1 Reply Last reply
              0
              • B bogong

                @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.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #10

                @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.

                B 1 Reply Last reply
                0
                • JonBJ JonB

                  @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.

                  B Offline
                  B Offline
                  bogong
                  wrote on last edited by
                  #11

                  @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.

                  kkoehneK 1 Reply Last reply
                  0
                  • B bogong

                    @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.

                    kkoehneK Offline
                    kkoehneK Offline
                    kkoehne
                    Moderators
                    wrote on last edited by
                    #12

                    @bogong

                    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.

                    Director R&D, The Qt Company

                    B 1 Reply Last reply
                    2
                    • kkoehneK kkoehne

                      @bogong

                      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.

                      B Offline
                      B Offline
                      bogong
                      wrote on last edited by bogong
                      #13

                      @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.

                      JonBJ JoeCFDJ 2 Replies Last reply
                      0
                      • B bogong

                        @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.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #14

                        @bogong
                        For the record, it looks like that was for Qt4 and not updated since then? Not that it's not useful, just that it may need some updating.

                        1 Reply Last reply
                        0
                        • B bogong

                          @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.

                          JoeCFDJ Offline
                          JoeCFDJ Offline
                          JoeCFD
                          wrote on last edited by
                          #15

                          @bogong I guess service is what you need on Linux/MacOS. Qt may not be needed here at all.

                          1 Reply Last reply
                          0
                          • JonBJ JonB referenced this topic on

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved