Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Commit

Permalink
add a logout hook for osx
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Zogg committed Jun 8, 2015
1 parent c3f1d12 commit 2a5dc51
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -26,6 +26,11 @@ Host *.dev
ForwardAgent yes
```

## MacOSX supend the running machinse on user logout (shutdown)

Copy the files `tools/vagrant-suspend` to `/usr/local/bin/vagrant-suspend` and register the logout hook with:
`sudo defaults write com.apple.loginwindow LogoutHook /usr/local/bin/vagrant-suspend`

## Symfony modification

### Update your app/AppKernel.php
Expand Down
23 changes: 23 additions & 0 deletions tools/vagrant-suspend
@@ -0,0 +1,23 @@
#!/usr/bin/env php
<?php

// sudo defaults write com.apple.loginwindow LogoutHook /usr/local/bin/vagrant-suspend

$user = exec('stat -f \'%Su\' /dev/console');

echo sprintf('User: %s', $user);
$output = array();
$command = sprintf('sudo -u %s VBoxManage list runningvms', $user);
echo $command . "\n";
exec($command, $output);

foreach($output as $line) {
$matches = array();
if(preg_match('/{([^}]+)}/', $line, $matches) !== 1) {
throw new \Exception(sprintf('Can\'t parse the following line: %s', $line));
}
$command = sprintf('sudo -u %s VBoxManage controlvm %s savestate', $user, $matches[1]);
echo $command . "\n";
exec($command);
echo 'done' . "\n";
}

0 comments on commit 2a5dc51

Please sign in to comment.