Today, the first time for a long while, I am again in the need to make a scheduled shutdown of a physical ESXi server. Strangely it seems that this function disappeared out of the vSphere Client. I'm pretty sure, it worked with one of the first VirtualCenter versions. But after a bit of research I found some hints about the vSphere CLI SDK. After a bit of testing I figured out how it works and it works just great. Now I'm able to schedule a cronjob, launching the reboot or shutdown command fully automated. To be able to shutdown or reboot, you have to enter maintenance mode. The command looks like this:
/usr/lib/vmware-vcli/apps/host/hostops.pl --server VCENTER_SERVER --target_host NAME_OF_ESX_HOST --operation enter_maintenance --username VCENTER_USER --password VCENTER_PASSWORD
Note, that for the --target_host you mustn't use the IP-address of the ESX/i server but the name used in the VirtualCenter configuration (as you see it in your vSphere Client). Now we make the same for the shutdown command:/usr/lib/vmware-vcli/apps/host/hostops.pl --server VCENTER_SERVER --target_host NAME_OF_ESX_HOST --operation shutdown --username VCENTER_USER --password VCENTER_PASSWORD
Commandline baby!ck from Switzerland wrote on Nov 8th, 2014:
Hi J. The ESXi server will only go into maintenance mode, once all running VMs were migrated or powered off. You can edit the VM settings to handle automatic power off and start up: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=850
J from home wrote on Nov 8th, 2014:
but if u want the vm to start automativly and to reboot the host you need to but the vm in maintence mode , thats not going to work is it.
can u add reference on how to restart the host and the vm automaticly aswell ?
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Office OpenSearch PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder