"""NASのDockerコンテナをパスワード認証で再起動するスクリプト"""
import paramiko

HOST = "192.168.0.61"
USER = "root"
PASS = "59911784"
CMD  = "cd /volume1/docker/njts-accounting && docker compose restart backend"

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(HOST, username=USER, password=PASS, timeout=30)

print(f"接続成功: {HOST}")
stdin, stdout, stderr = client.exec_command(CMD, timeout=60)

out = stdout.read().decode()
err = stderr.read().decode()
code = stdout.channel.recv_exit_status()

if out: print("stdout:", out)
if err: print("stderr:", err)
print("exit code:", code)
client.close()
