简体   繁体   English

如何在Ubuntu中将Qt程序作为服务运行?

[英]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. 我已经使用Qt为嵌入式板编写了C ++控制台应用程序,并将程序的二进制文件放入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. 由于我希望程序在突然崩溃后重新启动,因此我想到了两种可能的解决方案:1.使用硬件看门狗计时器,因此每当重置计时器时,系统便会继续运行...或2.将应用程序设置为Ubuntu服务,以便如果崩溃,它将重新启动它,或者它可能重新启动系统,所以我的应用程序再次启动。

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 !!! PS软件看门狗定时器不可靠,因此请不要使用软件WD定时器!!! What do you think ? 你怎么看 ? what Can I do ? 我能做什么 ? Thanks 谢谢

OK my suggestion is to use Monit you can install it by doing: 好的,我的建议是使用Monit,您可以通过以下方式安装它:

sudo apt-get install monit

with this tool you can monitor via Web, even send email if the process crashes. 使用此工具,您可以通过Web进行监视,甚至在进程崩溃时发送电子邮件。 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. 看一下您的/etc/init.d/目录,因为您可以使用其中一些文件作为示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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