+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
Thin Client and Virtual Machines Thread, Shutdown ESXi Server in Technical; I've utilised a script to shutdown my ESXi server when the APCUPSD program tells it the power has gone. I've ...
  1. #1

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242

    Shutdown ESXi Server

    I've utilised a script to shutdown my ESXi server when the APCUPSD program tells it the power has gone. I've got it working pretty neatly on a Nagios box (VM on the ESXi server).

    Basically, the nagios box monitors the UPS using APCUPSD. When the power goes it runs a local shell script that connects and runs a script via SSH to the ESXi box (unsupported mode) - the script it runs is stored on the Datastore of the ESXi box that then proceeds to shutdown all VM's and then finally the ESXi server.

    The problem I have though, is by running the script via SSH - the script runs in the nagios box (for all it is hosted on the ESXi server) so therefore it might shutdown 3 out of 5 VM's and then the nagios box (as it is a VM). This leaves a VM online as well as the physical ESXi server (as the nagios box controlling the shutdowns has turned off and therefore cannot carry out any more commands).

    Hope I've explained this clear enough. Anyhow, long story short is, how do I tell ESXi to run a script instead of having the nagios VM run the script that is hosted on the ESXi server?


    ARGHHHHHHHHHH

  2. #2

    Theblacksheep's Avatar
    Join Date
    Feb 2008
    Location
    In a house.
    Posts
    1,964
    Thank Post
    139
    Thanked 291 Times in 211 Posts
    Rep Power
    193
    Quote Originally Posted by Hightower View Post
    I've utilised a script to shutdown my ESXi server when the APCUPSD program tells it the power has gone. I've got it working pretty neatly on a Nagios box (VM on the ESXi server).

    Basically, the nagios box monitors the UPS using APCUPSD. When the power goes it runs a local shell script that connects and runs a script via SSH to the ESXi box (unsupported mode) - the script it runs is stored on the Datastore of the ESXi box that then proceeds to shutdown all VM's and then finally the ESXi server.

    The problem I have though, is by running the script via SSH - the script runs in the nagios box (for all it is hosted on the ESXi server) so therefore it might shutdown 3 out of 5 VM's and then the nagios box (as it is a VM). This leaves a VM online as well as the physical ESXi server (as the nagios box controlling the shutdowns has turned off and therefore cannot carry out any more commands).

    Hope I've explained this clear enough. Anyhow, long story short is, how do I tell ESXi to run a script instead of having the nagios VM run the script that is hosted on the ESXi server?


    ARGHHHHHHHHHH
    Using the free version of ESXi?
    vSphere - ESX 4u1?

    (you can see where this is going- few features removed inc rcli from ESX 3.5)
    Last edited by Theblacksheep; 22nd February 2010 at 05:25 PM.

  3. #3

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,821
    Thank Post
    272
    Thanked 1,140 Times in 1,036 Posts
    Rep Power
    351
    The way we had it set up was, the UPS sent the shutdown signal to all the VM's including the linux box. once the linux box received the signal it told the esxi box to shut down in like 10 mins (plent of time for vms to shutdown). but when it told the esxi box to shutdown it set itself to shutdown in 7 mins so the linux box was shutdown before the esxi box went.

    Does that make sense?

    it does require the APC addon ethernet card.

  4. #4

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    Quote Originally Posted by glennda View Post
    The way we had it set up was, the UPS sent the shutdown signal to all the VM's including the linux box. once the linux box received the signal it told the esxi box to shut down in like 10 mins (plent of time for vms to shutdown). but when it told the esxi box to shutdown it set itself to shutdown in 7 mins so the linux box was shutdown before the esxi box went.

    it does require the APC addon ethernet card.
    This is how our script works - but in order to shutdown the VM monitoring the UPS it needs to be run from the ESXi host. Our script also checks to make sure all VMs are powered off before turning off the ESXi host, instead of your more basic timer. We want it this way because we are hosting a mail server on one VM which can take some time to shutdown. We need to make sure it's off before the host goes down (not just guessing with a timer) because if it doesn't get shutdown properly it can be a bugger to recover.

    BTW - we have the network card for the UPS. All thought of when bought

    Quote Originally Posted by jinnantonnix View Post
    In my old vmware system, I wrote a little bash script that ran on the vmware host. It checked for a flag file (which was placed on a machine somewhere over NFS - the detail escapes me) and if it saw the file it would start a shutdown.
    Hmmmmm, that could be one solution if I can't do it my way.

    Quote Originally Posted by Theblacksheep View Post
    Using the free version of ESXi?
    vSphere - ESX 4u1?

    (you can see where this is going- few features removed inc rcli from ESX 3.5)
    I don't think this affects it. I know the free version has features removed, but my shutdown script works perfectly when run from the ESXi host. It shuts down all VMs and then finally the host.

    All I need to do is find a way to:

    1) UPS loses power. SNMP tells Ubuntu VM that power has gone (WORKING)
    2) ESXi host has script to shutdown VMs and host. This works when run physically logged into host via SSH
    3) I need the Ubuntu VM to say "power has gone, please run this script"

    At the minute Ubuntu VM is actually running the script itself, which is not what I want. I need Ubuntu VM to tell ESXi host to run the script.

    Sorry if this isn't clear - finding it hard to get my thoughts into words.

  5. #5

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,821
    Thank Post
    272
    Thanked 1,140 Times in 1,036 Posts
    Rep Power
    351
    i no its not ideal but old pc attached to the ups that doesn't matter if it shutdowns via power loss, you could set it to remotely execute the script on the esxi host. not quite the way you want it, but if all else fails!

  6. #6
    Duke's Avatar
    Join Date
    May 2009
    Posts
    1,017
    Thank Post
    300
    Thanked 174 Times in 160 Posts
    Rep Power
    58
    Anyone else think VMware should have better UPS support built in? It's kind of an important area, and what I'd really like is the ability to Vmotion my VMs to a different server room if the ESX host notices that it's going to lose power from the UPS. The ability to detect UPS status and write action rules accordingly would be very useful. I emailed VMware about this a couple of weeks ago an didn't even get a reply.

  7. #7

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    Quote Originally Posted by glennda View Post
    i no its not ideal but old pc attached to the ups that doesn't matter if it shutdowns via power loss, you could set it to remotely execute the script on the esxi host. not quite the way you want it, but if all else fails!
    That's kind of what I want, but using a VM instead of an actual physical machine. I just need to know how to "SSH into the ESXi and run the script from the ESXi host"

  8. #8

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,821
    Thank Post
    272
    Thanked 1,140 Times in 1,036 Posts
    Rep Power
    351
    but would the ssh session running the script not fail if the vm has shut down?

  9. #9

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    Quote Originally Posted by glennda View Post
    but would the ssh session running the script not fail if the vm has shut down?
    That's my dilemna

    I need to get the VM that monitors the UPS status to tell the ESXi host to run the script, rather than having the VM run it via an SSH session.

  10. #10

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,821
    Thank Post
    272
    Thanked 1,140 Times in 1,036 Posts
    Rep Power
    351
    Quote Originally Posted by jinnantonnix View Post
    It wouldn't matter - the ESX has started a shutdown - this can't be stopped. It does a graceful shutdown of all VMWare services first, then shuts down the hosting OS.
    yes, but if you run a script that shutsdown the vm's including the one that is running the script, while it is waiting to see if all the vm's have shutdown then the esxi host will not shutdown properly

  11. #11

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    Quote Originally Posted by jinnantonnix View Post
    It wouldn't matter - the ESX has started a shutdown - this can't be stopped. It does a graceful shutdown of all VMWare services first, then shuts down the hosting OS.
    It does matter. The ESX hasn't initiated a shutdown of itself yet.

    The script starts a shutdown (via VMWare Tools) of each VM, and each minute checks to see if any are online. Once they have all shutdown the ESXi server then proceeds to shut itself down (still reading from the script here).

    Now, when the script is run from the ESXi host (which is what I'm trying to achieve) the shutdowns work perfectly.

    However, when run from a VM on the ESXi host the VM actually gets shutdown, thus stopping the last part of the script from running which shuts down the ESXi host.

  12. #12

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,821
    Thank Post
    272
    Thanked 1,140 Times in 1,036 Posts
    Rep Power
    351
    Quote Originally Posted by Hightower View Post
    It does matter. The ESX hasn't initiated a shutdown of itself yet.

    The script starts a shutdown (via VMWare Tools) of each VM, and each minute checks to see if any are online. Once they have all shutdown the ESXi server then proceeds to shut itself down (still reading from the script here).

    Now, when the script is run from the ESXi host (which is what I'm trying to achieve) the shutdowns work perfectly.

    However, when run from a VM on the ESXi host the VM actually gets shutdown, thus stopping the last part of the script from running which shuts down the ESXi host.
    maybe just sent up another linux box with no resources but enough to send the shutdown signal and the just let it get powered off. as vmware don't support the ups until that happens we could be coming up with all sorts of querky ideas to try!!

  13. #13

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,821
    Thank Post
    272
    Thanked 1,140 Times in 1,036 Posts
    Rep Power
    351
    Quote Originally Posted by jinnantonnix View Post
    OK, I'm not too familiar with the the free ESXi, but I do know in vsphere you can configure the machines to shutdown their OS when they get a power down signal. Can you do this? If so, all you need to to is execute an init 0 command on the ESX host.
    problem is the vm will have shut itself down, so the vm cannot send the shutdown signal!

  14. #14

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    I think the way to go is a flag file, so:

    1) VM monitoring UPS gets power loss signal
    2) VM creates files called 'shutdown' on NFS share
    3) ESXi monitors NFS share for 'shutdown' file and initiates shutdown sequence if it finds it
    4) All machines gracefully shutdown, including ESXi host. When VM that monitors shutdown goes down it deletes the 'shutdown' file (as shutdown is already started on all VM's) so that when they get turned back on they don't get shutdown again and again etc.

    This looks like the way forward. Just got to get ESXi to keep checking for the file....

  15. #15

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    How do I go about mounting an NFS share in ESXi?



SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. ESXi Server
    By Danlewis3 in forum Thin Client and Virtual Machines
    Replies: 17
    Last Post: 17th February 2010, 03:40 PM
  2. VMWare ESXi - convert physical win2k3 server : Tips?
    By contink in forum Thin Client and Virtual Machines
    Replies: 21
    Last Post: 13th December 2009, 03:53 AM
  3. Server shutdown
    By KWestos in forum Windows Server 2000/2003
    Replies: 4
    Last Post: 6th July 2009, 12:11 PM
  4. ESXi disk setup for SQL server VMs - advice sought
    By fox1977 in forum Thin Client and Virtual Machines
    Replies: 2
    Last Post: 29th January 2009, 12:34 PM
  5. ESXI or Server?
    By TechSupp in forum Thin Client and Virtual Machines
    Replies: 4
    Last Post: 22nd January 2009, 08:42 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •