ominfra 0.0.0.dev132__py3-none-any.whl → 0.0.0.dev134__py3-none-any.whl
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.
- ominfra/{deploy → manage/deploy}/_executor.py +10 -10
- ominfra/{deploy → manage/deploy}/poly/_main.py +6 -6
- ominfra/{deploy → manage/deploy}/remote.py +1 -1
- ominfra/pyremote.py +389 -0
- ominfra/scripts/supervisor.py +1 -1
- ominfra/supervisor/http.py +1 -1
- {ominfra-0.0.0.dev132.dist-info → ominfra-0.0.0.dev134.dist-info}/METADATA +3 -3
- {ominfra-0.0.0.dev132.dist-info → ominfra-0.0.0.dev134.dist-info}/RECORD +36 -39
- ominfra/pyremote/__init__.py +0 -0
- ominfra/pyremote/_runcommands.py +0 -1201
- ominfra/pyremote/bootstrap.py +0 -149
- ominfra/pyremote/runcommands.py +0 -56
- /ominfra/{deploy → manage/deploy}/__init__.py +0 -0
- /ominfra/{deploy → manage/deploy}/configs.py +0 -0
- /ominfra/{deploy → manage/deploy}/executor/__init__.py +0 -0
- /ominfra/{deploy → manage/deploy}/executor/base.py +0 -0
- /ominfra/{deploy → manage/deploy}/executor/concerns/__init__.py +0 -0
- /ominfra/{deploy → manage/deploy}/executor/concerns/dirs.py +0 -0
- /ominfra/{deploy → manage/deploy}/executor/concerns/nginx.py +0 -0
- /ominfra/{deploy → manage/deploy}/executor/concerns/repo.py +0 -0
- /ominfra/{deploy → manage/deploy}/executor/concerns/supervisor.py +0 -0
- /ominfra/{deploy → manage/deploy}/executor/concerns/systemd.py +0 -0
- /ominfra/{deploy → manage/deploy}/executor/concerns/user.py +0 -0
- /ominfra/{deploy → manage/deploy}/executor/concerns/venv.py +0 -0
- /ominfra/{deploy → manage/deploy}/executor/main.py +0 -0
- /ominfra/{deploy → manage/deploy}/poly/__init__.py +0 -0
- /ominfra/{deploy → manage/deploy}/poly/base.py +0 -0
- /ominfra/{deploy → manage/deploy}/poly/configs.py +0 -0
- /ominfra/{deploy → manage/deploy}/poly/deploy.py +0 -0
- /ominfra/{deploy → manage/deploy}/poly/main.py +0 -0
- /ominfra/{deploy → manage/deploy}/poly/nginx.py +0 -0
- /ominfra/{deploy → manage/deploy}/poly/repo.py +0 -0
- /ominfra/{deploy → manage/deploy}/poly/runtime.py +0 -0
- /ominfra/{deploy → manage/deploy}/poly/site.py +0 -0
- /ominfra/{deploy → manage/deploy}/poly/supervisor.py +0 -0
- /ominfra/{deploy → manage/deploy}/poly/venv.py +0 -0
- {ominfra-0.0.0.dev132.dist-info → ominfra-0.0.0.dev134.dist-info}/LICENSE +0 -0
- {ominfra-0.0.0.dev132.dist-info → ominfra-0.0.0.dev134.dist-info}/WHEEL +0 -0
- {ominfra-0.0.0.dev132.dist-info → ominfra-0.0.0.dev134.dist-info}/entry_points.txt +0 -0
- {ominfra-0.0.0.dev132.dist-info → ominfra-0.0.0.dev134.dist-info}/top_level.txt +0 -0
ominfra/pyremote/bootstrap.py
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Basically this: https://mitogen.networkgenomics.com/howitworks.html
|
3
|
-
"""
|
4
|
-
import base64
|
5
|
-
import inspect
|
6
|
-
import os
|
7
|
-
import sys
|
8
|
-
import textwrap
|
9
|
-
import typing as ta
|
10
|
-
import zlib
|
11
|
-
|
12
|
-
|
13
|
-
##
|
14
|
-
|
15
|
-
|
16
|
-
_BOOTSTRAP_COMM_FD = 100
|
17
|
-
_BOOTSTRAP_SRC_FD = 101
|
18
|
-
|
19
|
-
_BOOTSTRAP_CHILD_PID_VAR = '_OPYR_CPID'
|
20
|
-
_BOOTSTRAP_ARGV0_VAR = '_OPYR_ARGV0'
|
21
|
-
|
22
|
-
BOOTSTRAP_ACK0 = b'OPYR000\n'
|
23
|
-
BOOTSTRAP_ACK1 = b'OPYR001\n'
|
24
|
-
|
25
|
-
_BOOTSTRAP_PROC_TITLE_FMT = '(pyremote:%s)'
|
26
|
-
|
27
|
-
_BOOTSTRAP_IMPORTS = [
|
28
|
-
'base64',
|
29
|
-
'os',
|
30
|
-
'sys',
|
31
|
-
'zlib',
|
32
|
-
]
|
33
|
-
|
34
|
-
|
35
|
-
def _bootstrap_main(context_name: str, main_z_len: int) -> None:
|
36
|
-
# Two copies of main src to be sent to parent
|
37
|
-
r0, w0 = os.pipe()
|
38
|
-
r1, w1 = os.pipe()
|
39
|
-
|
40
|
-
if (cp := os.fork()):
|
41
|
-
# Parent process
|
42
|
-
|
43
|
-
# Dup original stdin to comm_fd for use as comm channel
|
44
|
-
os.dup2(0, _BOOTSTRAP_COMM_FD)
|
45
|
-
|
46
|
-
# Overwrite stdin (fed to python repl) with first copy of src
|
47
|
-
os.dup2(r0, 0)
|
48
|
-
|
49
|
-
# Dup second copy of src to src_fd to recover after launch
|
50
|
-
os.dup2(r1, _BOOTSTRAP_SRC_FD)
|
51
|
-
|
52
|
-
# Close remaining fd's
|
53
|
-
for f in [r0, w0, r1, w1]:
|
54
|
-
os.close(f)
|
55
|
-
|
56
|
-
# Save child pid to close after relaunch
|
57
|
-
os.environ[_BOOTSTRAP_CHILD_PID_VAR] = str(cp)
|
58
|
-
|
59
|
-
# Save original argv0
|
60
|
-
os.environ[_BOOTSTRAP_ARGV0_VAR] = sys.executable
|
61
|
-
|
62
|
-
# Start repl reading stdin from r0
|
63
|
-
os.execl(sys.executable, sys.executable + (_BOOTSTRAP_PROC_TITLE_FMT % (context_name,)))
|
64
|
-
|
65
|
-
else:
|
66
|
-
# Child process
|
67
|
-
|
68
|
-
# Write first ack
|
69
|
-
os.write(1, BOOTSTRAP_ACK0)
|
70
|
-
|
71
|
-
# Read main src from stdin
|
72
|
-
main_src = zlib.decompress(os.fdopen(0, 'rb').read(main_z_len))
|
73
|
-
|
74
|
-
# Write both copies of main src
|
75
|
-
for w in [w0, w1]:
|
76
|
-
fp = os.fdopen(w, 'wb', 0)
|
77
|
-
fp.write(main_src)
|
78
|
-
fp.close()
|
79
|
-
|
80
|
-
# Write second ack
|
81
|
-
os.write(1, BOOTSTRAP_ACK1)
|
82
|
-
|
83
|
-
sys.exit(0)
|
84
|
-
|
85
|
-
|
86
|
-
#
|
87
|
-
|
88
|
-
|
89
|
-
def bootstrap_payload(context_name: str, main_z_len: int) -> str:
|
90
|
-
bs_src = textwrap.dedent(inspect.getsource(_bootstrap_main))
|
91
|
-
|
92
|
-
for gl in [
|
93
|
-
'_BOOTSTRAP_COMM_FD',
|
94
|
-
'_BOOTSTRAP_SRC_FD',
|
95
|
-
|
96
|
-
'_BOOTSTRAP_CHILD_PID_VAR',
|
97
|
-
'_BOOTSTRAP_ARGV0_VAR',
|
98
|
-
|
99
|
-
'BOOTSTRAP_ACK0',
|
100
|
-
'BOOTSTRAP_ACK1',
|
101
|
-
|
102
|
-
'_BOOTSTRAP_PROC_TITLE_FMT',
|
103
|
-
]:
|
104
|
-
bs_src = bs_src.replace(gl, repr(globals()[gl]))
|
105
|
-
|
106
|
-
bs_src = '\n'.join(
|
107
|
-
cl
|
108
|
-
for l in bs_src.splitlines()
|
109
|
-
if (cl := (l.split('#')[0]).rstrip())
|
110
|
-
if cl.strip()
|
111
|
-
)
|
112
|
-
|
113
|
-
bs_z = zlib.compress(bs_src.encode('utf-8'))
|
114
|
-
bs_z64 = base64.encodebytes(bs_z).replace(b'\n', b'')
|
115
|
-
|
116
|
-
stmts = [
|
117
|
-
f'import {", ".join(_BOOTSTRAP_IMPORTS)}',
|
118
|
-
f'exec(zlib.decompress(base64.decodebytes({bs_z64!r})))',
|
119
|
-
f'_bootstrap_main({context_name!r}, {main_z_len})',
|
120
|
-
]
|
121
|
-
|
122
|
-
cmd = '; '.join(stmts)
|
123
|
-
return cmd
|
124
|
-
|
125
|
-
|
126
|
-
#
|
127
|
-
|
128
|
-
|
129
|
-
class PostBoostrap(ta.NamedTuple):
|
130
|
-
input: ta.BinaryIO
|
131
|
-
main_src: str
|
132
|
-
|
133
|
-
|
134
|
-
def post_boostrap() -> PostBoostrap:
|
135
|
-
# Restore original argv0
|
136
|
-
sys.executable = os.environ.pop(_BOOTSTRAP_ARGV0_VAR)
|
137
|
-
|
138
|
-
# Reap boostrap child
|
139
|
-
os.waitpid(int(os.environ.pop(_BOOTSTRAP_CHILD_PID_VAR)), 0)
|
140
|
-
|
141
|
-
# Read second copy of main src
|
142
|
-
r1 = os.fdopen(_BOOTSTRAP_SRC_FD, 'rb', 0)
|
143
|
-
main_src = r1.read().decode('utf-8')
|
144
|
-
r1.close()
|
145
|
-
|
146
|
-
return PostBoostrap(
|
147
|
-
input=os.fdopen(_BOOTSTRAP_COMM_FD, 'rb', 0),
|
148
|
-
main_src=main_src,
|
149
|
-
)
|
ominfra/pyremote/runcommands.py
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
# @omlish-amalg ./_runcommands.py
|
3
|
-
# ruff: noqa: UP006 UP007
|
4
|
-
import dataclasses as dc
|
5
|
-
import io
|
6
|
-
import json
|
7
|
-
import subprocess
|
8
|
-
import sys
|
9
|
-
import typing as ta
|
10
|
-
|
11
|
-
from omlish.lite.json import json_dumps_compact
|
12
|
-
from omlish.lite.marshal import marshal_obj
|
13
|
-
from omlish.lite.marshal import unmarshal_obj
|
14
|
-
from omlish.lite.subprocesses import subprocess_maybe_shell_wrap_exec
|
15
|
-
|
16
|
-
from .bootstrap import post_boostrap
|
17
|
-
|
18
|
-
|
19
|
-
@dc.dataclass(frozen=True)
|
20
|
-
class CommandRequest:
|
21
|
-
cmd: ta.Sequence[str]
|
22
|
-
in_: ta.Optional[bytes] = None
|
23
|
-
|
24
|
-
|
25
|
-
@dc.dataclass(frozen=True)
|
26
|
-
class CommandResponse:
|
27
|
-
req: CommandRequest
|
28
|
-
rc: int
|
29
|
-
out: bytes
|
30
|
-
err: bytes
|
31
|
-
|
32
|
-
|
33
|
-
def _run_commands_loop(input: ta.BinaryIO, output: ta.BinaryIO = sys.stdout.buffer) -> None: # noqa
|
34
|
-
while (l := input.readline().decode('utf-8').strip()):
|
35
|
-
req: CommandRequest = unmarshal_obj(json.loads(l), CommandRequest)
|
36
|
-
proc = subprocess.Popen( # type: ignore
|
37
|
-
subprocess_maybe_shell_wrap_exec(*req.cmd),
|
38
|
-
**(dict(stdin=io.BytesIO(req.in_)) if req.in_ is not None else {}),
|
39
|
-
stdout=subprocess.PIPE,
|
40
|
-
stderr=subprocess.PIPE,
|
41
|
-
)
|
42
|
-
out, err = proc.communicate()
|
43
|
-
resp = CommandResponse(
|
44
|
-
req=req,
|
45
|
-
rc=proc.returncode,
|
46
|
-
out=out, # noqa
|
47
|
-
err=err, # noqa
|
48
|
-
)
|
49
|
-
output.write(json_dumps_compact(marshal_obj(resp)).encode('utf-8'))
|
50
|
-
output.write(b'\n')
|
51
|
-
output.flush()
|
52
|
-
|
53
|
-
|
54
|
-
def run_commands_main() -> None:
|
55
|
-
bs = post_boostrap()
|
56
|
-
_run_commands_loop(bs.input)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|