-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
后端内置定时器,每5秒检查前端dman是否存在,若不存在,则后端dmanHelper退出 Log: 修复系统启动后dmanHelper成为常驻进程的问题
- Loading branch information
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "dmanwatcher.h" | ||
|
||
#include <QProcess> | ||
#include <QCoreApplication> | ||
#include <QDebug> | ||
|
||
DManWatcher::DManWatcher():m_Timer(new QTimer (this)) | ||
{ | ||
|
||
connect(m_Timer,&QTimer::timeout,this,&DManWatcher::onTimeOut); | ||
m_Timer->start(5000); | ||
} | ||
|
||
/** | ||
* @brief 定时监控客户端 | ||
*/ | ||
void DManWatcher::onTimeOut() | ||
{ | ||
QString cmd, outPut; | ||
//判断dman客户端是否存在,如果不存在退出服务。 | ||
cmd = QString("ps aux | grep -w dman$"); | ||
outPut= executCmd(cmd); | ||
int ret = outPut.length(); | ||
if (!ret) | ||
QCoreApplication::exit(0); | ||
} | ||
|
||
/** | ||
* @brief 执行外部命令 | ||
* @param strCmd:外部命令字符串 | ||
*/ | ||
QString DManWatcher::executCmd(const QString &strCmd) | ||
{ | ||
QProcess proc; | ||
proc.start("bash", QStringList() << "-c" << strCmd); | ||
proc.waitForFinished(-1); | ||
return proc.readAllStandardOutput(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef DMANWATCHER_H | ||
#define DMANWATCHER_H | ||
|
||
#include <QObject> | ||
#include <QTimer> | ||
|
||
/** | ||
* @class DManWatcher | ||
* @brief 监控客户端类 | ||
*/ | ||
class DManWatcher :public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit DManWatcher(); | ||
|
||
public Q_SLOTS: | ||
void onTimeOut(); | ||
private: | ||
QString executCmd(const QString &strCmd); | ||
private: | ||
QTimer *m_Timer=nullptr; | ||
}; | ||
|
||
#endif // DMANWATCHER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters