Run console application in background (as service/daemon)
-
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!
-
Check the documentation of QProcess.
-
[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. -
You can run any application in the background on linux using "./myapp parameters &". You do not need to do anything special.
-
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