#!/bin/bash # {{ ansible_managed }} # Remote power control for truenas.localdomain via the R415 iDRAC6. # Usage: truenas-power.sh {status|on|soft|off|cycle} set -euo pipefail PW_FILE=/etc/ups/idrac.pw if [ ! -r "$PW_FILE" ]; then echo "cannot read $PW_FILE" >&2 exit 1 fi # -f keeps the password out of the process argument list. ipmi() { ipmitool -I lanplus -H {{ idrac_host }} -U {{ idrac_user }} \ -f "$PW_FILE" "$@" } case "${1:-status}" in status) ipmi chassis power status ;; on) ipmi chassis power on ;; # ACPI soft-off. FreeBSD has hw.acpi.power_button_state=S5, so this is # a clean TrueNAS shutdown. Normally unused: TrueNAS shuts itself down # as a NUT slave. This is the manual escape hatch. soft) ipmi chassis power soft ;; # Hard cut, last resort only. off) ipmi chassis power off ;; cycle) ipmi chassis power cycle ;; *) echo "usage: $0 {status|on|soft|off|cycle}" >&2 exit 2 ;; esac