Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
f9fd0804
Unverified
Commit
f9fd0804
authored
Feb 16, 2024
by
Daniel Hiltgen
Committed by
GitHub
Feb 16, 2024
Browse files
Merge pull request #2552 from dhiltgen/dup_update_menus
Fix duplicate menus on update and exit on signals
parents
4318e35e
a497235a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
37 deletions
+53
-37
app/lifecycle/lifecycle.go
app/lifecycle/lifecycle.go
+9
-1
app/lifecycle/logging_windows.go
app/lifecycle/logging_windows.go
+1
-1
app/lifecycle/server.go
app/lifecycle/server.go
+7
-3
app/lifecycle/updater.go
app/lifecycle/updater.go
+5
-5
app/tray/wintray/menus.go
app/tray/wintray/menus.go
+21
-21
llm/generate/gen_windows.ps1
llm/generate/gen_windows.ps1
+5
-1
scripts/build_windows.ps1
scripts/build_windows.ps1
+5
-5
No files found.
app/lifecycle/lifecycle.go
View file @
f9fd0804
...
@@ -6,6 +6,8 @@ import (
...
@@ -6,6 +6,8 @@ import (
"log"
"log"
"log/slog"
"log/slog"
"os"
"os"
"os/signal"
"syscall"
"github.com/jmorganca/ollama/app/store"
"github.com/jmorganca/ollama/app/store"
"github.com/jmorganca/ollama/app/tray"
"github.com/jmorganca/ollama/app/tray"
...
@@ -23,12 +25,18 @@ func Run() {
...
@@ -23,12 +25,18 @@ func Run() {
}
}
callbacks
:=
t
.
GetCallbacks
()
callbacks
:=
t
.
GetCallbacks
()
signals
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
signals
,
syscall
.
SIGINT
,
syscall
.
SIGTERM
)
go
func
()
{
go
func
()
{
slog
.
Debug
(
"starting callback loop"
)
slog
.
Debug
(
"starting callback loop"
)
for
{
for
{
select
{
select
{
case
<-
callbacks
.
Quit
:
case
<-
callbacks
.
Quit
:
slog
.
Debug
(
"QUIT called"
)
slog
.
Debug
(
"quit called"
)
t
.
Quit
()
case
<-
signals
:
slog
.
Debug
(
"shutting down due to signal"
)
t
.
Quit
()
t
.
Quit
()
case
<-
callbacks
.
Update
:
case
<-
callbacks
.
Update
:
err
:=
DoUpgrade
(
cancel
,
done
)
err
:=
DoUpgrade
(
cancel
,
done
)
...
...
app/lifecycle/logging_windows.go
View file @
f9fd0804
...
@@ -11,7 +11,7 @@ func ShowLogs() {
...
@@ -11,7 +11,7 @@ func ShowLogs() {
cmd_path
:=
"c:
\\
Windows
\\
system32
\\
cmd.exe"
cmd_path
:=
"c:
\\
Windows
\\
system32
\\
cmd.exe"
slog
.
Debug
(
fmt
.
Sprintf
(
"viewing logs with start %s"
,
AppDataDir
))
slog
.
Debug
(
fmt
.
Sprintf
(
"viewing logs with start %s"
,
AppDataDir
))
cmd
:=
exec
.
Command
(
cmd_path
,
"/c"
,
"start"
,
AppDataDir
)
cmd
:=
exec
.
Command
(
cmd_path
,
"/c"
,
"start"
,
AppDataDir
)
cmd
.
SysProcAttr
=
&
syscall
.
SysProcAttr
{
HideWindow
:
tru
e
,
CreationFlags
:
0x08000000
}
cmd
.
SysProcAttr
=
&
syscall
.
SysProcAttr
{
HideWindow
:
fals
e
,
CreationFlags
:
0x08000000
}
err
:=
cmd
.
Start
()
err
:=
cmd
.
Start
()
if
err
!=
nil
{
if
err
!=
nil
{
slog
.
Error
(
fmt
.
Sprintf
(
"Failed to open log dir: %s"
,
err
))
slog
.
Error
(
fmt
.
Sprintf
(
"Failed to open log dir: %s"
,
err
))
...
...
app/lifecycle/server.go
View file @
f9fd0804
...
@@ -31,11 +31,15 @@ func getCLIFullPath(command string) string {
...
@@ -31,11 +31,15 @@ func getCLIFullPath(command string) string {
return
cmdPath
return
cmdPath
}
}
}
}
cmdPath
=
filepath
.
Join
(
"."
,
command
)
pwd
,
err
:=
os
.
Getwd
()
_
,
err
=
os
.
Stat
(
cmdPath
)
if
err
==
nil
{
if
err
==
nil
{
return
cmdPath
cmdPath
=
filepath
.
Join
(
pwd
,
command
)
_
,
err
=
os
.
Stat
(
cmdPath
)
if
err
==
nil
{
return
cmdPath
}
}
}
return
command
return
command
}
}
...
...
app/lifecycle/updater.go
View file @
f9fd0804
...
@@ -23,8 +23,9 @@ import (
...
@@ -23,8 +23,9 @@ import (
)
)
var
(
var
(
UpdateCheckURLBase
=
"https://ollama.com/api/update"
UpdateCheckURLBase
=
"https://ollama.com/api/update"
UpdateDownloaded
=
false
UpdateDownloaded
=
false
UpdateCheckInterval
=
60
*
60
*
time
.
Second
)
)
// TODO - maybe move up to the API package?
// TODO - maybe move up to the API package?
...
@@ -112,7 +113,6 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) {
...
@@ -112,7 +113,6 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) {
return
true
,
updateResp
return
true
,
updateResp
}
}
// Returns true if we downloaded a new update, false if we already had it
func
DownloadNewRelease
(
ctx
context
.
Context
,
updateResp
UpdateResponse
)
error
{
func
DownloadNewRelease
(
ctx
context
.
Context
,
updateResp
UpdateResponse
)
error
{
// Do a head first to check etag info
// Do a head first to check etag info
req
,
err
:=
http
.
NewRequestWithContext
(
ctx
,
http
.
MethodHead
,
updateResp
.
UpdateURL
,
nil
)
req
,
err
:=
http
.
NewRequestWithContext
(
ctx
,
http
.
MethodHead
,
updateResp
.
UpdateURL
,
nil
)
...
@@ -144,7 +144,7 @@ func DownloadNewRelease(ctx context.Context, updateResp UpdateResponse) error {
...
@@ -144,7 +144,7 @@ func DownloadNewRelease(ctx context.Context, updateResp UpdateResponse) error {
// Check to see if we already have it downloaded
// Check to see if we already have it downloaded
_
,
err
=
os
.
Stat
(
stageFilename
)
_
,
err
=
os
.
Stat
(
stageFilename
)
if
err
==
nil
{
if
err
==
nil
{
slog
.
Debug
(
"update already downloaded"
)
slog
.
Info
(
"update already downloaded"
)
return
nil
return
nil
}
}
...
@@ -231,7 +231,7 @@ func StartBackgroundUpdaterChecker(ctx context.Context, cb func(string) error) {
...
@@ -231,7 +231,7 @@ func StartBackgroundUpdaterChecker(ctx context.Context, cb func(string) error) {
slog
.
Debug
(
"stopping background update checker"
)
slog
.
Debug
(
"stopping background update checker"
)
return
return
default
:
default
:
time
.
Sleep
(
60
*
60
*
time
.
Second
)
time
.
Sleep
(
UpdateCheckInterval
)
}
}
}
}
}()
}()
...
...
app/tray/wintray/menus.go
View file @
f9fd0804
...
@@ -33,27 +33,28 @@ func (t *winTray) initMenus() error {
...
@@ -33,27 +33,28 @@ func (t *winTray) initMenus() error {
}
}
func
(
t
*
winTray
)
UpdateAvailable
(
ver
string
)
error
{
func
(
t
*
winTray
)
UpdateAvailable
(
ver
string
)
error
{
slog
.
Debug
(
"updating menu and sending notification for new update"
)
if
err
:=
t
.
addOrUpdateMenuItem
(
updatAvailableMenuID
,
0
,
updateAvailableMenuTitle
,
true
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to create menu entries %w"
,
err
)
}
if
err
:=
t
.
addOrUpdateMenuItem
(
updateMenuID
,
0
,
updateMenutTitle
,
false
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to create menu entries %w"
,
err
)
}
if
err
:=
t
.
addSeparatorMenuItem
(
separatorMenuID
,
0
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to create menu entries %w"
,
err
)
}
iconFilePath
,
err
:=
iconBytesToFilePath
(
wt
.
updateIcon
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to write icon data to temp file: %w"
,
err
)
}
if
err
:=
wt
.
setIcon
(
iconFilePath
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to set icon: %w"
,
err
)
}
t
.
pendingUpdate
=
true
// Now pop up the notification
if
!
t
.
updateNotified
{
if
!
t
.
updateNotified
{
slog
.
Debug
(
"updating menu and sending notification for new update"
)
if
err
:=
t
.
addOrUpdateMenuItem
(
updatAvailableMenuID
,
0
,
updateAvailableMenuTitle
,
true
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to create menu entries %w"
,
err
)
}
if
err
:=
t
.
addOrUpdateMenuItem
(
updateMenuID
,
0
,
updateMenutTitle
,
false
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to create menu entries %w"
,
err
)
}
if
err
:=
t
.
addSeparatorMenuItem
(
separatorMenuID
,
0
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to create menu entries %w"
,
err
)
}
iconFilePath
,
err
:=
iconBytesToFilePath
(
wt
.
updateIcon
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to write icon data to temp file: %w"
,
err
)
}
if
err
:=
wt
.
setIcon
(
iconFilePath
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to set icon: %w"
,
err
)
}
t
.
updateNotified
=
true
t
.
pendingUpdate
=
true
// Now pop up the notification
t
.
muNID
.
Lock
()
t
.
muNID
.
Lock
()
defer
t
.
muNID
.
Unlock
()
defer
t
.
muNID
.
Unlock
()
copy
(
t
.
nid
.
InfoTitle
[
:
],
windows
.
StringToUTF16
(
updateTitle
))
copy
(
t
.
nid
.
InfoTitle
[
:
],
windows
.
StringToUTF16
(
updateTitle
))
...
@@ -65,7 +66,6 @@ func (t *winTray) UpdateAvailable(ver string) error {
...
@@ -65,7 +66,6 @@ func (t *winTray) UpdateAvailable(ver string) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
t
.
updateNotified
=
true
}
}
return
nil
return
nil
}
}
llm/generate/gen_windows.ps1
View file @
f9fd0804
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
$Error
ActionPreference
=
"Stop"
$Error
ActionPreference
=
"Stop"
function
init_vars
{
function
init_vars
{
$
script
:
SRC_DIR
=
$
(
resolve-path
"..\..\"
)
$
script
:
llamacppDir
=
"../llama.cpp"
$
script
:
llamacppDir
=
"../llama.cpp"
$
script
:
cmakeDefs
=
@(
"-DBUILD_SHARED_LIBS=on"
,
"-DLLAMA_NATIVE=off"
,
"-A"
,
"x64"
)
$
script
:
cmakeDefs
=
@(
"-DBUILD_SHARED_LIBS=on"
,
"-DLLAMA_NATIVE=off"
,
"-A"
,
"x64"
)
$
script
:
cmakeTargets
=
@(
"ext_server"
)
$
script
:
cmakeTargets
=
@(
"ext_server"
)
...
@@ -33,6 +34,9 @@ function init_vars {
...
@@ -33,6 +34,9 @@ function init_vars {
}
}
# Note: 10 Windows Kit signtool crashes with GCP's plugin
# Note: 10 Windows Kit signtool crashes with GCP's plugin
${script:SignTool}
=
"C:\Program Files (x86)\Windows Kits\8.1\bin\x64\signtool.exe"
${script:SignTool}
=
"C:\Program Files (x86)\Windows Kits\8.1\bin\x64\signtool.exe"
if
(
"
${env:KEY_CONTAINER}
"
)
{
${script:OLLAMA_CERT}
=
$
(
resolve-path
"
${script:SRC_DIR}
\ollama_inc.crt"
)
}
}
}
function
git_module_setup
{
function
git_module_setup
{
...
@@ -102,7 +106,7 @@ function sign {
...
@@ -102,7 +106,7 @@ function sign {
if
(
"
${env:KEY_CONTAINER}
"
)
{
if
(
"
${env:KEY_CONTAINER}
"
)
{
write-host
"Signing
${script:buildDir}
/lib/*.dll"
write-host
"Signing
${script:buildDir}
/lib/*.dll"
foreach
(
$file
in
(
get-childitem
"
${script:buildDir}
/lib/*.dll"
)){
foreach
(
$file
in
(
get-childitem
"
${script:buildDir}
/lib/*.dll"
)){
&
"
${script:SignTool}
"
sign
/v
/fd
sha256
/t
http://timestamp.digicert.com
/f
"
${
env
:OLLAMA_CERT}
"
`
&
"
${script:SignTool}
"
sign
/v
/fd
sha256
/t
http://timestamp.digicert.com
/f
"
${
script
:OLLAMA_CERT}
"
`
/csp
"Google Cloud KMS Provider"
/kc
"
${env:KEY_CONTAINER}
"
$file
/csp
"Google Cloud KMS Provider"
/kc
"
${env:KEY_CONTAINER}
"
$file
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
}
}
...
...
scripts/build_windows.ps1
View file @
f9fd0804
...
@@ -38,7 +38,7 @@ function checkEnv() {
...
@@ -38,7 +38,7 @@ function checkEnv() {
# Check for signing key
# Check for signing key
if
(
"
${env:KEY_CONTAINER}
"
)
{
if
(
"
${env:KEY_CONTAINER}
"
)
{
${
env
:OLLAMA_CERT}
=
$
(
resolve-path
"
${script:SRC_DIR}
\ollama_inc.crt"
)
${
script
:OLLAMA_CERT}
=
$
(
resolve-path
"
${script:SRC_DIR}
\ollama_inc.crt"
)
Write-host
"Code signing enabled"
Write-host
"Code signing enabled"
# Note: 10 Windows Kit signtool crashes with GCP's plugin
# Note: 10 Windows Kit signtool crashes with GCP's plugin
${script:SignTool}
=
"C:\Program Files (x86)\Windows Kits\8.1\bin\x64\signtool.exe"
${script:SignTool}
=
"C:\Program Files (x86)\Windows Kits\8.1\bin\x64\signtool.exe"
...
@@ -56,7 +56,7 @@ function buildOllama() {
...
@@ -56,7 +56,7 @@ function buildOllama() {
&
go
build
"-ldflags=-w -s ""-X=github.com/jmorganca/ollama/version.Version=
$
script
:
VERSION
"" ""-X=github.com/jmorganca/ollama/server.mode=release"""
.
&
go
build
"-ldflags=-w -s ""-X=github.com/jmorganca/ollama/version.Version=
$
script
:
VERSION
"" ""-X=github.com/jmorganca/ollama/server.mode=release"""
.
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
if
(
"
${env:KEY_CONTAINER}
"
)
{
if
(
"
${env:KEY_CONTAINER}
"
)
{
&
"
${script:SignTool}
"
sign
/v
/fd
sha256
/t
http://timestamp.digicert.com
/f
"
${
env
:OLLAMA_CERT}
"
`
&
"
${script:SignTool}
"
sign
/v
/fd
sha256
/t
http://timestamp.digicert.com
/f
"
${
script
:OLLAMA_CERT}
"
`
/csp
"Google Cloud KMS Provider"
/kc
${env:KEY_CONTAINER}
ollama.exe
/csp
"Google Cloud KMS Provider"
/kc
${env:KEY_CONTAINER}
ollama.exe
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
}
}
...
@@ -70,7 +70,7 @@ function buildApp() {
...
@@ -70,7 +70,7 @@ function buildApp() {
&
go
build
"-ldflags=-H windowsgui -w -s ""-X=github.com/jmorganca/ollama/version.Version=
$
script
:
VERSION
"" ""-X=github.com/jmorganca/ollama/server.mode=release"""
.
&
go
build
"-ldflags=-H windowsgui -w -s ""-X=github.com/jmorganca/ollama/version.Version=
$
script
:
VERSION
"" ""-X=github.com/jmorganca/ollama/server.mode=release"""
.
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
if
(
"
${env:KEY_CONTAINER}
"
)
{
if
(
"
${env:KEY_CONTAINER}
"
)
{
&
"
${script:SignTool}
"
sign
/v
/fd
sha256
/t
http://timestamp.digicert.com
/f
"
${
env
:OLLAMA_CERT}
"
`
&
"
${script:SignTool}
"
sign
/v
/fd
sha256
/t
http://timestamp.digicert.com
/f
"
${
script
:OLLAMA_CERT}
"
`
/csp
"Google Cloud KMS Provider"
/kc
${env:KEY_CONTAINER}
app.exe
/csp
"Google Cloud KMS Provider"
/kc
${env:KEY_CONTAINER}
app.exe
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
}
}
...
@@ -97,7 +97,7 @@ function gatherDependencies() {
...
@@ -97,7 +97,7 @@ function gatherDependencies() {
write-host
"about to sign"
write-host
"about to sign"
foreach
(
$file
in
(
get-childitem
"
${script:DEPS_DIR}
/cu*.dll"
)
+
@(
"
${script:SRC_DIR}
\dist\ollama_welcome.ps1"
)){
foreach
(
$file
in
(
get-childitem
"
${script:DEPS_DIR}
/cu*.dll"
)
+
@(
"
${script:SRC_DIR}
\dist\ollama_welcome.ps1"
)){
write-host
"signing
$file
"
write-host
"signing
$file
"
&
"
${script:SignTool}
"
sign
/v
/fd
sha256
/t
http://timestamp.digicert.com
/f
"
${
env
:OLLAMA_CERT}
"
`
&
"
${script:SignTool}
"
sign
/v
/fd
sha256
/t
http://timestamp.digicert.com
/f
"
${
script
:OLLAMA_CERT}
"
`
/csp
"Google Cloud KMS Provider"
/kc
${env:KEY_CONTAINER}
$file
/csp
"Google Cloud KMS Provider"
/kc
${env:KEY_CONTAINER}
$file
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
}
}
...
@@ -110,7 +110,7 @@ function buildInstaller() {
...
@@ -110,7 +110,7 @@ function buildInstaller() {
cd
"
${script:SRC_DIR}
\app"
cd
"
${script:SRC_DIR}
\app"
$
env
:
PKG_VERSION
=
$
script
:
PKG_VERSION
$
env
:
PKG_VERSION
=
$
script
:
PKG_VERSION
if
(
"
${env:KEY_CONTAINER}
"
)
{
if
(
"
${env:KEY_CONTAINER}
"
)
{
&
"
${script:INNO_SETUP_DIR}
\ISCC.exe"
/SMySignTool
=
"
${script:SignTool}
sign /fd sha256 /t http://timestamp.digicert.com /f
${
env
:OLLAMA_CERT}
/csp
`$
qGoogle Cloud KMS Provider
`$
q /kc
${env:KEY_CONTAINER}
`$
f"
.
\ollama.iss
&
"
${script:INNO_SETUP_DIR}
\ISCC.exe"
/SMySignTool
=
"
${script:SignTool}
sign /fd sha256 /t http://timestamp.digicert.com /f
${
script
:OLLAMA_CERT}
/csp
`$
qGoogle Cloud KMS Provider
`$
q /kc
${env:KEY_CONTAINER}
`$
f"
.
\ollama.iss
}
else
{
}
else
{
&
"
${script:INNO_SETUP_DIR}
\ISCC.exe"
.
\ollama.iss
&
"
${script:INNO_SETUP_DIR}
\ISCC.exe"
.
\ollama.iss
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment