VMware Cloud Community
MarkusAngerer
Contributor
Contributor

Automatic exit of maintenance mode after ESXi startup

Hi,

at the moment I'm playing a bit with a single ESXi 4 server and I came to one problem I could not yet find a solution to:

When I use vSphere CLI to reboot the host I need to enter maintenance mode and then reboot.

hostops.pl --operation enter_maintenance http://...

hostops.pl --operation reboot http://...

it automatically leave the maintenance mode and restarts fine.

If I try the same but shutdown the host it is still in maintenance mode after a restart. Is there any way to have it in normal operation after the boot-up?

Background: I'm thinking of switching some of your VMware Server 1.0.9 vm's to a new ESXi box. But if we have a power cut I need to shut down the host and after power is restored I'd like the server to start up again. It does not help much if it is booting up but does not execute any vm because of maintenance mode. Do I have missed something in my thoughts? Do I need to use other tools than vShpere CLI?

Thanks! Markus

Reply
0 Kudos
5 Replies
bulletprooffool
Champion
Champion

Hi Markus,

The host will not exit Maintenance mode until you instruct it to - this is by design, as you would want your host to remain in maintenance mode until patching etc is complete.

you could in your script, enter maintenance mode . . then instead of shutting down, Exit maintenance mode and then shut down before any VMs move back to the host.

It is OK to shut down a host that is not in maintenance mode - as long as you have shut down all your VMs (or migrated them)

The other option is to change your script to shut down all your VMs, then shut down - without going to maintenance mode?

One day I will virtualise myself . . .
Reply
0 Kudos
MarkusAngerer
Contributor
Contributor

Thanks for that!

My current test environment is an ESXi as a virtual machine in VM Server 1. Just the host, no additional VMs on it - so nothing that needs a shutdown there. I tried to shut down the host without maintenance mode but always get a message like "operation not supported in current state" (sorry I dont have the exact wording as a I'm not in the office anymore). Once I switch to maintenance mode the exact same command does shut down:

hostops.pl --username root --operation shutdown --url --target_host localhost.localdomain --suspend 1

Do you think I need a different command or tool? To be honest, I'm a bit lost with all these different tools and their different names with every new version.

Markus

Reply
0 Kudos
lamw
Community Manager
Community Manager

The reason for this is the function itself has an option to do a force shutdown/reboot and by default the hostops.pl script does not do a forceful shutdown/reboot. That is why you need to suspend your VMs and by default if it finds powered on VMs and you're not suspending them, the script will not execute through.

RebootHost_Task() http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.HostSystem.html#reboo...

ShutdownHost_Task() http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.HostSystem.html#shutd...

You can definitely write your own shutdown/reboot script that does exactly what you want, whether that is to forcefully shutdown/reboot the host, or suspend your Vms automatically and then reboot/shutdown. The force is what is forcing you to put the host in maintenance mode, so that can be easily overwritten.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

Twitter: @lamw

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
MarkusAngerer
Contributor
Contributor

Hi William,

I found a script written by yourself: ghettoShutdown.pl which does exactly what I'm looking for. Thanks for publishing it!!

Just for me to understand a bit better: VMware's hostops.pl uses a command target_host->ShutdownHost(force => 0); and your script uses (force => 1);

Does that make the difference I was initially looking for?

Thanks, Markus

Reply
0 Kudos
lamw
Community Manager
Community Manager

np. Don't forget to award 'helpful' or 'correct' points Smiley Wink

Yes it makes all the difference, since by default a host will not shutdown/reboot without going into maintenance mode first, of course this can be overwritten but by default it does not. Even though the script power's off all VMs, it will not shutdown/reboot w/o going into maintenance mode first, and that's where you could use force = 1 which just says, okay go for it.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

Twitter: @lamw

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos