VMware Cloud Community
joboo12
Enthusiast
Enthusiast
Jump to solution

RCLI Command required to shutdown ESXi Host

I have searched through the RCLI docs and can not seem to find the command that will shut down an ESXi host. Can someone provide this?

Thanks

John

Reply
0 Kudos
1 Solution

Accepted Solutions
Dave_Mishchenko
Immortal
Immortal
Jump to solution

There's another copy of the script in \Perl\apps\host that works. I had to enter maintenance mode first and then could shutdown the host. I was running this against an ESXi host directly (no VC server). See the syntax in the attached image.

Have you considered the Powershell toolkit for this as an alternative? It might be a little less awkward.

View solution in original post

Reply
0 Kudos
12 Replies
Troy_Clavell
Immortal
Immortal
Jump to solution

I don't know if the RCLI has this command or not, but try

shutdown -h now

Reply
0 Kudos
Dave_Mishchenko
Immortal
Immortal
Jump to solution

Give hostops.pl a try - you'll find it in VMware VI Remote CLI\Perl\samples.

If it's a test system and you have SSH enabled then you can use /sbin/poweroff (and there is also /sbin/reboot).

Reply
0 Kudos
HenrikElm
Contributor
Contributor
Jump to solution

What happens to VMs when you issue one of these commands?

Cool that you can enable SSH with ESXi ..

Best regards

Henrik

Reply
0 Kudos
balacs
Hot Shot
Hot Shot
Jump to solution

What happens to VMs when you issue one of these commands?

Depends on how the VMs are configured. VMs can be configured to do a graceful shutdown. By default, I think they are configured for a power-off. You can configure this by selecting the server in VI Client > Configuration tab > Virtual Machine Startup/shutdown.

Bala

Dell Inc

Bala Dell Inc
Reply
0 Kudos
joboo12
Enthusiast
Enthusiast
Jump to solution

Well it deifnitly seems to be the right script. However when I run the script with the appropriate variables I get this:

"Undefined subroutine &main::shutdown called at C:\Program Files\VMware\VMware VI

Remote CLI\Perl\samples\host\hostops.pl line 102."

Here is the full command line I'm using:

hostops.pl --username xxxxx --password xxxxx --host xxxxx --operation shutdown

Reply
0 Kudos
Dave_Mishchenko
Immortal
Immortal
Jump to solution

There's another copy of the script in \Perl\apps\host that works. I had to enter maintenance mode first and then could shutdown the host. I was running this against an ESXi host directly (no VC server). See the syntax in the attached image.

Have you considered the Powershell toolkit for this as an alternative? It might be a little less awkward.

Reply
0 Kudos
joboo12
Enthusiast
Enthusiast
Jump to solution

That did the trick. However I noticed a few things that may prevent me from using the script:

1) --target_host variable will only accept FQDN.

2) You MUST execute the enter_maintenance operation prior to shutdown. My intent is to create a script to shutdown resources during a power outage. Once the power comes back on the servers will still be in maintenance mode and therfore will not start associated guests automatically on restart. I'm wondering if I just shutdown the guests and let the servers just power off when the battery runs down? Looks like there would be minimal risk to the ESXi OS.

Thanks

Reply
0 Kudos
HenrikElm
Contributor
Contributor
Jump to solution

2) Yes, that was the reply I got at the VMWare booth at MS TechEd in Orlando. Use traditional script to shut down guests, then let the hosts just die.

/H

Reply
0 Kudos
Ritmo2k
Enthusiast
Enthusiast
Jump to solution

Joboo12,

Did you ever figure out a way to do this?

Reply
0 Kudos
SomeoneSomewher
Contributor
Contributor
Jump to solution

Turn out you can but you need to slghtly edit VMware VI Remote CLI\Perl\samples\hostops.pl

The function call for shutdown is wrong on line 22:

"shutdown => \&shutdown," should be "shutdown => \&shutdown_host,"

Then change line 236: "$host->ShutdownHost(force => 0);" to "$host->ShutdownHost(force => 1);"

Host will then suspend all vms and shutdown gracefully, when power is returned assuming the server and vms are configureed to come up again all is good.

For a standalone ESXi box without VCenter I use the command:

hstops.pl --host <FQDN to Host> --server <FQDN to Host> --username **** --password **** --operation shutdown

Hope this helps someone

Reply
0 Kudos
HenrikElm
Contributor
Contributor
Jump to solution

Ah! Yes! It works very well. I also tweaked the .pl script to only do a shutdown of the host with no suspend done. This way it behaves exactly like you have set it up with autostart/shutdown.

Nice!

/Henrik

Reply
0 Kudos
dozentmi
Enthusiast
Enthusiast
Jump to solution

Is it wroking to ESXi 4.1 free?

Reply
0 Kudos