Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit f576d41

Browse files
authored
fix: spawn process linux (#1210)
* fix: spawn process linux * fix: log
1 parent 6f0aa4e commit f576d41

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

.github/workflows/cortex-cpp-quality-gate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
uses: actions/checkout@v3
5252
with:
5353
submodules: recursive
54-
54+
5555
- name: Install choco on Windows
5656
if: runner.os == 'Windows'
5757
run: |

engine/main.cc

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <drogon/HttpAppFramework.h>
22
#include <drogon/drogon.h>
33
#include <climits> // for PATH_MAX
4+
#include "commands/cortex_upd_cmd.h"
45
#include "controllers/command_line_parser.h"
56
#include "cortex-common/cortexpythoni.h"
67
#include "utils/archive_utils.h"
@@ -9,7 +10,6 @@
910
#include "utils/file_logger.h"
1011
#include "utils/file_manager_utils.h"
1112
#include "utils/logging_utils.h"
12-
#include "commands/cortex_upd_cmd.h"
1313

1414
#if defined(__APPLE__) && defined(__MACH__)
1515
#include <libgen.h> // for dirname()
@@ -32,8 +32,9 @@ void RunServer() {
3232
<< " Port: " << config.apiServerPort << "\n";
3333

3434
// Create logs/ folder and setup log to file
35-
std::filesystem::create_directories(std::filesystem::path(config.logFolderPath) /
36-
std::filesystem::path(cortex_utils::logs_folder));
35+
std::filesystem::create_directories(
36+
std::filesystem::path(config.logFolderPath) /
37+
std::filesystem::path(cortex_utils::logs_folder));
3738
trantor::FileLogger asyncFileLogger;
3839
asyncFileLogger.setFileName(config.logFolderPath + "/" +
3940
cortex_utils::logs_base_name);
@@ -123,8 +124,25 @@ void ForkProcess() {
123124
std::cerr << "Could not start server: " << std::endl;
124125
return;
125126
} else if (pid == 0) {
126-
// Child process
127-
RunServer();
127+
// No need to configure LD_LIBRARY_PATH for macOS
128+
#if !defined(__APPLE__) || !defined(__MACH__)
129+
const char* name = "LD_LIBRARY_PATH";
130+
auto data = getenv(name);
131+
std::string v;
132+
if (auto g = getenv(name); g) {
133+
v += g;
134+
}
135+
CTL_INF("LD_LIBRARY_PATH: " << v);
136+
auto data_path = file_manager_utils::GetCortexDataPath();
137+
auto llamacpp_path = data_path / "engines" / "cortex.llamacpp/";
138+
auto trt_path = data_path / "engines" / "cortex.tensorrt-llm/";
139+
auto new_v = trt_path.string() + ":" + llamacpp_path.string() + ":" + v;
140+
setenv(name, new_v.c_str(), true);
141+
CTL_INF("LD_LIBRARY_PATH: " << getenv(name));
142+
#endif
143+
auto exe = commands::GetCortexBinary();
144+
std::string p = cortex_utils::GetCurrentPath() + "/" + exe;
145+
execl(p.c_str(), exe.c_str(), "--start-server", (char*)0);
128146
} else {
129147
// Parent process
130148
std::cout << "Server started" << std::endl;
@@ -173,8 +191,9 @@ int main(int argc, char* argv[]) {
173191
return 0;
174192
} else {
175193
auto config = file_manager_utils::GetCortexConfig();
176-
std::filesystem::create_directories(std::filesystem::path(config.logFolderPath) /
177-
std::filesystem::path(cortex_utils::logs_folder));
194+
std::filesystem::create_directories(
195+
std::filesystem::path(config.logFolderPath) /
196+
std::filesystem::path(cortex_utils::logs_folder));
178197
trantor::FileLogger asyncFileLogger;
179198
asyncFileLogger.setFileName(config.logFolderPath + "/" +
180199
cortex_utils::logs_cli_base_name);

engine/utils/file_manager_utils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ inline std::filesystem::path GetExecutableFolderContainerPath() {
2727
uint32_t size = sizeof(buffer);
2828

2929
if (_NSGetExecutablePath(buffer, &size) == 0) {
30-
LOG_INFO << "Executable path: " << buffer;
30+
CTL_INF("Executable path: " << buffer);
3131
return std::filesystem::path{buffer}.parent_path();
3232
} else {
33-
LOG_ERROR << "Failed to get executable path";
33+
CTL_ERR("Failed to get executable path");
3434
return std::filesystem::current_path();
3535
}
3636
#elif defined(__linux__)
3737
char buffer[1024];
3838
ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
3939
if (len != -1) {
4040
buffer[len] = '\0';
41-
LOG_INFO << "Executable path: " << buffer;
41+
CTL_INF("Executable path: " << buffer);
4242
return std::filesystem::path{buffer}.parent_path();
4343
} else {
44-
LOG_ERROR << "Failed to get executable path";
44+
CTL_ERR("Failed to get executable path");
4545
return std::filesystem::current_path();
4646
}
4747
#elif defined(_WIN32)

0 commit comments

Comments
 (0)