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. Run console application in background (as service/daemon)
Forum Updated to NodeBB v4.3 + New Features

Run console application in background (as service/daemon)

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 9.6k Views 1 Watching
  • 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.
  • X Offline
    X Offline
    xiit
    wrote on last edited by
    #1

    Hi!

    Say I would like to run a console application (for example a server) in the background on my linux machine, that can be started/stopped/restarted with ./MyApp <start|stop|restart>.

    How would I approach this? I believe it would have to run like some kind of service?

    Thankful for any ideas!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      Check the documentation of QProcess.

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xiit
        wrote on last edited by
        #3

        I think I wasn't clear enough, my bad. I want to run my application in the background, not start an external process. :)

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          You mean, something like daemons? In this case you can use Qt Solutions.
          If you don't need daemon and then you can create simple GUI app and then hide it or move to tray.

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xiit
            wrote on last edited by
            #5

            [quote author="qxoz" date="1363236879"]You mean, something like daemons? In this case you can use Qt Solutions.
            If you don't need daemon and then you can create simple GUI app and then hide it or move to tray. [/quote]

            Yeah, something like that, a service/daemon. It's supposed to run on a machine without a window manager.

            Is this what you mean? http://qt.gitorious.org/qt-solutions
            It seems to be for Qt4 and I'm using 5.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tobias.hunger
              wrote on last edited by
              #6

              You can run any application in the background on linux using "./myapp parameters &". You do not need to do anything special.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                bepehr
                wrote on last edited by
                #7

                which linux is it ?
                you can run applications on background with this command instead of usual runs
                @nohup programName@

                but to run it like service i did this with centos in this way , you can check what you can do on others ..
                first off all you need to create a file in this path /etc/init.d/
                for example startupScript.sh
                and write this codes on it
                @start() {

                    echo -n "My program is starting ";
                    nohup /root/path_To_Your_Applioction/myProgram &
                    
                    echo "done"
                

                }

                stop() {
                echo -n "Stopping my program "
                killall -9 myProgram
                }

                See how we were called.

                case "$1" in
                start)
                start
                ;;
                stop)
                stop
                ;;
                restart)
                stop
                start
                ;;
                *)
                echo $"Usage: {start|stop|restart}"
                exit
                esac@

                after this you have to change your startupScript.sh permesion with this code
                @chmod 0775 startupScript.sh@
                now when you type run this command your application must start or stop
                @/etc/init.d/startupScript.sh start@

                now you need just put startupScript.sh on startup
                with this code
                @chkconfig --level 345 startupScript.sh on@

                check this "link":http://support.suso.com/supki/CentOS_Init_startup_scripts for startup levels

                now you just need to rebot your machine and check is its runes or not

                1 Reply Last reply
                0

                • Login

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