Files
karung-counting-feedmill-se…/deploy_to_jetson.py
T

70 lines
2.5 KiB
Python

import paramiko
import os
# Production loads .engine weights from models/ (see models/README.md).
# .pt/.onnx stay local-only (dev/export) — not synced to save bandwidth.
MODEL_ENGINES = [
"v4-best.engine",
"yolo11n-bbox-100ep-sack+box-20260909-best.engine",
"best.engine",
"truck-detector.engine",
"model_karung_truk.engine",
]
files_to_sync = [
("templates/operator.html", "/home/jetson/karung/templates/operator.html"),
("templates/monitoring.html", "/home/jetson/karung/templates/monitoring.html"),
("templates/base.html", "/home/jetson/karung/templates/base.html"),
("counter_dashboard.py", "/home/jetson/karung/counter_dashboard.py"),
("predict.py", "/home/jetson/karung/predict.py"),
(".env", "/home/jetson/karung/.env"),
] + [
(f"models/{f}", f"/home/jetson/karung/models/{f}") for f in MODEL_ENGINES
]
def run():
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('192.168.192.96', username='jetson', password='jetson', timeout=10)
sftp = client.open_sftp()
# Ensure remote models/ dir exists (sftp.put fails otherwise)
try:
sftp.stat("/home/jetson/karung/models")
except FileNotFoundError:
print("Creating remote /home/jetson/karung/models/ ...")
sftp.mkdir("/home/jetson/karung/models")
print("Uploading updated files to Jetson...")
for local_f, remote_f in files_to_sync:
if not os.path.exists(local_f):
print(f"SKIP (missing local file): {local_f}")
continue
print(f"Uploading {local_f} -> {remote_f}")
sftp.put(local_f, remote_f)
sftp.close()
print("All files uploaded successfully!")
print("Restarting services on Jetson...")
cmd = "echo jetson | sudo -S systemctl restart karung-counter karung-counter-dashboard"
stdin, stdout, stderr = client.exec_command(cmd)
print("STDOUT:", stdout.read().decode('utf-8', errors='ignore'))
print("STDERR:", stderr.read().decode('utf-8', errors='ignore'))
# Check status
stdin, stdout, stderr = client.exec_command("systemctl status karung-counter-dashboard karung-counter --no-pager")
print("=== SERVICE STATUS ===")
print(stdout.read().decode('utf-8', errors='ignore').encode('ascii', errors='ignore').decode())
# Check listening ports
stdin, stdout, stderr = client.exec_command("netstat -tuln | grep -E '5000|5721'")
print("=== LISTENING PORTS ===")
print(stdout.read().decode('utf-8', errors='ignore'))
client.close()
if __name__ == '__main__':
run()