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"
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);
0 commit comments