In a previous question, I found out how to shut down all instances of running VMs started through vagrant. I'd like to call that script when logging out of my Desktop Manager which is currently Cinnamon.
Some have pointed to another similar similar, but I did not understand the selected answer(s) enough to be able to solve my issue and put anything into action. The comments below point to start on stopping lightdm
. This sounds like what I'm looking for. That is how can I run a script to stop all VMs (called: stop-vagrant.sh) when my log out of my desktop manager (start on stopping lightdm
)?
What you need to do is create an Upstart job. Let us say your script for stopping VMs is available at
/some/path/vagrant-stop.sh
.Depending on the exact nature of your VMs (are they run only when you're logged into a GUI, or are they run when the system starts up, etc.), you could use either a System job or a Session job. For the case where the VMs are run only when you're logged into a GUI, you can use a session job, a simple example of which I'll present here:
Create a file in
~/.config/upstart
with a.conf
extension (use your favourite editor):The content would be:
Run
initctl check-config
to see if there are any errors.Now, you can stop your VMs with (pardon the phrasing):
Upstart will automatically run this when you log out.