# systemd unit for AWOOOI auto-startup on reboot
# 2026-04-04 ogt: 根據實際重開機事故建立
#
# 部署方式 (on 192.168.0.188):
#   sudo cp awoooi-startup.sh /usr/local/bin/awoooi-startup.sh
#   sudo chmod +x /usr/local/bin/awoooi-startup.sh
#   sudo cp awoooi-startup.service /etc/systemd/system/awoooi-startup.service
#   sudo systemctl daemon-reload
#   sudo systemctl enable awoooi-startup.service

[Unit]
Description=AWOOOI Auto-Startup Recovery Sequence
# 在 network 就緒後才執行
After=network-online.target containerd.service docker.service
Wants=network-online.target

# 確保 PostgreSQL 盡早嘗試啟動
Wants=postgresql@14-main.service redis-server.service ollama.service nginx.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/awoooi-startup.sh
# 允許較長的啟動時間（修復流程可能需要時間）
TimeoutStartSec=300
StandardOutput=journal
StandardError=journal

# 以 root 執行（需要 systemctl 操作）
User=root

[Install]
WantedBy=multi-user.target
