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

Commit 76d653f

Browse files
authored
fix: server uploads to temporary directory (#1610)
* fix: server uploads to temporary directory * fix: format * fix: start/stop server * fix: postinstall * fix: stop server linux windows * fix: build windows
1 parent 267403e commit 76d653f

File tree

6 files changed

+25
-3
lines changed

6 files changed

+25
-3
lines changed

engine/main.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ void RunServer(std::optional<int> port) {
109109
drogon::app().registerController(pm_ctl);
110110
drogon::app().registerController(server_ctl);
111111

112+
auto upload_path = std::filesystem::temp_directory_path() / "cortex-uploads";
113+
drogon::app().setUploadPath(upload_path.string());
114+
112115
LOG_INFO << "Server started, listening at: " << config.apiServerHost << ":"
113116
<< config.apiServerPort;
114117
LOG_INFO << "Please load your model";

engine/templates/linux/postinst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ fi
99
USER_TO_RUN_AS=${SUDO_USER:-$(whoami)}
1010
echo "Download cortex.llamacpp engines by default for user $USER_TO_RUN_AS"
1111
sudo -u $USER_TO_RUN_AS env PATH=$PATH:/usr/lib/wsl/lib /usr/bin/$DESTINATION_BINARY_NAME engines install llama-cpp
12+
sudo -u $USER_TO_RUN_AS env PATH=$PATH:/usr/lib/wsl/lib /usr/bin/$DESTINATION_BINARY_NAME stop

engine/templates/macos/postinstall

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ fi
1111

1212
USER_TO_RUN_AS=$(stat -f "%Su" /dev/console)
1313

14+
echo "Start server before downloading server for user $USER_TO_RUN_AS"
15+
sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME start
16+
1417
echo "Download cortex.llamacpp engines by default for user $USER_TO_RUN_AS"
1518
sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME engines install llama-cpp
1619

20+
echo "Stop server"
21+
sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME stop
22+
1723
sudo chown -R $USER_TO_RUN_AS:staff "/Users/$USER_TO_RUN_AS/$DATA_FOLDER_NAME"
1824
sudo chown $USER_TO_RUN_AS:staff "/Users/$USER_TO_RUN_AS/$CONFIGURATION_FILE_NAME"
1925

engine/templates/windows/installer-beta.iss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Filename: "{app}\cortex-beta.exe"; Parameters: "stop"; StatusMsg: "Stopping cort
3636
procedure AddToUserPathAndInstallEngines;
3737
var
3838
ExpandedAppDir: String;
39-
CmdLine, CortexInstallCmd: String;
39+
CmdLine, CortexInstallCmd, CortexStopServerCmd: String;
4040
ResultCode: Integer;
4141
i: Integer;
4242
SkipPostInstall: Boolean;
@@ -84,6 +84,10 @@ begin
8484
CortexInstallCmd := Format('"%s\cortex-beta.exe" engines install llama-cpp', [ExpandedAppDir]);
8585
Exec('cmd.exe', '/C ' + CortexInstallCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
8686
87+
// Stop server
88+
CortexStopServerCmd := Format('"%s\cortex-nightly.exe" stop', [ExpandedAppDir]);
89+
Exec('cmd.exe', '/C ' + CortexStopServerCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
90+
8791
// Set the progress bar to 90% after downloading the engine
8892
WizardForm.ProgressGauge.Position := 90;
8993
WizardForm.ProgressGauge.Update;

engine/templates/windows/installer-nightly.iss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Filename: "{app}\cortex-nightly.exe"; Parameters: "stop"; StatusMsg: "Stopping c
3636
procedure AddToUserPathAndInstallEngines;
3737
var
3838
ExpandedAppDir: String;
39-
CmdLine, CortexInstallCmd: String;
39+
CmdLine, CortexInstallCmd, CortexStopServerCmd: String;
4040
ResultCode: Integer;
4141
i: Integer;
4242
SkipPostInstall: Boolean;
@@ -84,6 +84,10 @@ begin
8484
CortexInstallCmd := Format('"%s\cortex-nightly.exe" engines install llama-cpp', [ExpandedAppDir]);
8585
Exec('cmd.exe', '/C ' + CortexInstallCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
8686
87+
// Stop server
88+
CortexStopServerCmd := Format('"%s\cortex-nightly.exe" stop', [ExpandedAppDir]);
89+
Exec('cmd.exe', '/C ' + CortexStopServerCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
90+
8791
// Set the progress bar to 90% after downloading the engine
8892
WizardForm.ProgressGauge.Position := 90;
8993
WizardForm.ProgressGauge.Update;

engine/templates/windows/installer.iss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Filename: "{app}\cortex.exe"; Parameters: "stop"; StatusMsg: "Stopping cortexcpp
3636
procedure AddToUserPathAndInstallEngines;
3737
var
3838
ExpandedAppDir: String;
39-
CmdLine, CortexInstallCmd: String;
39+
CmdLine, CortexInstallCmd, CortexStopServerCmd: String;
4040
ResultCode: Integer;
4141
i: Integer;
4242
SkipPostInstall: Boolean;
@@ -84,6 +84,10 @@ begin
8484
CortexInstallCmd := Format('"%s\cortex.exe" engines install llama-cpp', [ExpandedAppDir]);
8585
Exec('cmd.exe', '/C ' + CortexInstallCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
8686
87+
// Stop server
88+
CortexStopServerCmd := Format('"%s\cortex-nightly.exe" stop', [ExpandedAppDir]);
89+
Exec('cmd.exe', '/C ' + CortexStopServerCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
90+
8791
// Set the progress bar to 90% after downloading the engine
8892
WizardForm.ProgressGauge.Position := 90;
8993
WizardForm.ProgressGauge.Update;

0 commit comments

Comments
 (0)