@simplexai/localmodels-linux-arm64 0.1.0-dev.57 → 0.1.0-dev.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +66 -64
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/app.py +1 -1
- package/modules/localmodels/bifrost_admin.py +53 -8
- package/modules/localmodels/bifrost_config.py +103 -4
- package/modules/localmodels/bifrost_log.py +166 -0
- package/modules/localmodels/budget.py +161 -1
- package/modules/localmodels/catalog.json +55 -32
- package/modules/localmodels/catalog.py +5 -2
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.5.json +94 -0
- package/modules/localmodels/frontend.py +26 -21
- package/modules/localmodels/gateway_bifrost.py +30 -6
- package/modules/localmodels/gpu_specs.py +38 -13
- package/modules/localmodels/hosts.py +99 -12
- package/modules/localmodels/library_cli.py +8 -1
- package/modules/localmodels/library_convert.py +34 -0
- package/modules/localmodels/library_elastic.py +747 -0
- package/modules/localmodels/library_gateway.py +101 -10
- package/modules/localmodels/library_jobs.py +16 -7
- package/modules/localmodels/library_model.py +101 -4
- package/modules/localmodels/library_pricing.py +41 -39
- package/modules/localmodels/library_serve.py +322 -58
- package/modules/localmodels/library_state.py +35 -1
- package/modules/localmodels/library_status.py +113 -6
- package/modules/localmodels/llm_rank.py +16 -5
- package/modules/localmodels/metal.py +141 -0
- package/modules/localmodels/metal_probe.py +167 -0
- package/modules/localmodels/plan_envelope.py +4 -1
- package/modules/localmodels/probe.py +2 -2
- package/modules/localmodels/process_identity_linux.py +39 -0
- package/modules/localmodels/recommend.py +6 -1
- package/modules/localmodels/remote_ops.py +4 -3
- package/modules/localmodels/remote_ops_download.py +37 -24
- package/modules/localmodels/remote_ops_mirrors.py +43 -2
- package/modules/localmodels/remote_ops_service.py +93 -36
- package/modules/localmodels/runtime_auth.py +4 -1
- package/modules/localmodels/service_wiring.py +238 -12
- package/modules/localmodels/setup_inspection.py +47 -70
- package/modules/localmodels/setup_inspection_harness.py +159 -15
- package/modules/localmodels/setup_text.py +14 -0
- package/modules/localmodels/setup_upgrade.py +1 -1
- package/modules/localmodels/source_byok.py +6 -2
- package/modules/localmodels/source_byok_probe.py +6 -1
- package/modules/localmodels/stack.py +9 -1
- package/modules/localmodels/stack_binding.py +3 -35
- package/modules/localmodels/stack_cleanup.py +4 -0
- package/modules/localmodels/stack_compose.py +24 -3
- package/modules/localmodels/stack_hardware.py +3 -1
- package/modules/localmodels/stack_lifecycle.py +24 -1
- package/modules/localmodels/stack_picks.py +16 -2
- package/modules/localmodels/stack_plan.py +6 -2
- package/modules/localmodels/stack_ports.py +2 -0
- package/modules/localmodels/stack_remove.py +10 -1
- package/modules/localmodels/stack_up.py +33 -7
- package/modules/localmodels/stack_update.py +3 -1
- package/modules/localmodels/{strata-poly-serve-0.2.19-poly.1.txt → strata-poly-serve-0.2.20-poly.5.txt} +1 -1
- package/modules/localmodels/suite.py +43 -27
- package/modules/localmodels/transport.py +13 -2
- package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/RECORD +63 -61
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-poly-0.2.19-poly.1.json +0 -79
- /package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -6,6 +6,7 @@ import os
|
|
|
6
6
|
import shlex
|
|
7
7
|
import shutil
|
|
8
8
|
import subprocess
|
|
9
|
+
import sys
|
|
9
10
|
import time
|
|
10
11
|
from pathlib import Path
|
|
11
12
|
|
|
@@ -165,3 +166,41 @@ def command_matches(pid: int, expected: list[str], root: str = "/") -> bool:
|
|
|
165
166
|
return argv_matches(actual, process.joinpath("exe"), expected, root)
|
|
166
167
|
except (OSError, ValueError, UnicodeError):
|
|
167
168
|
return False
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def bind_to_parent(parent: object) -> None:
|
|
172
|
+
"""End this local POSIX streaming helper when its controller dies (e.g. SIGKILL), matching
|
|
173
|
+
Windows's kill-on-close job object so an orphan never keeps writing ``.part`` files after
|
|
174
|
+
``cancel`` or a resumed download took over."""
|
|
175
|
+
if not isinstance(parent, int) or isinstance(parent, bool) or parent <= 1 or os.name == "nt":
|
|
176
|
+
return
|
|
177
|
+
armed = False
|
|
178
|
+
if sys.platform.startswith("linux"):
|
|
179
|
+
try:
|
|
180
|
+
import ctypes
|
|
181
|
+
import signal
|
|
182
|
+
|
|
183
|
+
libc = ctypes.CDLL(None)
|
|
184
|
+
libc.prctl.argtypes = (
|
|
185
|
+
ctypes.c_int,
|
|
186
|
+
ctypes.c_ulong,
|
|
187
|
+
ctypes.c_ulong,
|
|
188
|
+
ctypes.c_ulong,
|
|
189
|
+
ctypes.c_ulong,
|
|
190
|
+
)
|
|
191
|
+
libc.prctl.restype = ctypes.c_int
|
|
192
|
+
armed = libc.prctl(1, signal.SIGKILL, 0, 0, 0) == 0 # PR_SET_PDEATHSIG = 1
|
|
193
|
+
except (OSError, AttributeError):
|
|
194
|
+
armed = False
|
|
195
|
+
if os.getppid() != parent:
|
|
196
|
+
os._exit(1)
|
|
197
|
+
if not armed:
|
|
198
|
+
import threading
|
|
199
|
+
|
|
200
|
+
def _watch() -> None:
|
|
201
|
+
while True:
|
|
202
|
+
time.sleep(0.2)
|
|
203
|
+
if os.getppid() != parent:
|
|
204
|
+
os._exit(1)
|
|
205
|
+
|
|
206
|
+
threading.Thread(target=_watch, name="parent-watch", daemon=True).start()
|
|
@@ -193,7 +193,12 @@ def recommendation(
|
|
|
193
193
|
break
|
|
194
194
|
if not fitting:
|
|
195
195
|
return None
|
|
196
|
-
|
|
196
|
+
slow_ids = {
|
|
197
|
+
entry_id for (_, tok_s), entry_id, _ in fitting if tok_s < cat.USABLE_FLOOR_TOK_S
|
|
198
|
+
}
|
|
199
|
+
entry_id, index = llm_rank.choose(
|
|
200
|
+
fitting, "smartest", fallback_ids={fallback.id}, slow_ids=slow_ids
|
|
201
|
+
)
|
|
197
202
|
if entry_id != fallback.id:
|
|
198
203
|
return None
|
|
199
204
|
fallback_placement = next((p for p in host if p.id == f"gpu:{index}"), None)
|
|
@@ -619,6 +619,8 @@ def unpack(archive: str, directory: str, keep: tuple[str, ...] = ()) -> None:
|
|
|
619
619
|
member.mode |= 0o700
|
|
620
620
|
elif member.isfile():
|
|
621
621
|
member.mode |= 0o200
|
|
622
|
+
if member.issym() or member.islnk():
|
|
623
|
+
remote_ops_download.clear_link(os.path.join(directory, name))
|
|
622
624
|
tar.extract(member, directory)
|
|
623
625
|
|
|
624
626
|
|
|
@@ -729,9 +731,8 @@ ACTIONS: Actions = {
|
|
|
729
731
|
|
|
730
732
|
|
|
731
733
|
def main(argv: list[str]) -> int:
|
|
732
|
-
|
|
733
|
-
#
|
|
734
|
-
os.umask(os.umask(0o022) | 0o022)
|
|
734
|
+
remote_ops_download.bind_to_parent(globals().get("_PARENT_PID"))
|
|
735
|
+
os.umask(os.umask(0o022) | 0o022) # never leave group/world-writable files under umask 0002
|
|
735
736
|
encoded = globals().get("_PARAMS_B64") or (argv[2] if len(argv) == 3 else None)
|
|
736
737
|
if len(argv) not in (2, 3) or argv[1] not in ACTIONS or encoded is None:
|
|
737
738
|
sys.stderr.write("usage: remote_ops.py {{{}}} [PARAMS_B64]\n".format("|".join(ACTIONS)))
|
|
@@ -21,8 +21,15 @@ import urllib.request
|
|
|
21
21
|
from typing import Iterator, Tuple
|
|
22
22
|
|
|
23
23
|
try:
|
|
24
|
-
from localmodels import
|
|
24
|
+
from localmodels import (
|
|
25
|
+
process_identity_linux,
|
|
26
|
+
remote_ops,
|
|
27
|
+
remote_ops_mirrors,
|
|
28
|
+
remote_ops_prepare,
|
|
29
|
+
remote_ops_ranges,
|
|
30
|
+
)
|
|
25
31
|
except ImportError: # run as a bare file from this directory
|
|
32
|
+
import process_identity_linux # type: ignore[import-not-found,no-redef]
|
|
26
33
|
import remote_ops # type: ignore[import-not-found,no-redef]
|
|
27
34
|
import remote_ops_mirrors # type: ignore[import-not-found,no-redef]
|
|
28
35
|
import remote_ops_prepare # type: ignore[import-not-found,no-redef]
|
|
@@ -40,29 +47,33 @@ def act_engine(p: remote_ops.EngineParams) -> None:
|
|
|
40
47
|
if os.path.exists(done_marker) and remote_ops._read(done_marker).strip() == expected:
|
|
41
48
|
remote_ops.emit("result", binary=binary, reused=True)
|
|
42
49
|
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
a["
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
50
|
+
with remote_ops_mirrors.engine_lock(directory):
|
|
51
|
+
if os.path.exists(done_marker) and remote_ops._read(done_marker).strip() == expected:
|
|
52
|
+
remote_ops.emit("result", binary=binary, reused=True)
|
|
53
|
+
return
|
|
54
|
+
os.makedirs(directory, exist_ok=True)
|
|
55
|
+
cache = os.path.join(os.path.dirname(directory), ".archives")
|
|
56
|
+
active_region = p.get("region")
|
|
57
|
+
for i in remote_ops.each_file(
|
|
58
|
+
[(os.path.join(cache, a["name"]), a["size_bytes"]) for a in p["assets"]]
|
|
59
|
+
):
|
|
60
|
+
a = p["assets"][i]
|
|
61
|
+
archive = os.path.join(cache, a["name"])
|
|
62
|
+
switched = remote_ops.fetch(
|
|
63
|
+
a["url"],
|
|
64
|
+
archive,
|
|
65
|
+
a["sha256"],
|
|
66
|
+
a["size_bytes"],
|
|
67
|
+
a["name"],
|
|
68
|
+
npm_copies(a),
|
|
69
|
+
active_region,
|
|
70
|
+
)
|
|
71
|
+
if switched in ("cn", "global"):
|
|
72
|
+
active_region = switched
|
|
73
|
+
remote_ops.unpack(archive, directory, tuple(a.get("members") or ()))
|
|
74
|
+
if not os.access(binary, os.X_OK):
|
|
75
|
+
raise RuntimeError(f"the engine has no executable {os.path.relpath(binary, directory)}")
|
|
76
|
+
remote_ops._write(done_marker, expected)
|
|
66
77
|
remote_ops.emit("result", binary=binary, reused=False)
|
|
67
78
|
|
|
68
79
|
|
|
@@ -234,6 +245,8 @@ _load_ranges = remote_ops_mirrors.load_ranges
|
|
|
234
245
|
_save_ranges = remote_ops_mirrors.save_ranges
|
|
235
246
|
kept_bytes = remote_ops_mirrors.kept_bytes
|
|
236
247
|
discard = remote_ops_mirrors.discard
|
|
248
|
+
clear_link = remote_ops_mirrors.clear_link
|
|
249
|
+
bind_to_parent = process_identity_linux.bind_to_parent
|
|
237
250
|
|
|
238
251
|
|
|
239
252
|
def npm_transfer(source: remote_ops.Source, part: str, size: int, label: str) -> None:
|
|
@@ -7,6 +7,7 @@ Part of the remote_ops bundle (transport.BUNDLES): standard library only, Python
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
9
|
import collections
|
|
10
|
+
import contextlib
|
|
10
11
|
import json
|
|
11
12
|
import os
|
|
12
13
|
import shutil
|
|
@@ -14,6 +15,7 @@ import tarfile
|
|
|
14
15
|
import time
|
|
15
16
|
import urllib.parse
|
|
16
17
|
import urllib.request
|
|
18
|
+
from typing import Iterator
|
|
17
19
|
|
|
18
20
|
try:
|
|
19
21
|
from localmodels import remote_ops
|
|
@@ -232,9 +234,48 @@ def kept_bytes(part: str, size: int) -> int:
|
|
|
232
234
|
|
|
233
235
|
|
|
234
236
|
def discard(part: str) -> None:
|
|
235
|
-
for path in (part, state_path(part)):
|
|
236
|
-
|
|
237
|
+
for path in (part, state_path(part), state_path(part) + ".tmp", part + ".tmp", part + ".npm"):
|
|
238
|
+
try:
|
|
237
239
|
os.remove(path)
|
|
240
|
+
except FileNotFoundError:
|
|
241
|
+
pass
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def clear_link(target: str) -> None:
|
|
245
|
+
"""Remove an existing file or symlink before tar.extract recreates a link member."""
|
|
246
|
+
if os.path.islink(target) or os.path.isfile(target):
|
|
247
|
+
os.unlink(target)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
@contextlib.contextmanager
|
|
251
|
+
def engine_lock(directory: str) -> Iterator[None]:
|
|
252
|
+
"""Serialize concurrent engine fetches and unpacks under the same engines root so parallel
|
|
253
|
+
model downloads never race on ``.archives/*.part`` or ``unpack()``."""
|
|
254
|
+
parent = os.path.dirname(directory) or "."
|
|
255
|
+
os.makedirs(parent, exist_ok=True)
|
|
256
|
+
lock_path = os.path.join(parent, ".engine.lock")
|
|
257
|
+
with open(lock_path, "a+") as lock:
|
|
258
|
+
if os.name == "nt":
|
|
259
|
+
import msvcrt
|
|
260
|
+
|
|
261
|
+
lock.seek(0)
|
|
262
|
+
while True:
|
|
263
|
+
try:
|
|
264
|
+
msvcrt.locking(lock.fileno(), msvcrt.LK_NBLCK, 1) # type: ignore[attr-defined]
|
|
265
|
+
break
|
|
266
|
+
except OSError:
|
|
267
|
+
time.sleep(0.1)
|
|
268
|
+
try:
|
|
269
|
+
yield
|
|
270
|
+
finally:
|
|
271
|
+
with contextlib.suppress(OSError):
|
|
272
|
+
lock.seek(0)
|
|
273
|
+
msvcrt.locking(lock.fileno(), msvcrt.LK_UNLCK, 1) # type: ignore[attr-defined]
|
|
274
|
+
else:
|
|
275
|
+
import fcntl
|
|
276
|
+
|
|
277
|
+
fcntl.flock(lock, fcntl.LOCK_EX)
|
|
278
|
+
yield
|
|
238
279
|
|
|
239
280
|
|
|
240
281
|
def npm_transfer(
|
|
@@ -109,7 +109,7 @@ def _start_windows(paths: dict[str, str]) -> None:
|
|
|
109
109
|
|
|
110
110
|
|
|
111
111
|
def _previous_install(
|
|
112
|
-
p: remote_ops.
|
|
112
|
+
p: remote_ops.ServiceParams, paths: dict[str, str]
|
|
113
113
|
) -> remote_ops.InstallParams:
|
|
114
114
|
try:
|
|
115
115
|
record = json.loads(remote_ops._read(paths["spec"]))
|
|
@@ -136,7 +136,10 @@ def _previous_install(
|
|
|
136
136
|
raise RuntimeError(
|
|
137
137
|
"cannot confirm who owns the existing deployment; config left unchanged"
|
|
138
138
|
) from exc
|
|
139
|
-
return
|
|
139
|
+
return cast(
|
|
140
|
+
"remote_ops.InstallParams",
|
|
141
|
+
{**p, "argv": cast("list[str]", argv), "env": cast("dict[str, str]", env), "port": port},
|
|
142
|
+
)
|
|
140
143
|
|
|
141
144
|
|
|
142
145
|
def _darwin_listener_pids(port: int) -> set[int] | None:
|
|
@@ -272,14 +275,15 @@ def _unit_property(unit: str, prop: str) -> str:
|
|
|
272
275
|
return value
|
|
273
276
|
|
|
274
277
|
|
|
278
|
+
_FOREIGN_UNIT = "a systemd unit with this name belongs to another deployment"
|
|
279
|
+
|
|
280
|
+
|
|
275
281
|
def _require_own_fragment(unit: str, paths: dict[str, str]) -> None:
|
|
276
282
|
# The user manager loads a unit by name from its own search path, which need not
|
|
277
283
|
# include the one HOME points at; a same-named unit there is another deployment's.
|
|
278
284
|
fragment = _unit_property(unit, "FragmentPath")
|
|
279
285
|
if fragment and Path(fragment).resolve() != Path(paths["unit"]).resolve():
|
|
280
|
-
raise RuntimeError(
|
|
281
|
-
"a systemd unit with this name belongs to another deployment; config left unchanged"
|
|
282
|
-
)
|
|
286
|
+
raise RuntimeError(f"{_FOREIGN_UNIT}; config left unchanged")
|
|
283
287
|
|
|
284
288
|
|
|
285
289
|
def _unit_not_loaded(unit: str) -> bool:
|
|
@@ -329,8 +333,13 @@ def _recorded_service(paths: dict[str, str]) -> str | None:
|
|
|
329
333
|
|
|
330
334
|
|
|
331
335
|
def unit_runs_elsewhere(paths: dict[str, str]) -> bool:
|
|
332
|
-
"""The unit file of this name exists
|
|
333
|
-
carried the root tag, two installs could share one name, and only
|
|
336
|
+
"""The unit file of this name exists (or is a symlink) and does not run this directory's
|
|
337
|
+
run.sh: before unit names carried the root tag, two installs could share one name, and only
|
|
338
|
+
one of them owns it."""
|
|
339
|
+
if os.path.islink(paths["unit"]):
|
|
340
|
+
return True
|
|
341
|
+
if not os.path.exists(paths["unit"]):
|
|
342
|
+
return False
|
|
334
343
|
try:
|
|
335
344
|
text = remote_ops._read(paths["unit"])
|
|
336
345
|
except OSError:
|
|
@@ -368,6 +377,8 @@ def _prepare_install(p: remote_ops.InstallParams, paths: dict[str, str]) -> None
|
|
|
368
377
|
systemd = p["service_kind"] == "systemd-user"
|
|
369
378
|
if systemd:
|
|
370
379
|
_retire_renamed_unit(p, paths)
|
|
380
|
+
if unit_runs_elsewhere(paths):
|
|
381
|
+
raise RuntimeError(f"{_FOREIGN_UNIT}; config left unchanged")
|
|
371
382
|
state = remote_ops._systemctl("is-active", p["service"] + ".service")[1] if systemd else ""
|
|
372
383
|
pid = None if systemd else remote_ops._pid_alive(paths["pid"])
|
|
373
384
|
if pid is not None:
|
|
@@ -376,9 +387,11 @@ def _prepare_install(p: remote_ops.InstallParams, paths: dict[str, str]) -> None
|
|
|
376
387
|
pid = None
|
|
377
388
|
if systemd and state not in ("active", "inactive", "failed", "unknown"):
|
|
378
389
|
raise RuntimeError("the systemd service state is uncertain; config left unchanged")
|
|
379
|
-
if systemd and state in ("inactive", "failed"):
|
|
390
|
+
if systemd and state in ("inactive", "failed", "unknown"):
|
|
380
391
|
unit = p["service"] + ".service"
|
|
381
|
-
if
|
|
392
|
+
if state in ("inactive", "failed") and (
|
|
393
|
+
_unit_property(unit, "MainPID") != "0" or _unit_property(unit, "ControlGroup")
|
|
394
|
+
):
|
|
382
395
|
raise RuntimeError("the systemd service still has processes; config left unchanged")
|
|
383
396
|
_require_own_fragment(unit, paths)
|
|
384
397
|
if state == "active" or pid is not None:
|
|
@@ -445,11 +458,32 @@ def act_install(p: remote_ops.InstallParams) -> None:
|
|
|
445
458
|
remote_ops.emit("result", **{k: paths[k] for k in keys})
|
|
446
459
|
|
|
447
460
|
|
|
461
|
+
def _has_service_record(paths: dict[str, str]) -> bool:
|
|
462
|
+
if not os.path.isfile(paths["spec"]):
|
|
463
|
+
return False
|
|
464
|
+
try:
|
|
465
|
+
record = json.loads(remote_ops._read(paths["spec"]))
|
|
466
|
+
except (OSError, ValueError):
|
|
467
|
+
return True # unreadable or malformed spec still fails closed
|
|
468
|
+
return not (isinstance(record, dict) and not record)
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
def _foreign_systemd_unit(unit: str, paths: dict[str, str]) -> bool:
|
|
472
|
+
if unit_runs_elsewhere(paths):
|
|
473
|
+
return True
|
|
474
|
+
code, fragment = remote_ops._systemctl("show", "-p", "FragmentPath", "--value", unit)
|
|
475
|
+
return bool(
|
|
476
|
+
code == 0 and fragment and Path(fragment).resolve() != Path(paths["unit"]).resolve()
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
|
|
448
480
|
def act_start(p: remote_ops.ServiceParams) -> None:
|
|
449
481
|
paths, unit = remote_ops._paths(p), p["service"] + ".service"
|
|
450
482
|
if remote_ops.receipts() and p["service_kind"] == "nohup":
|
|
451
483
|
process_identity.require_owned(paths["pid"])
|
|
452
484
|
systemd = p["service_kind"] == "systemd-user"
|
|
485
|
+
if systemd and unit_runs_elsewhere(paths):
|
|
486
|
+
raise RuntimeError(f"{_FOREIGN_UNIT}; not started")
|
|
453
487
|
running = (
|
|
454
488
|
remote_ops_launchd.status(p["deploy_dir"])[0] == "active"
|
|
455
489
|
if p["service_kind"] == "launchd-user"
|
|
@@ -457,13 +491,23 @@ def act_start(p: remote_ops.ServiceParams) -> None:
|
|
|
457
491
|
if systemd
|
|
458
492
|
else remote_ops._pid_alive(paths["pid"])
|
|
459
493
|
)
|
|
494
|
+
if (
|
|
495
|
+
not systemd
|
|
496
|
+
and p["service_kind"] != "launchd-user"
|
|
497
|
+
and running
|
|
498
|
+
and sys.platform.startswith("linux")
|
|
499
|
+
and _has_service_record(paths)
|
|
500
|
+
and not command_matches(int(running), _previous_install(p, paths)["argv"])
|
|
501
|
+
):
|
|
502
|
+
raise RuntimeError("the existing PID does not belong to this deployment; not started")
|
|
460
503
|
if not running and remote_ops._port_owner(p["port"]):
|
|
461
504
|
raise RuntimeError(f"port {p['port']} is held by another process")
|
|
462
505
|
if p["service_kind"] == "launchd-user":
|
|
463
506
|
remote_ops_launchd.start(p["deploy_dir"])
|
|
464
507
|
elif systemd:
|
|
465
|
-
|
|
466
|
-
|
|
508
|
+
_require_own_fragment(unit, paths)
|
|
509
|
+
if running and not os.path.isfile(paths["unit"]):
|
|
510
|
+
raise RuntimeError(f"{_FOREIGN_UNIT}; not started")
|
|
467
511
|
remote_ops._systemctl_ok("start", unit)
|
|
468
512
|
elif not running and sys.platform == "win32":
|
|
469
513
|
_start_windows(paths)
|
|
@@ -482,6 +526,35 @@ def act_start(p: remote_ops.ServiceParams) -> None:
|
|
|
482
526
|
remote_ops.emit("result", started=True)
|
|
483
527
|
|
|
484
528
|
|
|
529
|
+
def _stop_nohup_verified(p: remote_ops.ServiceParams, paths: dict[str, str]) -> None:
|
|
530
|
+
pid = remote_ops._pid_alive(paths["pid"])
|
|
531
|
+
state = _process_state(pid) if pid is not None else None
|
|
532
|
+
if pid is not None and state and not (state == "Z" and not _group_members(pid)):
|
|
533
|
+
_stop_owned_group(pid, _previous_install(p, paths)["argv"])
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
def _stop_nohup_signals(paths: dict[str, str]) -> None:
|
|
537
|
+
# SIGKILL what SIGTERM leaves running: whisper-server b5454 can hang on SIGTERM.
|
|
538
|
+
for sig in (signal.SIGTERM, signal.SIGKILL):
|
|
539
|
+
if sys.platform == "darwin":
|
|
540
|
+
process_identity.require_owned(paths["pid"])
|
|
541
|
+
pid, deadline = (
|
|
542
|
+
remote_ops._pid_alive(paths["pid"]),
|
|
543
|
+
time.monotonic() + remote_ops.STOP_GRACE_S,
|
|
544
|
+
)
|
|
545
|
+
if pid is not None:
|
|
546
|
+
try:
|
|
547
|
+
os.killpg(pid, sig)
|
|
548
|
+
except ProcessLookupError: # it exited after the check: stopped, as wanted
|
|
549
|
+
pid = None
|
|
550
|
+
while (
|
|
551
|
+
pid is not None and remote_ops._pid_alive(paths["pid"]) and time.monotonic() < deadline
|
|
552
|
+
):
|
|
553
|
+
time.sleep(0.2)
|
|
554
|
+
if remote_ops._pid_alive(paths["pid"]):
|
|
555
|
+
raise RuntimeError("the service process is still running after SIGKILL")
|
|
556
|
+
|
|
557
|
+
|
|
485
558
|
def act_stop(p: remote_ops.ServiceParams) -> None:
|
|
486
559
|
paths = remote_ops._paths(p)
|
|
487
560
|
if remote_ops.receipts() and p["service_kind"] == "nohup":
|
|
@@ -502,28 +575,10 @@ def act_stop(p: remote_ops.ServiceParams) -> None:
|
|
|
502
575
|
pass
|
|
503
576
|
elif remote_ops._systemctl("stop", unit)[0]:
|
|
504
577
|
raise RuntimeError("systemctl could not stop the service")
|
|
578
|
+
elif sys.platform.startswith("linux") and _has_service_record(paths):
|
|
579
|
+
_stop_nohup_verified(p, paths)
|
|
505
580
|
else:
|
|
506
|
-
|
|
507
|
-
for sig in (signal.SIGTERM, signal.SIGKILL):
|
|
508
|
-
if sys.platform == "darwin":
|
|
509
|
-
process_identity.require_owned(paths["pid"])
|
|
510
|
-
pid, deadline = (
|
|
511
|
-
remote_ops._pid_alive(paths["pid"]),
|
|
512
|
-
time.monotonic() + remote_ops.STOP_GRACE_S,
|
|
513
|
-
)
|
|
514
|
-
if pid is not None:
|
|
515
|
-
try:
|
|
516
|
-
os.killpg(pid, sig)
|
|
517
|
-
except ProcessLookupError: # it exited after the check: stopped, as wanted
|
|
518
|
-
pid = None
|
|
519
|
-
while (
|
|
520
|
-
pid is not None
|
|
521
|
-
and remote_ops._pid_alive(paths["pid"])
|
|
522
|
-
and time.monotonic() < deadline
|
|
523
|
-
):
|
|
524
|
-
time.sleep(0.2)
|
|
525
|
-
if remote_ops._pid_alive(paths["pid"]):
|
|
526
|
-
raise RuntimeError("the service process is still running after SIGKILL")
|
|
581
|
+
_stop_nohup_signals(paths)
|
|
527
582
|
remote_ops.emit("result", stopped=True)
|
|
528
583
|
|
|
529
584
|
|
|
@@ -652,11 +707,13 @@ def act_status(p: remote_ops.ServiceParams) -> None:
|
|
|
652
707
|
if p["service_kind"] == "launchd-user":
|
|
653
708
|
state, pid = remote_ops_launchd.status(p["deploy_dir"])
|
|
654
709
|
elif p["service_kind"] == "systemd-user":
|
|
655
|
-
|
|
710
|
+
unit = p["service"] + ".service"
|
|
711
|
+
if _foreign_systemd_unit(unit, paths):
|
|
712
|
+
remote_ops.emit("result", state="inactive", health=f"{_FOREIGN_UNIT}, not probed")
|
|
713
|
+
return
|
|
714
|
+
_, state = remote_ops._systemctl("is-active", unit)
|
|
656
715
|
if state == "active":
|
|
657
|
-
_, number = remote_ops._systemctl(
|
|
658
|
-
"show", "-p", "MainPID", "--value", p["service"] + ".service"
|
|
659
|
-
)
|
|
716
|
+
_, number = remote_ops._systemctl("show", "-p", "MainPID", "--value", unit)
|
|
660
717
|
pid = int(number) if number.isdigit() and int(number) > 0 else None
|
|
661
718
|
elif remote_ops.receipts():
|
|
662
719
|
state, pid = process_identity.status(paths["pid"])
|
|
@@ -28,6 +28,7 @@ from localmodels.runtime_io import (
|
|
|
28
28
|
)
|
|
29
29
|
|
|
30
30
|
MAX_CONTEXT_WINDOW = 2_147_483_647
|
|
31
|
+
_USER_AGENT = "localmodels-auth"
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
def model_config(profile: Path, owned: dict[str, str]) -> dict[str, Any] | None:
|
|
@@ -292,6 +293,7 @@ def _verify_config(value: dict[str, Any]) -> None:
|
|
|
292
293
|
else:
|
|
293
294
|
url, data = "https://api.anthropic.com/v1/models", None
|
|
294
295
|
headers = {"x-api-key": key, "anthropic-version": "2023-06-01"}
|
|
296
|
+
headers["User-Agent"] = _USER_AGENT
|
|
295
297
|
try:
|
|
296
298
|
request = urllib.request.Request(url, data=data, headers=headers)
|
|
297
299
|
with urllib.request.build_opener(http_local.NoRedirectHandler()).open(
|
|
@@ -380,7 +382,8 @@ def _endpoint_metadata(value: dict[str, Any]) -> tuple[int, bool]:
|
|
|
380
382
|
for url in (base.removesuffix("/v1") + "/props", base + "/models"):
|
|
381
383
|
try:
|
|
382
384
|
request = urllib.request.Request(
|
|
383
|
-
url,
|
|
385
|
+
url,
|
|
386
|
+
headers={"Authorization": "Bearer " + value["apiKey"], "User-Agent": _USER_AGENT},
|
|
384
387
|
)
|
|
385
388
|
with opener.open(request, timeout=5) as response:
|
|
386
389
|
if response.status != 200:
|