In this latest post by TechHead guest contributor James Pearce he covers a topic near and dear to many of us – how to get VMware ESX/ESXi and its VMs to shut down gracefully upon power failure to the host. Tighter integration between a UPS and a VMware ESX/ESXi host is no doubt something that will become more mature over time though for now it can be an issue for many administrators especially those running the free version of ESXi. So read on to find out how James overcame this issue in his virtualization lab.
A Nearly Free UPS
I recently acquired an APC Smart UPS that was being chucked out from work (having never worked) for my home lab along with an ancient AP9606 management card. With the batteries changed the UPS burst into life – but after some messing about getting the right firmware on it, I was disappointed to find no easy way to get it to shutdown my ESXi box when it needed to.
VMware License Restriction
The VMware management appliance (vima) can shutdown only paid-for installations of ESXi (using apcupsd and VMware community member lamw’s scripts) – the necessary interfaces on the free version have been made read-only since ESXi v3.5 U3.
Burp Suite
I’ve been finding a lot of use recently for network sniffers, so thought I’d have a look at how the VMware vSphere Client works, as obviously that can shut down the host. As luck would have it, the client is nothing more than a glorified web browser with the slight complication that it’s talking over SSL – but that’s no problem for PortSwigger’s Burp suite in its transparent proxy mode.
The traffic captures revealed that only three frames would be needed to perform the shutdown (hello, authenticate, and shutdown). A little manipulation is needed to get the session keys in, but that is basically it. ESXi’s startup and shutdown policy will do the work suspending or shutting down individual VMs, as configured through the vSphere Client.
The Script – shutdown.bat
Using this newly found knowledge I’ve created a Windows batch file (with a few supporting text files which are basically HTTP requests) that takes the hostname, username and password as parameters and will then shut down the host cleanly. The script needs something to launch it – APC PowerChute Network Shutdown in my case – and a utility to send the commands over SSL, for which I’ve used Nmap ncat (which just needs to be installed).
I have put all the necessary script files into a single convenient zipped file which you can download from here – the scripts are fairly well commented so you should be able to follow what is happening.
APC PowerChute
A potential issue is that APC’s PowerChute Network Shutdown utility will always shut down the Windows machine it’s running on. I’ve therefore used a separate Windows management VM to host PowerChute and my script, since I wanted everything else just suspended.
PowerChute has an option to ‘run this command’ but it’s limited to 8.3 paths and won’t accept command line parameters. A separate batch file is needed (poweroff.bat) that runs the shutdown script with the parameters – but that could shut down other ESXi boxes as well if required. Also the PowerChute service needs to be run as local Administrator as the default Local System account doesn’t have sufficient rights.
Testing the Scripts
Download the ZIP and extract the files – I’ve assumed the package will be extracted to c:scriptsesxi; update the path in poweroff.bat otherwise. Also the hostname, username and password also need to be specified in poweroff.bat.
Next install and configure PowerChute (in particular change the service user account) and enter the script in the ‘run this command’ box – I also increased the time allowed, but in practice it runs in a few seconds.
Some waiting around can be avoided when testing by setting the UPS low-battery duration as high as it will go – just remember to change it back.
Next open up vSphere Client from a real machine, pull the UPS plug and once the battery get’s down to the specified number of minutes remaining, the script should run and the tasks will appear in vSphere Client. Shortly afterwards the VM used to launch the script will itself shutdown under the control of PowerChute!
In Summary
The complete set of files can be downloaded here, and nMap ncat installation for Windows from here. Then a UPS management application is needed, for APC Smart UPSs use PowerChute for Windows.
The shutdown script includes logging and should report most errors. Bear in mind though that once a host is shutdown, it probably won’t be restarted when utility power is restored.
Burp Suite is a handy utility to bypass device limitations by enabling the scripting of management tasks that are only usually available through a web interface. I’ve used it to build scripts to regularly reboot home-spec routers every couple of weeks to keep them stable, and to set the time on the APC AP9606 management card daily since it doesn’t support NTP – and here to build a UPS shutdown script for ESXi; functionality that should really be built into ESXi in the first place.
Clever.
Update: vmware communities member William Lam (lamw) has used this to create a new Pearl script that provides this functionality in a neater form, although without the logging – check out his post on it at http://communities.vmware.com/docs/DOC-11623
Hi James,
Many thanks for the post. Well written and clear.
Hope to see more clever tricks!
Hi,
Great job James, I’ve been looking for this for some time.
I’m having a problem where the guest/s don’t get time to shut down gracefully before the host powers down. This is testing the command only, I have taken the ups out of the equation for now.
NB: Esxi 4 running sbs 2008 and openfiler on a HP ML115 G5 w/ 8GB RAM. (There is a vcenter 4 server in the mix, but I’m directing the shutdown cmd to the host itself).
Anyone have any ideas/suggestions as to why I cannot shutdown the sbs guest gracefully?
Thanks in advance.
Hi David
Two things I’d suggest – first ensure vmware tools are installed in the guests. Second configure the ESXi startup / shutdown order to automatically suspend guests, openfiler starting first (and hence closing last).
Lamw’s interpretation of this code will work against vcentre and there are other options too for licensed ESXi, like lamw’s other scripts.
Thanks for reading!
What to change if I only want my host to reboot ?
Hello, I assume that you really just want to script a host reboot, in which case the best bet is to use Burp to capture that request from the VI Client.
Hope that helps!
Hi,
I replaced “ShutdownHost_Task” with “RebootHost_Task” in the shutdown-3.txt file and it worked.
I never think it will be so simple.
Thank
Excellent – thanks for sharing this!
Hi James,
I am facing a similar situation like the one you describe.
I have an ESXi 4.0 free licensed installation running some VMs.
I have a UPS without a network management card. This UPS is connected against the host via USB or serial port. Need to shutdown VMs and finally the host in case of power outage.
and need to avoid the following:
1) license the ESXi 4.0
2) buy a network management card
3) buy APC software (not sure if cames for free when you buy network management card)
Any ideas about how to do this?
Any guide will be much appreciated
Thanks
Federico
Hi, to get a USB UPS working you will need either a physical host with a USB port (an old laptop maybe?), a network USB hub (http://www.digi.com/products/usb/anywhereusb.jsp#overview), or an ESXi server that supports vmDirectPath and pass through a port in the host.
To be honest, if it is an APC Smart UPS I would definitely hunt out a cheap old AP9606 web management card (seem to be about £25 on eBay at the moment, but they do come up cheaper sometimes). It doesn’t matter what it was from (i.e. PDU, UPS, whatever) – the firmware I’ve linked to above can be installed to get it working with a UPS.
The APC software is freely downloaded from apcc.com, or there are freeware UPS utilities as linked to by the lamw scripts that are more generic.
Hope that helps!
Thanks,
excellent solution for a “strange” limitation on the free version. It works very well. Just for info (I’m not so far expert in VmWare management), if an ESXi machine is powered off with this script, are the hosted VMs gracefully closed before?
TIA
Regards
Roberto
Hi Roberto,
Thanks for the question.
What happens to running VMs depends on how the auto startup/shutdown policy is configured through the vSphere Client. I set all my VMs to ‘suspend’, in a particular order, except the management VM running the APC software which is set to ‘shutdown’. Since the script just asks ESXi to shutdown, these policies are adhered to in the process.
Hope that helps.
James.
James,
Thanks a lot!
All the VMs are configured now for “ShutDown Guest”.
Best regards
Roberto
First of all, congratulations for this post is excelent. Just a point when you talk about the local rights in the power chute service I belive if you put the path of ncat in the variable PATH of the global enviorment it will works in any account.
Hi Jordi, glad you find it useful, and thanks for posting the permissions tip.
Cheers,
James.
Brilliant article James!
With regards to the SBS shutdown question above, you definetly need to configure the startup/shuwdown sequence. Put your SBS shutdown timeout at 5-10 minutes. If SBS is done after 4 minutes, ESXi will continue with the next vm. If you keep everything default, ESXi will use the default timeout to continue to the next vm. After the last poweroff command, ESXi will shutdown itself, even if your SBS is still waiting to shutdown!
Many thanks James for Your excellent job.
Nicola
A note for non-english users: some small customization are needed inside the shutdown.bat file (in the CheckHost routine) according to the response messages given by ping in Your copy of windows (those messages are used to check if Your host is alive)
Hi Tiana,
I’m glad you found this useful, and many thanks for taking the time to post the localisation note!
Thanks
James.
Hi James,
Thanks for taking the time to share your work. I am trying to run this with ESXi 4 and 2008 64bit VM. The script works great when I run it from the command line but when it runs via the Powerchute during the VM shutdown I get the below error. I think it is a permissions issue but not sure. The APC service is running as a Domain Admin account for testing but still get the message below when it is executed via Powerchute. The script was added with the full path C:scriptsesxipoweroff.bat and set the time for script execution for 60 seconds. The script is called as you see the message in the shuudown.txt log file but only the VM shuts down. Any ideas?
Shutdown.txt log:
System shutdown called: Fri 04/16/2010 3:05:53.22
ESXi Server did not accept connection attempt:
Return code was (no-response-from-server).
Thanks,
Brad
Hi James,
My issue is resolved with the help of Jordi’s comments.
Once the Nmap/Ncat path was set in the system variables and restart of the server the script was able to execute under the credentials running the PowerChute service and shutdown the ESXi host.
Thanks again,
Brad
Hi Brad, glad it’s sorted and sorry the delay in replying. I was pondering on this, wondering whether it was a path issue or Windows firewall getting in the way of things 🙂
Thanks
Hello
I just wanted to verify a few details. This process should work with any ( new or older ) APC Smart UPS and a AP9606 management card ? Are the newer APC Smart UPS still compatible with the AP9606 management card ?
I have a HP Proliant 150 G5 and all I am really looking for is enough battery uptime to gracefully shutdown 3 VMs. Can anyone recommnned a APC Smart UPS that would fit those minimal requirements?
Thank you in advance.
Hi, sorry for the delay in picking up this query.
The process is driven from APC’s PowerChute software. With v2.2.4 I’ve used both AP9606 and later AP9617 cards OK. The only requirement for the card is that it has the Smart-UPS firmware application (sumx.bin), as they can be flashed for several different devices.
I’ve put a bit more detail on this at http://blog.peacon.co.uk/wiki/APC_Smart_UPS, but essentially all smart slot management cards are interchangeable as really it’s just a serial port, but the functionality is dependent on the firmware on the card, which varies by card type.
For your server, it really depends on the wattage and your expected run time and shutdown time. My home-lab ML115G5 draws about 120W, the small 750 model in this article giving about 30 minutes with that load. I set the shutdown time at 11 minutes, to give plenty of time for all the VMs to suspend properly.
Hope that helps!
very nice post buddy
cheers
1. Install the Digi AnywhereUSB/2 device.
– Configure a static IP Address
– Connect the UPS USBcable
2. Open SSH connection on the the ESXi host.
– At the Host Terminal hit Alt-F1 to access the command prompt.
– Type “unsupported” and hit enter.
– Log in and edit /etc/inet.d.conf
– Uncomment the line where you can see “#ssh”
– Restart the host for changes to take effect.
3. Install the UPS software on the Windows 2008 Guest.
– We used the UPS Management Lite software that was shipped with the UPS unit.
– Make all the services to run as the Administrator user. eg: it-admin.
This is done by deleting the start-up registry entries (HLMSOFTWAREMICROSOFTWINDOWSCurrentVersionRUN) and creating a Windows Scheduler task(s) to run these processes at windows startup.
4. Create a Windows batch file in root of C: and name it accordingly. eg: host_down.bat
Add this line in the text file: plink.exe -ssh (ESXi-Server-IP-address) -l (username) -pw (password) “/sbin/poweroff”
5. Download and install Putty’s Plink command utility and place it in root of C:.
6. Run the batch file to initiate the once off Host Key acceptance prompt.
7. Test the UPS with a power failure. You can open the VMware vSphere Client and look out for a “System auto off” event.
Hi.
Thanks for the great info!
I have ESX servers. Will this work as well for ESX 4.o or are there edits?
Thanks,
Mike
Hi, yes this does work with ESX. But you also have other options – supported SSH console (see the posters comments about plink above) or William Lam’s ‘ghetto’ UPS shutdown scripts. I’ve also built this ‘original hack’ into an esxi scripting utility ‘esxi-control.pl’ which has shutdown capabilities: http://blog.peacon.co.uk/esxi-control-pl-script-vm-actions-on-free-licensed-esxi/.
Hope one of those options helps 🙂
Hey
Great post..
just a few questions that i have..
i keep getting a message saying connection refused by server..
can you help me on this??
thank you
Hey
to add to my previous comment,
in the poweroff bat file for the [hostname], do i put the Vm’s ip address or the server’s ip address hosting the VM?
Thank you
Hi, I’d go with IP addresses to be sure a name resolution issue won’t stop it working.
I’ve since developed this into a more general esxi control script – imaginatively called esxi-control.pl – see http://blog.peacon.co.uk/wiki/Esxi-control.pl.
Cheers, James.
Hello again..
i have managed to get everything working and the ESXI server does shut down. The only issue i have is that i found out that the VMs in the ESXI server have a delay time before shutting down. Unfortunatelly, the server itself will shut down regardless of whether the VMs have finished shutting down. Can you assist me on that matter.
Do you know if the delay time for the host machine can be changed through the VSphere or some other place..
THank you very much
I was looking through that perl script you wrote and i was thinking.Maybe i can use that to shutdown all my VMs and then use the other technique described at the top to shut down my host.Can i run the script from a VM which will shutdown all the other VMs and then itself??
Hi, yes you can use esxi-control.pl to do exactly that. If you’re using APC’s PowerChute, that will always shut down it’s host (itself a VM in my case) so esxi-control.pl need not shut that down. Once all VMs are stopped it is safe to let ESXi die with the power, so there is probably no need to shutdown the host in this case.
Be sure the UPS has enough run-time to complete the shutdown process cleanly and bear in mind that the batteries will age (i.e. have a good margin of safety). Trying to suspend or shutdown lots of VMs at once will put a lot of strain on your disks, so it may be faster to run the shutdowns sequentially.
The command for each VM would be:
perl esxi-control.pl –server [esx-host-ip] –username root –password [password] –action shutdown –vmname [[NameOfVM]]
List those down in the shutdown script, and remember to keep it updated!
Re the initial problem, I’ve not seen that issue. Do you have vmware tools installed on all guests?
Thank you very much for your reply but can you assist me with the error message i get when running the script:
Can’t locate VMware/VIRuntime.pm in @INC (@INC contains: C:/strawberry/perl/site
/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib .) at Esxi-control.pl
line 85.
BEGIN failed–compilation aborted at Esxi-control.pl line 85.
Thank you very much
You need vmware’s vCLI installed.
does the vmware vCLI run the script automatically?
Hi, vCLI provides the perl environment with the vmware libraries and bits. It can be downloaded from vmware: http://www.vmware.com/support/developer/vcli/
Tasks can be scheduled using the Windows task scheduler, typically to run a batch file containing the necessary commands. In the shutdown case, some other method will be needed to fire off the command, such as APC’s PowerChute.
HTH
sorry again for bothering you but i installed vCLI and run the script but get the following:
Server version unavailable at ‘https://localhost:443/sdk/vimService.wsdl’ at C:/
Program Files (x86)/VMware/VMware vSphere CLI/Perl/lib/VMware/VICommon.pm line 5
45, line 2.
the password and username are the ones i used for the Vsphere client..is that correct?
vCLI should be on the same box (or VM) as the scripts. Then the script should be run specifying the IP address of the ESX(i) host (same as used to connect through vSphere client), rather than the vCLI box.
For example for esxi-control.pl from the command line on the box with vCLI running:
perl esxi-control.pl –server 192.168.1.10 –username root –password letmein….
where 192.168.1.10 is the IP address of the ESXi management interface.
HTH!
thank you!!!
i got working now thank you very much!!
Great job!!!
hello again..
quick question
I tested the perl script with the shutdown command for shutting down the VM on the ESXI server. what will you suggest in the case when there are processes running on the VM when the shutdown command is run?what happened in my case is that some VMs did not shut down because of windows messages asking “if user wants to stop/save work”..do you have anything to suggest for that so that all processes can be forced to shutdown..
thank you
Hi Kyrillos, my script doesn’t consider the VMs, depending on the actions configured in the vSphere client for automatic host startup and shutdown. You could use ‘shutdown /f’ to force a shutdown of VMs in a set order though instead of shutting down ESXi (if nothing is running in my experience ESXi can be left to just die).
Nice post, works well! On a non english system, you have to adapt the lines:
REM Analyse the results and set environment variable hostconnectres:
find “could not find host” test-connect.txt > not-found.txt
find “Lost = 0” test-connect.txt > found.txt
find “Lost = 1” test-connect.txt > time-out.txt
In German it looks like:
find “nicht finden” test-connect.txt > not-found.txt
find “Verloren = 0” test-connect.txt > found.txt
find “Verloren = 1” test-connect.txt > time-out.txt
Thanks for posting this which no doubt will help others. Also, the perl version won’t have this issue (search esxi-control.pl).
For what it’s worth, I was having problems with the VMs not shutting down gracefully and found this fix from VMWare.
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1008182
Thanks for the great help developing the script!
Thanks for this elegant solution to this issue, it’s a great help to us.
I am interested in taking a look at the soap commands myself but at the moment the Burp suite will not see traffic from the vSphere client, normal browser traffic is visible. Any tips on hohw to configure Burp to see the traffic between the vSphere Client and the ESXi host?
My concern is that in the future the soap commands may change so the scripts will need to be updated to continue to work.
Cheers
Simon
Hi Simon, it’s easiest to run Burp on another computer.
Go to Proxy, Options, remove anything that’s there and enter 443 in the local listener port, check support invisible, redirect to host (ip of esxi host management interface), redirect to port 443, use self-signed, then click on add. Check running is ticked on the top left and that should start the listener. Then go to the intercept tab and set the intercept to off.
You will also need to open 443 on the firewall of the box running burp.
Once that’s all done you should be able to start vSphere client and enter the IP of the box running Burp as the host, and use the normal username and password.
I’ve since wrapped up this and other functionality into a perl script which should be a bit more robust (although it needs vmware’s vCLI installed) – search for esxi-control.pl.
Hope that helps.
Ah, I was attempting to run Burp for the same machine as the vSphere client. I have it working now.
Thanks so much for the tips and your work on this solution, it’s all very appreciated.
Cheers
Simon
I have issue executing batch file from withing powerchute command line. Service is ran under local admin or domain admin and it will not execute any batch file. Anyone knows why? Spent 2 hours on phone with APC and they couldn’t find any answers. FYI, the low battery event triggered on the managment card shows up in powerchute, but again it doesn’t trigger the batch.
Hi, in my experience problems tend to be either that the path must be in 8.3 format or some kind of permissions or path issue. It might be worth adding “echo Started >log.txt” as the first line of the batch file, so you can be sure it is or isn’t running. HTH
Hi James.
I’m looking at shutting down an ESXi box and a FreeNAS box.
Do you see any issues or know of any that I may encounter by setting this up?
I have a Powerware 5110 (I’ve had for a couple of years) I’d hoped to use for the FreeNAS, but haven’t been able to get FreeNAS to find the USB port the UPS is plugged into, so have kind of given up on that UPS. On top of that, it’s probably to small to use to shutdown vm guests.
So I think the best option for me may be to find a second hand APC Smart-UPS 1000 or greater and fit it with a network management card.
Thoughts?
Hi James,
thank you for the awesome script.
But I still have a question: doesn’t a “poweroff” command sent by ssh to the ESXi host do the same graceful shut down – assuming that the VMs are shut down gracefully by the host itself?
Hi, yes indeed SSH can be used. But having looked at the underlying SOAP communication, this opened lots of other possibilities – search online for ‘esxi-control.pl’.
Great post. Someone has tested it on vSphere 4.1?
Hi, yes it will work, but this has been superceded by esxi-control. Cheers!
Hi James.
You don’t seem to be issuing a maintenance mode command in amongst your (hello, authenticate, and shutdown)
Is there a reason for this, or have I just missed it?
It states here http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1013193
“From vSphere Client
Before shutting down or rebooting the ESX 4.0 or the ESXi 4.0 hosts, ensure that the hosts are put in maintenance mode.”
Hi Kim
You are right, the script doesn’t put the host in maintenance mode. I’m assuming that the controlling function (VM) will be running ON the ESXi host being controlled, hence maintenance mode is not considered (as it couldn’t be entered with the controlling VM running, and we’re relying on the auto start to wake up the VMs once power is restored).
Also – the script is superceded by esxi-cotnrol.pl – Google on that for further info.
Hope that helps!
I’ve obtained an ap9606 on your advice.
Trouble is… I’m not sure of it’s subnet address, let alone it’s IP address.
An arp -s [new ip] [existing mac] doesn’t help, as the ap9606 is obviously not on the same subnet.
The lights on the card are both green, so it obviously already has an ip set.
I don’t have a serial cable for the smart-ups, so Ethernet is my only option.
I’m hoping nmap may be able to help me find the IP via a sweep for the MAC’s?
Any other options anyone can think of?
Thanks.
Hi, the procedure is to find the card MAC address (see label on the card), then plug it in and let it boot. Next, reset the card (using a paper clip to press the reset button), then either use arp -s to create a static entry for it and access it via that IP, actually I think it also then has a default IP like 192.168.0.1 or 192.168.1.1 or 192.168.1.254 (sorry can’t recall exactly!).
See page 10 on of the AP9606 manual (here) and some notes here.
Another option is to use the configuration wizard, which should be downloadable from apc.com.
Once you have telnet access, you’ll need to load the UPS firmware on it.
Hope that helps!
Yeah, did all that.
Problem is, the IP was already set and using a different subnet mask to my LAN.
Can see the IP is set by the green light on the card.
Without being on the same subnet as the AP9606 there is no way of knowing what the cards IP is.
Not even nmap could tell me unless I knew the subnet.
Re-assigning an IP using arp doesn’t take either.
I plugged the AP9606 into my notebook and ran wireshark.
This told me what the cards IP was. as the AP9606 sends a packet aprx every minute.
I’ll be making a post of all this on my blog once I’ve completed everything.
Once I found the IP, I just took a guess at the subnet mask it was /24.
and assigned a temporary static IP and changed my notebooks subnet to match that of the cards.
I could then telnet to the card and receive login prompt.
An arp assignment still wouldn’t take though, so I’m guessing I need to log into the card to change it.
Only problem is now… I don’t have the password, but that’s another problem I’m dealing with now.
I contacted APC support for the backdoor credentials, and it looks like you need the special serial cable for this.
Which is aprx $100NZ, a little to much for a single use cable.
I requested the pin layout and was told that they make the cables, but did not have the layout information (not sure how they would make the cable without knowing the pin config).
If I can’t find the credentials (non default (not apc/apc or User/apc)) then I still have options.
Make up a serial cable with I believe…
Pin#2 Female to Pin#2 Male,
Pin#3 Female to Pin#1 Male,
Pin#5 Female to Pin#9 Male,
and find a computer with a com port.
Layout info found here http://www.tek-tips.com/viewthread.cfm?qid=522564&page=1
Hopefully it’s correct.
That would cost next to nothing.
Or…
just crack the credentials with one of these http://sectools.org/crackers.html
I don’t know if this applies to the AP9606 but it might be worth a go:
“5.) Press the Reset button. Wait 5-7 seconds and the Status LED will flash rapidly while alternating between orange and green. Press the Reset button a second time immediately while the LED is rapidly flashing – which will cause the LED to then go off – in order to reset the User Name and Password to their defaults temporarily (the default User Name and password are both apc).”
Yeah, I saw that.
I’m picking this only happens if the serial cable is plugged in.
As the experience I’ve had… There is only green lights (mostly solid).
When I reset the card, the light on the right (I think) goes out for a few seconds then it’s on solid again, that’s it.
I did try the pressing the reset the second time while the light was out, with no apparent effect.
If I have to resort to making up a serial cable, I’ll try this though.
Cheers!
Ok, so hydra tells me the telnet user name is n/a and password is steven.
I’m assuming somehow that means there isn’t a user name.
Any idea how to get past the user name prompt, as it doesn’t allow a blank username?
Got past all this, with a db-9 equipped 3 core cable.
Details will be in my blog post once done.
Thanks for the details James, your name has popped up a fair bit as I’m googling my way through ESXi management!!
I find your posts great as the commands are step by step and you give syntax that I can adapt from my environment.
The link to your esxi-control.pl script is returning nothing and a search on your site gives nothing by this name, is it still available?
Cheers
nothing less than brilliant.
could you post a valid link for esxi-control.pl ??
Can’t say I’ve been able to find esxi-control.pl either, looks like it has disappeared from peacon’s site 🙁 Will give the original batch scripts a go later.
Love your site btw, has been very helpful in getting ideas / sorting out my home esxi server so far 🙂
Hi,
Does this work with the new Vmware Vsphere ESXi 5? Has somebody tested it?
Hi, has someone found new links for esxi-control.pl?
Thx a lot!
Pleased to see this script!
is there an easy way to call multiple boxes??
I must be missing something.
I’ve tried the following
*****************************************************************
@echo off
c:scriptsesxishutdown ipaddress1 [username] [password]
c:scriptsesxishutdown ipaddress2 [username] [password]
******************************************************************
only the first line is completed, the script ends prior to the 2nd line being run. I’ve also tried with a timeout 30 between lines 2 and 3.
any ideas??
Thanks,
John
I’m having the same problem – the fist line executes, the second one does not.
Is there any solution for this? Or do I need to set up a 2nd VM for that purpose?
Thank you,
Matthias
Hi, try “call c:scripts….”, HTH!
Thanks,
spent way too much time looking at the screen and trying to decide to go the Perl route or this one.
This script works for me on 4.0, 4.1 and 5.0 so far.
John
Hi!
I try to use this script with my ESXi 4.1 and from Windows host (Windows 2008) on ESXi server scrupt works. But if a try to run this script from other Windows (XP SP3) machine, connected to same UPS (APC 1500) like ESXi hos tis, then i get this error, when i try to run poweroff.bat:
C:scriptsesxi>poweroff.bat
System shutdown called: pon 30.04.2012 15:57:42,92
Unexpected call.
What is wrong? I copy ncat.exe to %WINDIR%, also all files are located in default directory: c:scriptsesxi
PLease, any hint would be apreciated?
Thank you!
Same problem as you Bosco, but I’m experimenting this issue in Windows Server 203
Just install apcupsd on the esxi host if you are looking for a simple solution. Its a daemon for a USB/Serial/SNMP-connected APC that shuts down any Unix/Windows machine. However, you’ll still need some script to suspend the machines.
This is very handy. In my case it does shut down the ESXi host and vms but even if I enable the ““Turn off the UPS after the shutdown finishes” setting” it does not shut down the UPS. I also followed the steps here http://blog.rebelit.net/?p=118#comment-1175, same thing.
Am I missing something, should I be able to shut the UPS down, or do I have to let the battery die?
This looks like exactly what we are after – I have some remote sites that I look after that I am rolling out new kit to. So I’m using esxi free to give me flexabilty on recovery etc – I have the USB pass thru working so can shut windows VM down, but I can’t shut the host down.
The Host is esxi 5 free so can’t use vCLI that can shutdown the paid for licensed hosts – I’ve tried this script and after a bit of faffing to get nmap working (installing c++ redist and copying the wow 64 version of the dll into the same folder as nmap) I get a ‘cannot connect to host actively refused’ is it a non starter for esxi 5?
It works great for me with ESXi 4.x. I don’t use the UPS signal so what I do is have a cron script that polls some devices on the network (Router, WAP and Lan NAS server). I know that my UPS battery lasts for 30-40 minutes. If ALL of these non-ups devices fail to respond to a ping for 20 minutes then I assume that power is out and shut down the ESXi server. This may sound like a strange way to do it but it works great for me.
Also – I use cygwin so the ‘find’ in the script would invoke the cygwin find instead of the Windows ‘find’ so I modified the script and set FIND=/find.exe and then replaced find in the script with %FIND%.
I’ve been looking for something like this for a while but most other solutions seem far too complicated. This is perfect – thank you very much.
great idea! thanks – I’ll try that…
Looks, like using the APC AP9606 network card would be an optimal choise.
Tested on ESXi (free license) 5.5. Worked like a charm. I’m amazed 🙂
Guest VMs are correctly shut down, everything is perfect.
I haven’t tried this yet, but will try it out soon.. Very clever!..
I was thinking about another option instead of Powerchute to detect the power outage.. and it could be done with an Arduino + network shield.. If the arduino is powered by a UPS, and also a regular dc power adapter is connected directly to the wall outlet just to detect if there’s power or not (google: arduino detect power outage), then through a simple web page arduino could report if it’s detecting power or not from the wall outlet.. From a cron process, the arduino web page could be monitored.. and if it’s reported that there’s no power for more than x minutes, then the esx shutdown process could be initiated..
cheers!
Thanks for your share Expirence
Does it running as well with ESXi 5.5 free license ?
Hi,
Great job Techhead Team, I’ve been looking for this for some time.
I’m having a problem where the guest/s don’t get time to shut down gracefully before the host powers down. This is testing the command only, I have taken the ups out of the equation for now.
Thanks.