An interesting set of scripts from [Wayback/Archive.is] No Joke IT: Graceful shutdown of an ESXi 5.1 host and guest VMs (free edition) using the shell/command line/scripting (UPS friendly).
If all ESXi virtual machines support running of VMware Tools, then the solution is a plain /sbin/shutdown.sh && /sbin/poweroff
(see [Wayback/Archive.is] No Joke IT: Shut down ESXi 5.1 guest VMs and the host (free edition) via SSH – the easy way!).
Code is in the repository at [Wayback/Archive.is] sixdimensionalarray/esxidown: A shell script to shutdown VMware ESXi host servers, with these two main files:
- [Wayback/Archive.is] esxidown/async.sh at master · sixdimensionalarray/esxidown
#!/bin/sh # Runs a shell command asynchronously. if [ "$1" != "" ]; then nohup sh $1 > /dev/null 2>&1 & fi
- [Wayback/Archive.is] esxidown/esxidown.sh at master · sixdimensionalarray/esxidown with this interesting code fragment right before the script finishes:
# exit maintenance mode immediately before server has a chance to shutdown/power off # NOTE: it is possible for this to fail, leaving the server in maintenance mode on reboot! echo "Exiting maintenance mode..." if [ $TEST -eq 0 ]; then esxcli system maintenanceMode set -e false -t 0 fi
Note: the No Joke IT web-site has vanished, so only the [Wayback] and [Archive.is] links of it still work. The github code was still there at the time of writing.
Via: [Wayback] Solved: Read only Files – VMware Technology Network VMTN
Related: Some notes on replacing parts of a text file with template text using sed on a Busybox system.
–jeroen