简体   繁体   中英

How to run a Qt program as a service in Ubuntu?

I've written a C++ console application using Qt for an embedded board, I've put the binary file of the program in the startup of the Ubuntu. So whenever the system reboots, My applications starts to work. But sometimes the application crashes and I don't know why !!! I don't want my system to be idle in these situations. Since I want my program to restart after sudden crashing I thought of two possible solutions: 1. use a hardware watchdog timer, so whenever I reset the timer, the system goes on ... or 2. set my application as an Ubuntu service so in case of crashing it will restart it or it might reboot the system so my application starts again.

the first one is not presented in my board and I don't want to use an external watchdog timer so I wonder if I could do the latter !

PS a software watchdog timer is not reliable so plz don't propose to use a software WD timer !!! What do you think ? what Can I do ? Thanks

OK my suggestion is to use Monit you can install it by doing:

sudo apt-get install monit

with this tool you can monitor via Web, even send email if the process crashes. Of course in your case you can just sent a timeout to restart the application. The best would be to build a simple logging system of your application so it would be easier to trigger the timeout if it crashes.

But first you need to set your application in a upstart service. Take a look at you /etc/init.d/ directory because you can use some of this files as an example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM