From c4addf2afe5c9238374ead191f13d42a2372335b Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 1 Nov 2024 18:29:47 +0700 Subject: [PATCH 1/6] fix: server uploads to temporary directory --- engine/main.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/engine/main.cc b/engine/main.cc index 1e97384c8..986194219 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -103,12 +103,15 @@ void RunServer(std::optional port) { auto pm_ctl = std::make_shared(); auto server_ctl = std::make_shared(inference_svc); - drogon::app().registerController(engine_ctl); + drogon::app().registerController(engine_ctl); drogon::app().registerController(model_ctl); drogon::app().registerController(event_ctl); drogon::app().registerController(pm_ctl); drogon::app().registerController(server_ctl); + auto upload_path = std::filesystem::temp_directory_path() / "cortex-uploads"; + drogon::app().setUploadPath(upload_path.string()); + LOG_INFO << "Server started, listening at: " << config.apiServerHost << ":" << config.apiServerPort; LOG_INFO << "Please load your model"; From e5524c61549b76010b9a79d8375bfbf5582d0540 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 1 Nov 2024 18:31:49 +0700 Subject: [PATCH 2/6] fix: format --- engine/main.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/main.cc b/engine/main.cc index 986194219..afe843817 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -103,7 +103,7 @@ void RunServer(std::optional port) { auto pm_ctl = std::make_shared(); auto server_ctl = std::make_shared(inference_svc); - drogon::app().registerController(engine_ctl); + drogon::app().registerController(engine_ctl); drogon::app().registerController(model_ctl); drogon::app().registerController(event_ctl); drogon::app().registerController(pm_ctl); From 47ab81dd3ef5174a930cefe13aba947b105d94d4 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 1 Nov 2024 22:17:41 +0700 Subject: [PATCH 3/6] fix: start/stop server --- engine/templates/macos/postinstall_local | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/engine/templates/macos/postinstall_local b/engine/templates/macos/postinstall_local index 7a6af4090..c3cb31565 100644 --- a/engine/templates/macos/postinstall_local +++ b/engine/templates/macos/postinstall_local @@ -11,9 +11,15 @@ fi USER_TO_RUN_AS=$(stat -f "%Su" /dev/console) +echo "Start server before downloading server for user $USER_TO_RUN_AS" +sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME start + echo "Download cortex.llamacpp engines by default for user $USER_TO_RUN_AS" sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME engines install llama-cpp -s ./dependencies +echo "Stop server" +sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME stop + sudo chown -R $USER_TO_RUN_AS:staff "/Users/$USER_TO_RUN_AS/$DATA_FOLDER_NAME" sudo chown $USER_TO_RUN_AS:staff "/Users/$USER_TO_RUN_AS/$CONFIGURATION_FILE_NAME" From c3984607d43bcac00e602a93dfc9ace23a1d0b2f Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 1 Nov 2024 22:53:35 +0700 Subject: [PATCH 4/6] fix: postinstall --- engine/templates/macos/postinstall | 6 ++++++ engine/templates/macos/postinstall_local | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/engine/templates/macos/postinstall b/engine/templates/macos/postinstall index 6d06c673d..38310a452 100644 --- a/engine/templates/macos/postinstall +++ b/engine/templates/macos/postinstall @@ -11,9 +11,15 @@ fi USER_TO_RUN_AS=$(stat -f "%Su" /dev/console) +echo "Start server before downloading server for user $USER_TO_RUN_AS" +sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME start + echo "Download cortex.llamacpp engines by default for user $USER_TO_RUN_AS" sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME engines install llama-cpp +echo "Stop server" +sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME stop + sudo chown -R $USER_TO_RUN_AS:staff "/Users/$USER_TO_RUN_AS/$DATA_FOLDER_NAME" sudo chown $USER_TO_RUN_AS:staff "/Users/$USER_TO_RUN_AS/$CONFIGURATION_FILE_NAME" diff --git a/engine/templates/macos/postinstall_local b/engine/templates/macos/postinstall_local index c3cb31565..7a6af4090 100644 --- a/engine/templates/macos/postinstall_local +++ b/engine/templates/macos/postinstall_local @@ -11,15 +11,9 @@ fi USER_TO_RUN_AS=$(stat -f "%Su" /dev/console) -echo "Start server before downloading server for user $USER_TO_RUN_AS" -sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME start - echo "Download cortex.llamacpp engines by default for user $USER_TO_RUN_AS" sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME engines install llama-cpp -s ./dependencies -echo "Stop server" -sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME stop - sudo chown -R $USER_TO_RUN_AS:staff "/Users/$USER_TO_RUN_AS/$DATA_FOLDER_NAME" sudo chown $USER_TO_RUN_AS:staff "/Users/$USER_TO_RUN_AS/$CONFIGURATION_FILE_NAME" From 42a573abb0596e29b38cccafcc4b590c73c27707 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 1 Nov 2024 23:14:04 +0700 Subject: [PATCH 5/6] fix: stop server linux windows --- engine/templates/linux/postinst | 1 + engine/templates/windows/installer-beta.iss | 4 ++++ engine/templates/windows/installer-nightly.iss | 4 ++++ engine/templates/windows/installer.iss | 4 ++++ 4 files changed, 13 insertions(+) diff --git a/engine/templates/linux/postinst b/engine/templates/linux/postinst index 401b9f4b8..583639b5e 100644 --- a/engine/templates/linux/postinst +++ b/engine/templates/linux/postinst @@ -9,3 +9,4 @@ fi USER_TO_RUN_AS=${SUDO_USER:-$(whoami)} echo "Download cortex.llamacpp engines by default for user $USER_TO_RUN_AS" sudo -u $USER_TO_RUN_AS env PATH=$PATH:/usr/lib/wsl/lib /usr/bin/$DESTINATION_BINARY_NAME engines install llama-cpp +sudo -u $USER_TO_RUN_AS env PATH=$PATH:/usr/lib/wsl/lib /usr/bin/$DESTINATION_BINARY_NAME stop diff --git a/engine/templates/windows/installer-beta.iss b/engine/templates/windows/installer-beta.iss index 7bb937d11..0b48a92f6 100644 --- a/engine/templates/windows/installer-beta.iss +++ b/engine/templates/windows/installer-beta.iss @@ -84,6 +84,10 @@ begin CortexInstallCmd := Format('"%s\cortex-beta.exe" engines install llama-cpp', [ExpandedAppDir]); Exec('cmd.exe', '/C ' + CortexInstallCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); + // Stop server + CortexStopServerCmd := Format('"%s\cortex-nightly.exe" stop', [ExpandedAppDir]); + Exec('cmd.exe', '/C ' + CortexStopServerCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); + // Set the progress bar to 90% after downloading the engine WizardForm.ProgressGauge.Position := 90; WizardForm.ProgressGauge.Update; diff --git a/engine/templates/windows/installer-nightly.iss b/engine/templates/windows/installer-nightly.iss index 21a681234..7924240da 100644 --- a/engine/templates/windows/installer-nightly.iss +++ b/engine/templates/windows/installer-nightly.iss @@ -84,6 +84,10 @@ begin CortexInstallCmd := Format('"%s\cortex-nightly.exe" engines install llama-cpp', [ExpandedAppDir]); Exec('cmd.exe', '/C ' + CortexInstallCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); + // Stop server + CortexStopServerCmd := Format('"%s\cortex-nightly.exe" stop', [ExpandedAppDir]); + Exec('cmd.exe', '/C ' + CortexStopServerCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); + // Set the progress bar to 90% after downloading the engine WizardForm.ProgressGauge.Position := 90; WizardForm.ProgressGauge.Update; diff --git a/engine/templates/windows/installer.iss b/engine/templates/windows/installer.iss index 5bbd83ec7..9eb4aa3fe 100644 --- a/engine/templates/windows/installer.iss +++ b/engine/templates/windows/installer.iss @@ -84,6 +84,10 @@ begin CortexInstallCmd := Format('"%s\cortex.exe" engines install llama-cpp', [ExpandedAppDir]); Exec('cmd.exe', '/C ' + CortexInstallCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); + // Stop server + CortexStopServerCmd := Format('"%s\cortex-nightly.exe" stop', [ExpandedAppDir]); + Exec('cmd.exe', '/C ' + CortexStopServerCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); + // Set the progress bar to 90% after downloading the engine WizardForm.ProgressGauge.Position := 90; WizardForm.ProgressGauge.Update; From 53f760d753aef01d36eab612f8466198d5fe715a Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Sat, 2 Nov 2024 05:26:10 +0700 Subject: [PATCH 6/6] fix: build windows --- engine/templates/windows/installer-beta.iss | 2 +- engine/templates/windows/installer-nightly.iss | 2 +- engine/templates/windows/installer.iss | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/templates/windows/installer-beta.iss b/engine/templates/windows/installer-beta.iss index 0b48a92f6..b8524afd0 100644 --- a/engine/templates/windows/installer-beta.iss +++ b/engine/templates/windows/installer-beta.iss @@ -36,7 +36,7 @@ Filename: "{app}\cortex-beta.exe"; Parameters: "stop"; StatusMsg: "Stopping cort procedure AddToUserPathAndInstallEngines; var ExpandedAppDir: String; - CmdLine, CortexInstallCmd: String; + CmdLine, CortexInstallCmd, CortexStopServerCmd: String; ResultCode: Integer; i: Integer; SkipPostInstall: Boolean; diff --git a/engine/templates/windows/installer-nightly.iss b/engine/templates/windows/installer-nightly.iss index 7924240da..0cf5616fc 100644 --- a/engine/templates/windows/installer-nightly.iss +++ b/engine/templates/windows/installer-nightly.iss @@ -36,7 +36,7 @@ Filename: "{app}\cortex-nightly.exe"; Parameters: "stop"; StatusMsg: "Stopping c procedure AddToUserPathAndInstallEngines; var ExpandedAppDir: String; - CmdLine, CortexInstallCmd: String; + CmdLine, CortexInstallCmd, CortexStopServerCmd: String; ResultCode: Integer; i: Integer; SkipPostInstall: Boolean; diff --git a/engine/templates/windows/installer.iss b/engine/templates/windows/installer.iss index 9eb4aa3fe..440d6bf93 100644 --- a/engine/templates/windows/installer.iss +++ b/engine/templates/windows/installer.iss @@ -36,7 +36,7 @@ Filename: "{app}\cortex.exe"; Parameters: "stop"; StatusMsg: "Stopping cortexcpp procedure AddToUserPathAndInstallEngines; var ExpandedAppDir: String; - CmdLine, CortexInstallCmd: String; + CmdLine, CortexInstallCmd, CortexStopServerCmd: String; ResultCode: Integer; i: Integer; SkipPostInstall: Boolean;