Cyberpower UPS + NUT + remote shutdown of ESXi

Status
Not open for further replies.

gmcj

Cadet
Joined
Oct 2, 2016
Messages
3
FreeNAS: FreeNAS-9.10-STABLE-201606270534
Cyberpower UPS: CP1300EPFCLCD
ESXi Host: ESXi 6.0.0 build-3029758

Running two boxes at home, one FreeNAS and one ESXi Host all connecting to a new Cyberpower UPS. A piece of disk space on FreeNAS was exported to ESXi via iscsi catering for VMs. Connected a FreeNAS to UPS via USB and made it running in master mode. Had to find a way to shutdown ESXi and FreeNAS in proper order that is ESXi first and then FreeNAS. Otherwise it may lead to potential data loss. So FreeNAS is the controller in the shutdown.

After setting up NUT on FreeNAS, got the following in place too:
- password free ssh login for root user, from FreeNAS to ESXi
- customised script /usr/local/bin/custom-upssched-cmd on FreeNAS to do:
> remote log into ESXi
> shutdown active VMs
> put host in maintenance mode
> poweroff
> send out email notice
> shutdown FreeNAS at the last step

The script worked fine in tests -- it could correctly shutdown remote VMs and then ESXi. But it was not working after deployed to nut. Then figured out there was a permission issue:
> In test I ran the script from the command line as root
> upsmon daemon is running in two sub processes, one as root, the other one as uucp
> /usr/local/bin/custom-upssched-cmd was run as uucp, not root. Therefore it did not have sufficient privilege to remote log into ESXi
> uucp is not a realy user id. It's just a pseudo id so for it I can't setup password free ssh login to remote ESXi

Did quite a lot of searching. A post said upsmon could be run as a single root daemon by changing the command in /conf/base/etc/local/rc.d/nut_upsmon to "upsmon -p", but it did not work.

Finally, I figured out it's the /etc/local/rc.d/nut_upsmon who controls the daemon commands. Modification like below resolved my problem by forcing upsmon to run as root:
Code:
nut_upsmon_flags=${nut_upsmon_flags-"-p"}


The original setting seems incorrect becoz upsmon does not recognise this flag I suppose. No idea why this flag was put here:
Code:
nut_upsmon_flags=${nut_upsmon_flags-"localhost"}


Now the shutdown script is working like a charm and I don't need to worry about the data loss of VMs.
However, I am not sure if I should run upsmon as root because it's not recommended by nut. Does anyone have alternatives/suggestions? Thanks.
 
Status
Not open for further replies.
Top