Fix Classic bot login, native commands and unattended activity
Core tests / core (push) Successful in 26s
Core tests / core (push) Successful in 26s
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Install isolated, restartable Classic dashboard/relay/autonomy user services.
|
||||
|
||||
Prepare staging state first and stop any manually started staging processes.
|
||||
This does not enable game login, start authentication, or change live services.
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
|
||||
|
||||
def main(root):
|
||||
app = root / 'app-staging'
|
||||
node = pathlib.Path.home() / '.local/bin/node'
|
||||
for path in [node, app / '.dev.vars', root / 'adapter/relay.py']:
|
||||
if not path.is_file():
|
||||
raise RuntimeError('Missing prerequisite: ' + str(path))
|
||||
if any(c in str(root) for c in [' ', '\n', '"', "'", '%']):
|
||||
raise RuntimeError('Use a simple absolute staging path')
|
||||
values = {}
|
||||
for line in (app / '.dev.vars').read_text().splitlines():
|
||||
if '=' in line and not line.lstrip().startswith('#'):
|
||||
key, value = line.split('=', 1)
|
||||
values[key.strip()] = value.strip().strip('"\'')
|
||||
token = values['AUTONOMY_TOKEN']
|
||||
if not token or any(c in token for c in ['\n', '\r', '"', '\\']):
|
||||
raise RuntimeError('Invalid autonomy token format')
|
||||
environment = root / 'staging-worker.env'
|
||||
fd = os.open(environment, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
|
||||
with os.fdopen(fd, 'w') as out:
|
||||
out.write('AUTONOMY_TOKEN="' + token + '"\nAZEROTHAI_URL=http://127.0.0.1:8791\n')
|
||||
environment.chmod(0o600)
|
||||
units = pathlib.Path.home() / '.config/systemd/user'
|
||||
units.mkdir(parents=True, exist_ok=True)
|
||||
commands = {
|
||||
'runtime': (f'{node} {app}/scripts/start-local-runtime.mjs', 'Environment=RUNTIME_PORT=8791 RUNTIME_HOST=127.0.0.1\n'),
|
||||
'relay': (f'/usr/bin/sg docker -c "/usr/bin/python3 {root}/adapter/relay.py --root {root} --url http://127.0.0.1:8791 --env-file {app}/.dev.vars"', ''),
|
||||
'autonomy': (f'{node} {app}/scripts/autonomy-worker.mjs', f'EnvironmentFile={environment}\n'),
|
||||
}
|
||||
names = []
|
||||
for kind, (command, extra) in commands.items():
|
||||
name = f'azerothai-classic-{kind}.service'
|
||||
names.append(name)
|
||||
after = 'network.target' if kind == 'runtime' else 'azerothai-classic-runtime.service'
|
||||
(units / name).write_text(f'''[Unit]
|
||||
Description=AzerothAI Classic staging {kind}
|
||||
After={after}
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory={app}
|
||||
Environment=PATH={node.parent}:/usr/local/bin:/usr/bin:/bin
|
||||
{extra}ExecStart={command}
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
TimeoutStopSec=20
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
''')
|
||||
subprocess.run(['systemctl', '--user', 'daemon-reload'], check=True)
|
||||
subprocess.run(['systemctl', '--user', 'enable', '--now', *names], check=True)
|
||||
subprocess.run(['systemctl', '--user', 'is-active', *names], check=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--root', type=pathlib.Path, required=True)
|
||||
main(parser.parse_args().root.resolve())
|
||||
Reference in New Issue
Block a user