Originally Posted by
ian-weisser
/etc/init/lightdm.conf emits desktop-shutdown.
Perhaps a pre-stop stanza there?
I am very happy to report success.
First, I created the script /home/<user>/Script/vmhalt:
Code:
#!/bin/bash
# set primary variables
credentials="/path/to/credentials/file/.vmcred"
if pgrep -x vmware-vmx > /dev/null 2>&1; then
# send vm shutdown signal with user credentials
source "$credentials"
net rpc shutdown -I "<vm>" -U "$unpass" #unpass defined in credentials file
# wait 5m for vm shutdown.
counter=1
while pgrep -x vmware-vmx > /dev/null 2>&1; do
sleep 5
if [ $counter -ge 60 ]; then
break
fi
counter=$[counter + 1]
done
fi
exit 0
Next, I edited /etc/init/lightdm.conf. Directly underneath the line "emits desktop-shutdown" I added:
Code:
pre-stop script
exec sudo -u <user> /home/<user>/Script/vmhalt
end script
The result is that any shutdown (graphical, shell or remote) will hold the desktop open, wait for the virtual machine to shutdown gracefully, and then continue with a normal shutdown.
Bookmarks