Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pr3sto/vagrant-state-change-listener
Vagrant plugin for monitoring vm state changes and executing actions on changes
https://github.com/pr3sto/vagrant-state-change-listener
vagrant vagrant-plugin
Last synced: about 1 month ago
JSON representation
Vagrant plugin for monitoring vm state changes and executing actions on changes
- Host: GitHub
- URL: https://github.com/pr3sto/vagrant-state-change-listener
- Owner: pr3sto
- License: mit
- Created: 2018-05-06T21:04:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-17T07:57:46.000Z (about 6 years ago)
- Last Synced: 2024-09-06T02:49:26.574Z (3 months ago)
- Topics: vagrant, vagrant-plugin
- Language: Ruby
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vagrant-state-change-listener
Vagrant plugin for listening vm state changes and executing actions on changes.[![Gem Version](https://badge.fury.io/rb/vagrant-state-change-listener.svg)](https://badge.fury.io/rb/vagrant-state-change-listener)
## Installation
```console
foo@bar:~$ vagrant plugin install vagrant-state-change-listener
```## Usage
Use **listen-state-changes** command to listen vm state changes. When state is changed (e.g., from *running* to *stopped*), command executes given actions (shell commands).
### Command syntax
```console
foo@bar:~$ vagrant listen-state-changes [options]
```**\** - name of virtual machine
**\** - shell commands to execute after state change
### Options
**-f (--first-state) FSTATE** - If vm changes it's state from FSTATE, plugin executes **\**
**-s (--second-state) SSTATE** - If vm changes it's state to SSTATE, plugin executes **\"**
**-l (--latency SECONDS)** - Delay (in seconds) between checking for changes. Default: 1 sec
**-a (--auto-stop)** - Stop listening after first state change (after executing **\**)
### Examples
```console
foo@bar:~$ vagrant listen-state-changes default 'echo Changed!'
```When vm with name *default* changes it's state, *Changed!* is printed to console. Terminal is blocked until the user manually terminates command
---
```console
foo@bar:~$ vagrant listen-state-changes default 'echo Changed!' -a
```When vm with name *default* changes it's state, *Changed!* is printed to console and command terminates
---
```console
foo@bar:~$ vagrant listen-state-changes default 'echo Changed!' -f running
```When vm with name *default* changes it's state from *running* to any other state, *Changed!* is printed to console
---
```console
foo@bar:~$ vagrant listen-state-changes default 'echo Changed!' -s stopped
```When vm with name *default* changes it's state to *stopped* from any other state, *Changed!* is printed to console
---
```console
foo@bar:~$ vagrant listen-state-changes default 'echo Changed!' -f running -s stopped
```When vm with name *default* changes it's state from *running* to *stopped*, *Changed!* is printed to console
---
```console
foo@bar:~$ vagrant listen-state-changes default 'echo Changed!' -l 10
```When vm with name *default* changes it's state, *Changed!* is printed to console. Delay between state checking - 10 sec\
## Example
```console
# in other terminal: $ vagrant upfoo@bar:~$ vagrant listen-state-changes default 'echo Changed!'
# in other terminal: $ vagrant destroy
VM state changed from 'running' to 'stopped'
Executing actions: 'echo Changed!'
Changed!
Actions executed successfully: trueVM state changed from 'stopped' to 'not created'
Executing actions: 'echo Changed!'
Changed!
Actions executed successfully: true
```With **--auto-stop** option:
```console
# in other terminal: $ vagrant upfoo@bar:~$ vagrant listen-state-changes default 'echo Changed! -a
# in other terminal: $ vagrant destroy
VM state changed from 'running' to 'stopped'
Executing actions: 'echo Changed!'
Changed!
Actions executed successfully: true
Stopping listening ...foo@bar:~$
```