Skip to content

Commit

Permalink
feat: Run anything service in independent process
Browse files Browse the repository at this point in the history
Using an independent process to run anything service can solve known
log conflict problems. When the service runs abnormally, the service
can be restored by creating a new process.

Log: handle high CPU usage
Task: https://pms.uniontech.com/task-view-300371.html
  • Loading branch information
wangrong1069 authored and deepin-bot[bot] committed Oct 31, 2023
1 parent 82a2295 commit 2d73ea6
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
deepin-anything (6.1.5) unstable; urgency=medium

* add executable for running anything.
* let process abort when cpu usage limit is exceeded.

-- Deepin Package Builder <[email protected]> Thu, 26 Oct 2023 14:35:37 +0800

deepin-anything (6.1.4) unstable; urgency=medium

* fix index issue.
Expand Down
1 change: 1 addition & 0 deletions debian/deepin-anything-server.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
usr/bin/deepin-anything-server
usr/lib/*/libdeepin-anything-server-lib.*
usr/share/dbus-1/interfaces
etc/dbus-1/system.d
1 change: 1 addition & 0 deletions src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ if(NOT CMAKE_BUILD_TYPE)
endif(NOT CMAKE_BUILD_TYPE)

add_subdirectory("backend")
add_subdirectory("app")
33 changes: 33 additions & 0 deletions src/server/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.10)

project(deepin-anything-server)

# Version
if (NOT PROJECT_VERSION)
set(PROJECT_VERSION "1.0.0")
endif()

if (NOT PROJECT_VERSION_MAJOR)
set(PROJECT_VERSION_MAJOR 0)
endif()

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../backend
)

set(SRCS
main.cpp
)

find_package(PkgConfig REQUIRED)
find_package(Qt5 COMPONENTS Core REQUIRED)

add_executable(${PROJECT_NAME} ${SRCS})

target_link_libraries(${PROJECT_NAME} PUBLIC
Qt5::Core
deepin-anything-server-lib
)

# binary
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
34 changes: 34 additions & 0 deletions src/server/app/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include <QCoreApplication>
#include <QDebug>
#include "anythingexport.h"
#include <signal.h>

static void handleSIGTERM(int sig)
{
qDebug() << "received SIGTERM" << sig;
if (qApp) {
qApp->quit();
}
}

int main(int argc, char *argv[])
{
int ret;

QCoreApplication app(argc, argv);
app.setOrganizationName("deepin");

if (fireAnything()) {
qCritical() << "fireAnything failed!";
abort();
}
signal(SIGTERM, handleSIGTERM);

ret = app.exec();
downAnything();
return ret;
}
1 change: 1 addition & 0 deletions src/server/backend/anythingexport.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@

#define ANYTHINGBACKEND_SHARED_EXPORT Q_DECL_EXPORT
extern "C" ANYTHINGBACKEND_SHARED_EXPORT int fireAnything();
extern "C" ANYTHINGBACKEND_SHARED_EXPORT void downAnything();

#endif // ANYTHINGEXPORT_H
7 changes: 7 additions & 0 deletions src/server/backend/lib/lftmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern "C" {

#include <unistd.h>
#include <sys/time.h>
#include <sys/stat.h>

Q_LOGGING_CATEGORY(logN, "anything.normal.manager", DEFAULT_MSG_TYPE)
Q_LOGGING_CATEGORY(logC, "anything.changes.manager", DEFAULT_MSG_TYPE)
Expand Down Expand Up @@ -1091,6 +1092,12 @@ void LFTManager::_cpuLimitCheck()
QProcess::startDetached(cmd + "50%");
cpu_limited = true;
nWarning() << "Limited, long time high CPU usage: " << current_cpu;

struct stat statbuf;
if (stat("/tmp/anything_disable_abort", &statbuf)) {
nWarning() << "Abort for high CPU usage.";
abort();
}
} else if (current_cpu < low_use) {
QProcess::startDetached(cmd);
cpu_limited = false;
Expand Down

0 comments on commit 2d73ea6

Please sign in to comment.