feat: atxpi — server power & console manager (core, CLI, deploy)

- core/hardware: драйверы real (atxctl/pyserial) + mock, ATXPI_DRIVER
- core/power, console, mock: операции питания и RS232-консоли
- cli/atxpi: status/on/off/reset/cycle/console (stdlib, без deps)
- install.sh: one-shot curl|bash, идемпотентный, хост-агностичный
- deploy: systemd-юнит, шаблон env, update.sh
- README, AGENTS.md: документация и проектные решения
- AGENTS.md и доки очищены от внутренних хостов/адресов (публичный репо)
This commit is contained in:
toros
2026-09-08 21:54:11 +05:00
parent 135b091567
commit 12e6a453de
14 changed files with 657 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
"""atxpi CLI: управление питанием и консолью сервера.
Примеры:
atxpi status
atxpi on | off | reset | cycle
atxpi console --cmd "uptime" --read # скриптовый обмен
atxpi console --read # просто прочитать буфер
"""
import argparse
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..")))
from atxpi.core import power as power_mod
from atxpi.core import console as console_mod
def main() -> int:
ap = argparse.ArgumentParser(prog="atxpi", description=__doc__)
sub = ap.add_subparsers(dest="action", required=True)
sub.add_parser("status", help="текущее состояние питания")
sub.add_parser("on", help="нажать кнопку питания (вкл/выкл)")
sub.add_parser("off", help="принудительное выключение (длинное нажатие)")
sub.add_parser("reset", help="аппаратный сброс")
sub.add_parser("cycle", help="жёсткий перезапуск (выкл, пауза, вкл)")
con = sub.add_parser("console", help="работа с RS232-консолью")
con.add_argument("--cmd", help="отправить строку в консоль")
con.add_argument("--read", action="store_true", help="прочитать и вывести буфер")
args = ap.parse_args()
try:
if args.action == "status":
print(_fmt(power_mod.status()))
elif args.action == "on":
print(_fmt(power_mod.press_power()))
elif args.action == "off":
print(_fmt(power_mod.force_off()))
elif args.action == "reset":
print(_fmt(power_mod.press_reset()))
elif args.action == "cycle":
print(_fmt(power_mod.cycle()))
elif args.action == "console":
if args.cmd:
print(_fmt(console_mod.send(args.cmd)))
if args.read or args.cmd:
print(_fmt(console_mod.read_bytes()))
return 0
except Exception as e:
print(f"atxpi: ошибка: {e}", file=sys.stderr)
return 1
def _fmt(d: dict) -> str:
return " ".join(f"{k}={v}" for k, v in d.items())
if __name__ == "__main__":
sys.exit(main())