nielsmouthaan / ejectify-macos

Ejectify automatically unmounts external volumes when your Mac starts sleeping, and mounts them again after it wakes up.
https://ejectify.app
Other
370 stars 50 forks source link

Eject disk when power source switch from AC to battery #42

Open YangJianchong opened 2 years ago

YangJianchong commented 2 years ago

Hi,

I'm using a Mac mini with an APC backup UPS at home.

I'm a bit worried about that when I'm not at home and there's a power outage, after the UPS battery drained out, or due to Energy Saver schedule, Mac just shuts down hard without safely ejecting all my external drive.

I hope ejectify can listen to some sort of 'power source switching to UPS' system event and safely eject all my external drives.

Hope I expressed myself clearly.

nielsmouthaan commented 2 years ago

How is your disk connected to your Mac? Directly or via a hub (which can also be an external display)?

YangJianchong commented 2 years ago

How is your disk connected to your Mac? Directly or via a hub (which can also be an external display)?

Both. Some are connected directly to the Mac and the others connected via hub(which has its own power source also connected to the UPS).

nielsmouthaan commented 2 years ago

Ejectify needs to be able to unmount the volumes before the (external) disks lose power. That will be the case for those connected directly to your Mac. I cannot say whether that's also the case for those connected to the hub. If the hub or disks loses power before your Mac (because the UPS is empty), Ejectify won't have unmounted the volumes. Somehow the UPS should notify your Mac that its power is critically low so that your Mac can safely unmount (external) volumes. Do you know whether your UPS supports such a notification mechanism?

YangJianchong commented 2 years ago

Thank you for replying.

I forgot to tell you that my UPS has a USB cable which connects to my Mac so the Mac can read the UPS's battery percentage (shown as images below). Is this the mechanism you are talking about?

Screen Shot 2022-08-06 at 1 16 55 Screen Shot 2022-08-06 at 1 23 53 Screen Shot 2022-08-06 at 1 22 48
nielsmouthaan commented 2 years ago

So your Mac shuts down when the UPS battery is critically low? In that case, you should be good: connected volumes will be unmounted safely as part of the shutdown process of macOS.

YangJianchong commented 2 years ago

So your Mac shuts down when the UPS battery is critically low? In that case, you should be good: connected volumes will be unmounted safely as part of the shutdown process of macOS.

TL;DR: I did some test yesterday. I'm afraid that Energy Saver cannot control the the Mac to perform a normal shutdown process as it's scheduled.

I scheduled my Mac to shutdown when time remaining on UPS is 5min and when UPS battery level is below 5% and I pull off the UPS's power cable from the wall to simulate a power outage situation and let the Mac use UPS's power, with an external disk connected directly to it. Then I found out that the battery percentage reading of the UPS is inaccurate and not reliable, and even though the battery percentage become 0% the Mac is still running. Finally the Mac shutdown suddenly and I heard the sound by external hard drive's actuator arm returning to the position immediately. That indicates the hard drive is still spinning and working.

nielsmouthaan commented 2 years ago

That's odd; something is wrong with your Mac starting to sleep based on the UPS having a critically low battery level? I would suggest contacting the manufacturer of your UPS to receive support regarding this matter.

YangJianchong commented 2 years ago

Thank you, I'll reach for manufacture's help about the UPS. But will Ejectify be able to take action before the Mac shuts down on its own because of the power source changing? Since the change itself can be detected by macOS everytime.

nielsmouthaan commented 2 years ago

So unmount when switching from AC to battery?

YangJianchong commented 2 years ago

Yes exactly.