Skip to content

Commit

Permalink
fix: server uploads to temporary directory (#1610)
Browse files Browse the repository at this point in the history
* fix: server uploads to temporary directory

* fix: format

* fix: start/stop server

* fix: postinstall

* fix: stop server linux windows

* fix: build windows
  • Loading branch information
vansangpfiev authored Nov 4, 2024
1 parent 267403e commit 76d653f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ void RunServer(std::optional<int> port) {
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";
Expand Down
1 change: 1 addition & 0 deletions engine/templates/linux/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions engine/templates/macos/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 5 additions & 1 deletion engine/templates/windows/installer-beta.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion engine/templates/windows/installer-nightly.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion engine/templates/windows/installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 76d653f

Please sign in to comment.