configure esxi shutdown in case of power loss (HP UPS)
These steps are necessary to implement a graceful shutdown of an vSphere environment. For this scenario you need supportet HP UPSs for HP Power Protector.
Preparation
- First: think about timing
- how many seconds/minutes after power loss the hosts should start to shutdown?
- how long do a host to shut down? This question is about how long does the slowest VM needs to shutdown.
- Download HP Power Protector Agent for Linux here. Current version: 1.02.31
- Download VMware Management Assistant (vMA) suitable for your vSphere environment here for 5.5
- IP addresses for UPS management module und each vMA
Installation
- Assign IP address to HP management module installed in HP UPS
either the module gets an DHCP address or you need to connect by use of serial connector - A vMA has to be deployed on every host that should do a graceful shutdown in case of power loss.
- Install HP Power Protector Agent for Linux in vMA
- copy agent onto vMA
- install agent:
sudo rpm -i hppp-linux-1.02.031-1.x86_64.rpm
respectively current version number - login:
http://IP-vMA:4679/
orÂhttps://IP-vMA:4680/
(user: admin/admin) - choose
Client Installation
- Default installation path:Â
/usr/local/HP/PowerProtector
- RPM-Package name:Â
hppp-linux-1.02.031-1
respectively current version number
 Configuration
- Automatic discovery of administrator (module) and client (linux agent) normally works fine. If not, scan for administrator in client.
- If the UPS is discovered and show with status not managed, right-click the UPS and configure Power Sorce. The status has to be OK.
- UPS Network Module should show the discovered devices as Notified Applications.
- HP Power Protector Agent
- copy script (in my case:Â
ShudownESXi.sh
) to shut down all VMs running on that host toÂ/usr/local/HP/PowerProtector/bin/virt-tools
[ShutdownESXi.sh
 is s very simple script to shut down all VMs, but the vMA itself, and the host afterwards. You can’t use cluster-settings to shut down VMs on an cluster with HA enabled.
If you don’t have an own script to do this task, leave a command and I will email the script[update] A working script you can find here]
- configure Event Actions as necessary (SMTP)
- configure Shutdown Parameters
- time settings as considered
- Shutdown type: script
- Shutdown script:Â
/bin/su - vi-admin -c "/usr/local/HP/PowerProtector/bin/virt_tools/ShutdownESXi.sh vMA_ESXi_IP"
- Test Shutdown
- copy script (in my case:Â
Upgrading Power Protector Agent
- upgrade agent:
sudo rpm -U hppp-linux-1.03.041-1
Uninstallation of Power Protector Agent
- uninstall agent:
sudo rpm -e hppp-linux-1.02.031-1
- because of a known issue, uninstalling the packate does not remove the software completely. Therefore remove also all files withinÂ
/usr/local/HP
Hi, I’m from Spain.
I have two hosts with esxi 5.5 in a HA cluster and a HP UPS R/T3000 with the ethernet module.
I’ve installed VMA in one of the hosts and I would like to shutdown all the virtual machines and all the hosts if there is a power fail.
I would like to power on the hosts and all the virtual machines if the energy comes again. I don’t know if this is possible or not.
Will you please help me with this.
Thanks.
Hi!
At least it is easily possible to shut-down the VMs and the hosts in case of a power failure. If you decide to configure it like I wrote in the post, you need to install a vMA on each host. If the configuration is right, the Agent Software in each vMA receives a trap from the Management Module within the UPS, so it gets the information to do what is configured in case of a power failure. Here it runs a script that shuts down all VMs and afterwards the host itself.
But it is more complicated to automate the power-on after a power failure. You have to take a lot of parameters into account. Just a few examples:
Storage
– How long do the switches (Ethernet, FC) need to fully power on
– How long do the storage system need to fully operate
– In case of a shared SAS-Array, eventually HBAs should wait until the array is fully started up
VMs
– Do you need a special order to start up VMs. Even if you could configure the Host Shutdown/-up feature in a HA-Cluster, you are not able to define a “global order” of VM starts. The order is just valid for the host you configured the order. When you use vMotion to move a VM, the order of this VM is lost on destination host.
– It’s not just the order of VMs to boot, also important is the timing between the starts. Think of applications that need more time to start.
– Do you have VMs that are shut-down during the power failure and you don’t want them to start up after the failure is gone?
It’s a little bit like backup and restore. To do a backup of whatever is quite easy to manage. But if you need to restore data, you have to have a lot more information and knowledge of the environment. What I want to say, it could be hard work to set up an automated start-up after a power failure. But it is possible. You just have to do more planing and do more work to get it done. So it is possible to write a simple script that starts your VMs in the order you need. If you need a “global order” you need a better script. And at which situation the script should start? You can easily trigger the script to start during vMA start-up. But you should not do this at every start-up, just after a power failure occurred. If you are good in scripting it will be no big deal, if you are not, it will be harder. Another way could be using vSphere Orchestrator.
Also because of this possible complexity, most of my customers decided to do the start-up after a power failure manually.
I hope I could help you with that. Let me know if not.
Regards to spain!
Hi,
great read.
can you email the script please?
THX
Daniel
sent
Hello! Will your script working on free version of the ESXi?
Hi Eugene!
I did not test the script in free ESXi edition, but I don’t see any command that would not work on this edition. But I think you are not allowed to download a vMA without a paid license for a ESXi host. So when you have a least one ESXi license, you can download the appliance.
regards
Wolfgang
Let mr try your script on free ESXi.
script sent
It works. Thank you!
Hi Mate, Could I have your Shutdown script, please? Thanks.
Hi Sam, script sent!
regards
Hello Wolfgang!
May I ask you to send me the script?
Many thanks
Vito
Hi vito! script sent.
Hi Woifgaung, may I get a copy of your script
Thanks
scrip sent.
Hi Vito, I have worked through this and created a script that works fine when run from the command line, but is ignored when a test shutdown is triggered from the UPS (it shuts down the vMA only)
I wonder if you would be so lind as to share your script with me too?
Thanks
Stephen
Scrip sent. I hope it complementarily shuts down everything but the vMA.
regards
Wolfgang
Hello Vito, may i ask you to send me your shutdown script also? Thank you in advance
Regards
Lukas
Hi Lukus!
Scrip sent. By the way, my name is wolfgang, not vito.
regards
hi wolfgang, been configuring this but stuck at the same stage, script wont run. Would you mind share me the script pls.
Thanks!
Script sent. Let me know if it is working. regards.
Hi Wolfgang, great post. Kindly share the script.
Thanks!
hello! Thanks for feedback! The script should be already in your mailbox.
Hi woifgaung, nice post, could you please share the shtudwon script?
Thanks!
Hi Jan, Script sent!
Hi, I’m stucked with this scripted shutdown in an ESXi v6.0.0 environment (original HP image). I use an vMA 5.5 with the latest HPPP to do this. Hopefully this works with your script ?
Hi!
I sent the script to you mail-address.
Up to now I did not use the script on ESXi 6.0 hosts. But I had some trouble when trying to use the script in a vMA 5.1 on a 5.5 host. This does not work! You can try to execute the command
vmware-cmd
in your vMA 5.5 connected to a 6.0 host. When this command works you have a good chance to get the script to work. If it does not work, you probably have to move to vMA 6.0.Let me know if it works
Thanks
Hi Woifgaung,
I am getting the below given error when it run the script to shut down the vms and host. I have not altered anything in the script.
vi-admin@localhost:~> /bin/su – vi-admin -c “/usr/local/HP/PowerProtector/bin/virt_tools/ShutdownESXi.sh XX.XX.XX.XX”
Password:Password:
: command not foundProtector/bin/virt_tools/ShutdownESXi.sh: line 1:
: command not foundProtector/bin/virt_tools/ShutdownESXi.sh: line 7:
sleep: invalid time interval `s\r’
Try `sleep –help’ for more information.
: command not foundProtector/bin/virt_tools/ShutdownESXi.sh: line 10:
: command not foundProtector/bin/virt_tools/ShutdownESXi.sh: line 15:
: command not foundProtector/bin/virt_tools/ShutdownESXi.sh: line 16:
: command not foundProtector/bin/virt_tools/ShutdownESXi.sh: line 19:
: command not foundProtector/bin/virt_tools/ShutdownESXi.sh: line 22:
: command not foundProtector/bin/virt_tools/ShutdownESXi.sh: line 25:
/usr/local/HP/PowerProtector/bin/virt_tools/ShutdownESXi.sh: line 27: syntax err ‘r near unexpected token `do
/usr/local/HP/PowerProtector/bin/virt_tools/ShutdownESXi.sh: line 27: `for i in ‘vmware-cmd -l`; do
Hi!
It looks like you just entered the IP address of the host to shutdown as a parameter of the script. You have to enter 4 parameters as you can see in the remarks of the script. Can you confirm this?
regards
Wolfgang
Hi Wolf!
Is it really 4 parameters? My script just demands server, username and password…
Could you please provide your alternate script as well?
thx
Hi Stephan!
Yes in my script I use 4 parameters. Username and password is coded in the script. If you like you can easily add parameters for these values.
Regards
Wolfgang
PS: Script should be in your in-box.
Hello Wolfgang!
Thank you for help.
Is it possible to have ShutdownESXi.sh for me also )
Gennady
Hi Wolfgang!
Thank You for instruction. It was very helpful for me.
May i have script also ?
Gennady
thanks, script sent.
Hi work the script with esxi 6.0?
Hi Nils!
I still did not try the script in 6 up to now. Some time ago jfrog asks the same question. I sent the script and did not hear that it did not work. But I also did not hear that it worked. I am quite sure it will work. Please try and give me some feedback.
Thanks
Wolfgang
Hi, can you send me the script?
Thank you Nils
Hi Nils! Script sent. Regards Wolfgang
hi, can you please send me a script?
Thank you very much
Hi Petar! Script sent.
Please send me the script. Thanks!
Script sent.
Hi Wlofgaung, can you send me the script, thanks.
script sent
Hi Wolfgang, thank you for the nice description! Can you please send me the script? thx
Thanks for commend! script sent.
Hi mate, thanks for the great post. Could I get the script sent please? Cheers.
Hi Jim! Script sent.
Hi Wolfgang,
is the script working on ESXi 6 too?
Could i get the script to try it in my Environment?
Regards
Script sent. Yes, the script should work fine in a vSphere 6 environment.
Regards
Hi Wolfgang,
We have a V6 environment, could you please send me a copy of your script please.
Thanks,
Andy….
script sent
Hi,
Can You send me a script?
TIA
Thanks for the detailed instructions. Could you please send me your script?
Can you please email me the script. Also please let me know 1. Where the script originates 2. Which host gets the script (the VMA or the ESXi server) thanks.
Dear Woifgaung, there is a script that shutdown all VM’s on a Cluster with HA enabled?
I’ve a 4-node cluster. Do I need to install vMA on every node of my cluster or only on one of them?
Many thanks in advance for your precious help.
Marco.
Hi Marco!
Yes the script shuts down all VMs, regardless of whether HA is enabled or net. Yes, for this approach it is necessary to deploy a vMA on every host in the cluster.
Regards
Wolfgang
Thanks you so much for your very fast reply. so how I can a copy of your script?
Many thanks and best regards!
Hi, helped me very much. Would like to ask for your script. Could you sent it? Thanks a lot
send me a copy of your script please
Can you send me the vsphere 6.0 version of the script as well please
Hi would appreciate a copy of your script please. Thank you 🙂
I have two hosts with esxi 6.0 in a HA cluster and a HP UPS R/T3000 with the ethernet module.
I’ve installed VMA6 in one of the hosts and I would like to shutdown all the virtual machines and all the hosts if there is a power fail. Can you send me the script please. Thank you.
Hi Woifgaung. Could I have a copy of your script please. It will be used on ESXi 6 in an HA Cluster. Thank you in advance.
Hi, can you send me please the script? I need it for an ESXi 6.0 environment to shutdown den VMs and in the end the host himself.
Thank you!
Hi,
nice work!
can you email the script please?
THX
Exactly what i was searching for! Would you send me the Shutdown Script please? Thanks!
We have a 2 node ESXi 6.0 cluster on Vcenter 6.0 where i am trying to Automate VM & Esx graceful shutdown by deploying vMA & installed HP Power protector 1.04 & 1.02 on the vMA’s. The UPS is reachable from vMA & Vcenter. But the issue that i am facing is when trying to discover UPS from HPPP web interface with the quick scan option, the UPS is not discovered probably because it is in a different IP range. According to the HPPP Guide, i should have an option below “quick scan” to scan using IP ranges which i am not getting in the user interface in HPPP version 1.02 & 1.04.
Could you please throw some light as to why i do not get the option of scanning/ discovering UPS through IP ranges?
solved it, its cause i was opening HPPP as administrator instead of client as Range scan option is available only with client.
wolfgang, very nice solution, please sent me the script. thank you a lot 🙂
Hi Wolfgang,
I’d like to receive the script as well. I find that the HP Management module is not very stable when you have a lot of remote clients (HP Power Protection Agents) running. Hopefully this will solve that problem since I only have 3 ESXi hosts.
Thanks in advance.
Regards,
Cyril
At least this reduces your problem
Hi Wolfgang,
this is realy good post. I’m interested in the script as well.
Hi Wolfgang,
can you share the script with me too i need to do some configuration like your with 3 esx and 1 vcenter
Hello Wolfgang, very good post! Can you send me the script? Thanks alot!
Hi Wolfgang, excellent post! Could you please send me the script as well? Thanks so much in advance.
Great work, i have esxi 6.0, can you send me the script please??
Thaks
Hi everybody, I’d need that script, too 🙂 Could someone kindly send it to me? Thank’s!
HyWolfgang, its nice what you doing, very good post! Can you send me the script? Thank you!
What ?
Good post! Can you send me the script?
Thank you!
Hello Wolfgang, thanks for the good article. Could you provide the script as well? Thank you!
Hi
thanks for your useful post, could you send me script please?
could you use vicfg command or something similar?
I note this for vMA:
vicfg-hostops.pl –server ip_address –username root –password password –operation shutdown
but you need to sent the “enter” command before to put host in maintenance mode, it is not a useful mode because when host came up again won’t start VMs automatically because of mant. mode status.
Hi Wolfgang, very good post! Can you send me the script?
Thanks
Hi guys,
after several research i found a useful script into this path of vMA
/usr/local/HP/PowerProtector/bin/virt_tools/shutdownESXi.pl
I had to go on the top of the montain to get back to level ground 🙂 🙂
I used this script into HPP web console shutdown parameters
perl /usr/local/HP/PowerProtector/bin/virt_tools/shutdownESXi.pl –server xxxxxxxx –username root –password xxxxxxxx
Adding “perl” at the beginning it worked perfectly for my environment (no Cluster, No HA) you have to try with HA enabled.
here a useful link too
http://h20564.www2.hpe.com/hpsc/doc/public/display?docId=emr_na-c03600516&sp4ts.oid=5106149
Thanks again to Wolfgaung to pointing me on the right way
Woifgaung, Thanks for this very helpful post, you have saved me a load of time and no doubt pain. Could you please send me the Shutdown script. Many thanks
would really appreciate to receive the script as well! thanks in advance, great write up
Hi Woifgaung, I would appreciate it a lot if you could send me the script. Thank you!
[…] Here is a very simple linux bash script to shut down all VMs of a ESXi host and the host itself, for example when a power failure occurs, this script can be used in UPS software. Some time ago a posted how to use such script in an HPE UPS environment. You can find the post here. […]
Hi Woifgaung would you be able to send me the script, will this work with ESXi 6.7
and HP R5000
Hello James!
You can find the script here: https://vnote42.net/2018/05/14/simple-linux-script-to-shut-down-vms-and-esxi-host/
For the HP R5000 it will work. But I am not sure about vSphere 6.7. VMware vMA is already deprecated for a few years (https://blogs.vmware.com/vsphere/2017/04/vsphere-management-assistant-deprecation.html). I personally think, it will work, but I did not try up to now. You can easily test the setup by installing vMA and running the vmware-cmd, vifptarget and vifp commands – like in the script.
Regards
Wolfgang
Hey Woifgaung I would like to shut down VMs in a sequence so that the DC is last
Is there a way we can do that ? or would you have another script that might be able
to help out in that fashion
Hi James!
You can easily change the script to do so. You can exclude VMs you want to shutdown at last by excluding them during the loop. I did so with the VMA-VM itself ($VMA). After the loop, shut them down individually by running command “vmware-cmd path_to_vmx-file stop soft”.
I hope this helps you!
Regards
Wolfgang
Hi Wolfgang
Can I have the script for shutting down the servers attached to the HPE UPS please?
Regards
Boba
Hello Boba!
Script you can find here: https://vnote42.net/2018/05/14/simple-linux-script-to-shut-down-vms-and-esxi-host/
Regards
Wolfgang
Hi all,
Can this script be used without the HPE? I would like to just schedule all the VM and ESXi Host to power off and then shutdown the server hardware.
Hi Jim!
Sorry for my late response!
Sure, script is hardware independent. You just need to trigger the script in any way.
Wolfgang