BY35SはUSB-HID規格でないためmacOSのUPS連携ができない→NUTでなんとかできる?→諦めた
基素.iconmacOSはUPSとの連携機能がない
o3.iconあります。macOS は HID 対応(USB ケーブルでつなぐとキーボードのように認識するタイプ)の UPS なら標準で監視できます。
Apple Silicon/Ventura 以降
システム設定 → 一般 → 電源 → 右下「UPSオプション…」
※見当たらない場合は UPS が HID 非対応か、USB が刺さっていない
USBさすと出るのか基素.icon
o3.iconBY50S は USB-HID 規格ではなく専用プロトコル機器。macOS が標準で監視できるのは HID-UPS だけなので、USB を挿しても「UPS オプション」が出ないのは正常な挙動です。
手順(Apple Silicon/最新 macOS 可)
1. brew install nut
2. /usr/local/etc/nut/ups.conf を新規作成
code:conf
driver = blazer_usb
port = auto
vendorid = 2109
productid = 0813 # うまく行かなければ 2813 に変えて試す
subdriver = ippon # BY50S/BY35S で実績あり
OMRONの多くのUSB接続UPSは blazer_usb ドライバで動作しますGemini 2.5 Pro.icon
3. upsmon.conf に MONITOR by50s@localhost 1 nut nut slave を追加
Gemini 2.5 Pro.icon
code:toml
# MONITOR <system> <powervalue> <username> <password> <type>
MONITOR by35s@localhost 1 upsmon_master your_secure_password master
# SHUTDOWNCMD <command>
SHUTDOWNCMD "/sbin/shutdown -h +0"
パスワードはupsd.usersで設定
masterなのかslaveなのか?基素.icon
4. brew services start nut で常駐
5. /usr/local/etc/nut/upssched.conf で残量◯%時に shutdown -h now を呼ばせる
これで NUT が残量監視→pmset 経由で安全終了します(macOS側の設定画面は出ない)。
USBを接続すると
code:zsh
ioreg -p IOUSB -l -n BY35S | grep -E 'idVendor|idProduct'
| | "idProduct" = 2067
| | "idVendor" = 8457
| | "idProduct" = 10259
| | "idVendor" = 8457
| "idProduct" = 128
| "idVendor" = 1424
Step 4: 自動起動の設定
Macを再起動した際に、自動でNUTが起動するようにlaunchdサービスとして登録します。brew servicesは権限の問題でUPS監視には不向きなため、手動で設定ファイルを作成します。
upsd用
$ sudo nano /Library/LaunchDaemons/org.nut.upsd.plist
code:xml
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.nut.upsd</string>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/sbin/upsd</string>
<string>-F</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>UserName</key>
<string>root</string>
</dict>
</plist>
upsmon用
$ sudo nano /Library/LaunchDaemons/org.nut.upsmon.plist
code:xml
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.nut.upsmon</string>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/sbin/upsmon</string>
<string>-D</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>UserName</key>
<string>root</string>
</dict>
</plist>
サービスをlaunchdに登録、起動
code:bash
sudo launchctl load -w /Library/LaunchDaemons/org.nut.upsd.plist
sudo launchctl load -w /Library/LaunchDaemons/org.nut.upsmon.plist
実践
Home brewのインストール
$ brew install nut
したらこんなメッセージが出てきた。上の設定をしなくてもbrew services start nutでいけるのかな?
code:zsh
To start nut now and restart at login:
brew services start nut
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/nut/sbin/upsmon -D
o3.icon
brew services start nut だけでは Step 4(常駐化)を完結できません。
Homebrew の service 定義は upsmon しか起動しないため、
ドライバ (upsdrvctl start) と upsd がブート時に走りません。
そのままでは upsmon が UPS と通信できず、意図した「抜けたら即シャットダウン」が発火しません。
GitHub での指摘「nut formula はクライアント用途(upsmon のみ)で、ドライバと upsd は自前で起動が必要」
基素.icon半日潰したけどうまくいかなかった
再起動はするが、upscでドライバに接続できない
code:zsh
sudo /opt/homebrew/sbin/upsd
Network UPS Tools upsd 2.8.2
fopen /opt/homebrew/var/state/ups/upsd.pid: No such file or directory
Could not find PID file '/opt/homebrew/var/state/ups/upsd.pid' to see if previous upsd instance is already running!
listening on ::1 port 3493
listening on 127.0.0.1 port 3493
Can't connect to UPS by35s (blazer_usb-by35s): Connection refused Found 1 UPS defined in ups.conf
Can't open /opt/homebrew/etc/nut/upsd.users: Permission denied
パーミッションは見直した
:nobodyにしろ派とroot:wheelにしろ派のLLMがいた
エラーメッセージ的にはパーミッションと明言されていないが、その可能性も考慮
粘ればできそうな気がするが、時間がもったいない&買い替えても良いので諦めてHID対応モデルを購入
以下のコマンドで動かそうとした
/opt/homebrew/sbin/upsdrvctl start
UPSハードウェアと通信するためのドライバ群を起動
upsdrvctl はラッパーであって、実際のドライバーではない
sudo upsdrvctl start by35s を実行すると、まず内部で/opt/homebrew/Cellar/nut/2.8.2/bin/blazer_usb -a by35s を起動し
その後ラッパー自身は終了してプロンプトに戻る
/opt/homebrew/sbin/upsd
ドライバから受け取った情報をネットワーク経由でUPSの状態を提供するサーバ
/opt/homebrew/sbin/upsmon -D
状態監視するクライアントを起動
設定ファイル
code:zsh
sudo tee /opt/homebrew/etc/nut/ups.conf <<'EOF'
driver = blazer_usb
subdriver = ippon
port = auto
user = root
group = nobody ; ★ドライバと ups(d|mon) が共有
vendorid = 0590 # 0x0590 = 1424 OMRON
productid = 0080 # 0x0080 = 128 BY35S
desc = "Omron BY35S UPS"
EOF
gorupとuserは指定しなくても良いという情報もあった
subdriverはipponを指定しないとだめそうだった
code:zsh
sudo tee /opt/homebrew/etc/nut/upsd.conf <<'EOF'
# どのポートで待ち受けるかは nut.conf の LISTEN 行を使うので
# ここは空で OK。コメント 1 行でもファイルがあれば upsd は起動する。
EOF
シャットダウン用スクリプト
code:zsh
sudo tee /opt/homebrew/etc/nut/notify.sh <<'EOF'
case "$NOTIFYTYPE" in
ONBATT|LOWBATT|COMMBAD|NOCOMM)
logger "NUT: $NOTIFYTYPE -> shutting down"
/sbin/shutdown -h now
;;
*) logger "NUT: $NOTIFYTYPE";;
esac
EOF
sudo chmod +x /opt/homebrew/etc/nut/notify.sh
upsmon が 2 つ立ち上がった
pidも消したしプロセスも落としたのになぜ?
o3.iconは異常だと言ったり正常だと言ったりブレた
code:zsh
% ps ax | egrep 'ups(drvctl|d|mon)' | grep -v egrep
317 ?? Ss 0:00.01 /bin/sh -c \012 /opt/homebrew/sbin/upsdrvctl start &&\012 /opt/homebrew/sbin/upsd &&\012 /opt/homebrew/sbin/upsmon -D\012
362 ?? Ss 0:00.01 /opt/homebrew/sbin/upsd
363 ?? S 0:00.01 /opt/homebrew/sbin/upsmon -D
367 ?? S 0:00.01 /opt/homebrew/sbin/upsmon -D
動作確認
code:zsh
sudo $(brew --prefix nut)/bin/blazer_usb -a by35s -DDD
# → Battery capacity … が流れれば Ctrl-C で抜ける
ここで失敗する
軌道の自動化
code:zsh
# 1. ひな形をコピー
sudo cp /opt/homebrew/opt/nut/homebrew.mxcl.nut.plist \
/Library/LaunchDaemons/org.nut.full.plist
# 2. plist を編集(root で開ける好きなエディタで)
sudo vi /Library/LaunchDaemons/org.nut.full.plist
code:xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
<plist version="1.0">
<dict>
<key>Label</key><string>org.nut.full</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>
/opt/homebrew/sbin/upsdrvctl start &&
/opt/homebrew/sbin/upsd &&
/opt/homebrew/sbin/upsmon -D
</string>
</array>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
</dict>
</plist>
code:zsh
# 3. 読み込んで自動起動
# 先にストップしておく。どうせ失敗するからコマンドはよく使う(unload→手動でプロセスを殺してpidを削除→load)
sudo launchctl unload /Library/LaunchDaemons/org.nut.full.plist
sudo launchctl load -w /Library/LaunchDaemons/org.nut.full.plist
# 4. 今すぐ動作確認
sudo launchctl start org.nut.full # 明示起動(再起動後は自動)
やり直すとき、こういう感じでやる。面倒
code:zsh
# 1) plist を止める
sudo launchctl unload /Library/LaunchDaemons/org.nut.full.plist
# 2) 迷子プロセスを全部止める
sudo pkill -9 upsd upsmon upsdrvctl
# 3) 残骸 PID ファイルを消す。ディレクトリの権限によっては消えないことがある
sudo rm -f /opt/homebrew/var/state/ups/*.pid
# 4) いま 3493 が空いたか確認(何も返らなければ空き)
sudo lsof -iTCP:3493 -sTCP:LISTEN
# 5) plist を再ロード
sudo launchctl load -w /Library/LaunchDaemons/org.nut.full.plist
# 6) 状態確認:真ん中が 0 なら成功
sudo launchctl list | grep org.nut.full
古いらしい
o4-mini-high.iconmacOS 11(Big Sur)以降、load / unload は「Legacy commands」として扱われ、将来的に削除される可能性があります 推奨サブコマンド
bootstrap:サービス(plist)をロード
bootout:サービス(plist)をアンロード
enable/disable:起動のオン/オフをマーク
デバッグのための手動実行
code:zsh
sudo upsdrvctl -DD start by35s
Network UPS Tools - UPS driver controller 2.8.2
If you're not a NUT core developer, chances are that you're told to enable debugging
to see why a driver isn't working for you. We're sorry for the confusion, but this is
the 'upsdrvctl' wrapper, not the driver you're interested in.
Below you'll find one or more lines starting with 'exec:' followed by an absolute
path to the driver binary and some command line option. This is what the driver
starts and you need to copy and paste that line and append the debug flags to that
line (less the 'exec:' prefix).
Alternately, provide an additional '-d' (lower-case) parameter to 'upsdrvctl' to
pass its current debug level to the launched driver, and '-B' keeps it backgrounded.
0.000060 D1 upsdrvctl commanding one driver (by35s): start 0.000064 D1 Starting UPS: by35s 0.000072 D2 1 remaining attempts 0.000075 D2 exec: /opt/homebrew/Cellar/nut/2.8.2/bin/blazer_usb -a by35s Network UPS Tools - Megatec/Q1 protocol USB driver 0.18 (2.8.2)
Please note that this driver is deprecated and will not receive
new development. If it works for managing your devices - fine,
but if you are running it to try setting up a new device, please
consider the newer nutdrv_qx instead, which should handle all 'Qx'
protocol variants for NUT. (Please also report if your device works
with this driver, but nutdrv_qx would not actually support it with
any subdriver!)
Supported UPS detected with megatec protocol
Rating information unavailable
Vendor information unavailable
No values provided for battery high/low voltages in ups.conf
Using 'guesstimation' (low: -0.866667, high: -1.083333)!
Battery runtime will not be calculated (runtimecal not set)
1.048597 D1 upsdrvctl: successfully finished 1.048631 D1 Completed the job of upsdrvctl tool, cleaning up and exiting now 1.048639 D1 Completed the job of upsdrvctl tool, clean-up finished, exiting now o4-mini-high.icon
USB 経由で UPS(識別名 by35s)は認識されたものの、UPS 本体から定格(電圧や容量)やベンダー情報は取得できなかった
ups.conf にバッテリーの高低電圧設定がないため、「guesstimation」(推定値: low -0.866667V, high -1.083333V)を使っている
runtimecal が設定されていないので、バッテリー稼働時間の自動計算は行われない
code:zsh
sudo /opt/homebrew/sbin/upsd
Network UPS Tools upsd 2.8.2
fopen /opt/homebrew/var/state/ups/upsd.pid: No such file or directory
Could not find PID file '/opt/homebrew/var/state/ups/upsd.pid' to see if previous upsd instance is already running!
ACL in upsd.conf is no longer supported - switch to LISTEN
ACCEPT in upsd.conf is no longer supported - switch to LISTEN
listening on 127.0.0.1 port 3493
listening on ::1 port 3493
Can't connect to UPS by35s (blazer_usb-by35s): Connection refused Found 1 UPS defined in ups.conf
ドライバからサーバーに接続できていない
o4-mini-high.icon
先にサーバーから立ち上げないとダメ
その後ドライバーを立ち上げる。-DDだと常駐しないから-Bで
upsdのfopenに失敗している=権限がない?
code:zsh
sudo chown root:wheel /opt/homebrew/var/state/ups
sudo chmod 700 /opt/homebrew/var/state/ups
sudo zsh -c 'rm -f /opt/homebrew/var/state/ups/*'
sudo /opt/homebrew/sbin/upsd
Network UPS Tools upsd 2.8.2
fopen /opt/homebrew/var/state/ups/upsd.pid: No such file or directory
Could not find PID file '/opt/homebrew/var/state/ups/upsd.pid' to see if previous upsd instance is already running!
not listening on 127.0.0.1 port 3493
not listening on ::1 port 3493
no listening interface available
o4-mini-high.icon
no listening interface available
upsd.conf に有効な LISTEN 行がないためサーバーが “監視すべきインターフェース” を見つけられず起動を拒否している
/opt/homebrew/etc/nut/nut.conf の MODE が netclient や none に設定されていると、upsd は自分をクライアント(upsmon)とみなして LISTEN 指定を無視します。その結果、待ち受けできずに “no listening interface available” となります
サーバー(upsd)を動かすには MODE=netserver が正しい設定です。各モードの違いをまとめます:
standalone
UPS のドライバー(upsdrv)とモニター(upsmon)を同じマシン上で動かしますが、upsd(サーバー)は起動しません。
ローカル Unix ソケット経由のみで通信するイメージです。
netserver
upsd(サーバー)を起動し、TCP ポート 3493 で待ち受けます。
同じマシン上でドライバーとモニターも動かせます。
他のクライアント(別ホストの upsmon)からも接続可能です
基素.iconstandaloneからnetserverに変えるも同様の結果
code:/opt/homebrew/etc/nut/nut.conf
MODE=netserver
デバッグ
code:zsh
sudo /opt/homebrew/sbin/upsd -F -D
Network UPS Tools upsd 2.8.2
0.000000 fopen /opt/homebrew/var/state/ups/upsd.pid: No such file or directory
0.000004 Could not find PID file '/opt/homebrew/var/state/ups/upsd.pid' to see if previous upsd instance is already running!
0.001361 D1 debug level is '1' 0.001498 not listening on 127.0.0.1 port 3493
0.001527 not listening on ::1 port 3493
0.001533 D1 server_load: tried to set up 2 listening sockets, succeeded with 0 0.001535 no listening interface available
o4-mini-high.iconupsd は 127.0.0.1:3493 と ::1:3493 の2つを読み込んでバインドを試みたが、どちらも OS レベルで失敗しています
基素.icon
code:zsh
sudo lsof -i TCP:3493
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
upsd 2055 nobody 3u IPv4 0x1b6f9813a77c73db 0t0 TCP localhost:nut (LISTEN)
upsd 2055 nobody 4u IPv6 0x3ca3ad2d02660d67 0t0 TCP localhost:nut (LISTEN)
o4-mini-high.icon出力を見ると、upsd はちゃんとポート 3493 で LISTEN できているので、サーバー側の起動自体は成功しています。
upsd は起動時だけ root 権限を使って TCP ポート 3493 をバインドし、その後はセキュリティ上の理由から nobody(または設定した非特権ユーザ)に落として動きます。
そのため、ps aux 上でユーザが nobody と表示されても、同じ upsd プロセスです。