vagrant_reboot_linux 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +60 -0
- data/Gemfile +10 -0
- data/example/Vagrantfile +10 -0
- data/lib/vagrant_reboot_linux.rb +1 -0
- data/lib/vagrant_reboot_linux/cap/reboot.rb +64 -0
- data/lib/vagrant_reboot_linux/plugin.rb +14 -0
- data/lib/vagrant_reboot_linux/version.rb +5 -0
- data/vagrant_reboot_linux.gemspec +19 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5cfd2775aac0d200bc0f22cfc1e0b229a119af78d6c37b52c126b93865b0ad25
|
4
|
+
data.tar.gz: b80405a74dfa10d5635742b50db1bb511112ca53f04ccef98b84d683126f7b11
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2204f1e0b58e88975fce8dc610a84582628d82e0a30ad9f4262e4b12844b2a387e427e82d0bc6c876c416ad83cf18e362839f4735eac5a00f26ebe584cddbb34
|
7
|
+
data.tar.gz: c611ee89fc9b4bbcb3cc1f87d99df662eea89076e1daf6094845615aa5d0b76abf5902ffaf40bc11ceb38b5e56bcae14b556c1dcad06d3946b8ba25531ddc887
|
data/.gitignore
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
# Created by https://www.gitignore.io/api/rust,macos,vagrant
|
3
|
+
# Edit at https://www.gitignore.io/?templates=rust,macos,vagrant
|
4
|
+
|
5
|
+
### macOS ###
|
6
|
+
# General
|
7
|
+
.DS_Store
|
8
|
+
.AppleDouble
|
9
|
+
.LSOverride
|
10
|
+
|
11
|
+
# Icon must end with two \r
|
12
|
+
Icon
|
13
|
+
|
14
|
+
# Thumbnails
|
15
|
+
._*
|
16
|
+
|
17
|
+
# Files that might appear in the root of a volume
|
18
|
+
.DocumentRevisions-V100
|
19
|
+
.fseventsd
|
20
|
+
.Spotlight-V100
|
21
|
+
.TemporaryItems
|
22
|
+
.Trashes
|
23
|
+
.VolumeIcon.icns
|
24
|
+
.com.apple.timemachine.donotpresent
|
25
|
+
|
26
|
+
# Directories potentially created on remote AFP share
|
27
|
+
.AppleDB
|
28
|
+
.AppleDesktop
|
29
|
+
Network Trash Folder
|
30
|
+
Temporary Items
|
31
|
+
.apdisk
|
32
|
+
|
33
|
+
### Rust ###
|
34
|
+
# Generated by Cargo
|
35
|
+
# will have compiled files and executables
|
36
|
+
/target/
|
37
|
+
|
38
|
+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
39
|
+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
40
|
+
Cargo.lock
|
41
|
+
|
42
|
+
# These are backup files generated by rustfmt
|
43
|
+
**/*.rs.bk
|
44
|
+
|
45
|
+
### Vagrant ###
|
46
|
+
# General
|
47
|
+
.vagrant/
|
48
|
+
|
49
|
+
# Log files (if you are creating logs in debug mode, uncomment this)
|
50
|
+
# *.logs
|
51
|
+
|
52
|
+
### Vagrant Patch ###
|
53
|
+
*.box
|
54
|
+
|
55
|
+
example/*.log
|
56
|
+
|
57
|
+
|
58
|
+
Gemfile.lock
|
59
|
+
|
60
|
+
# End of https://www.gitignore.io/api/rust,macos,vagrant
|
data/Gemfile
ADDED
data/example/Vagrantfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'vagrant_reboot_linux/plugin'
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
require 'vagrant'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module RebootLinux
|
6
|
+
module Cap
|
7
|
+
class Reboot
|
8
|
+
MAX_REBOOT_RETRY_DURATION = 120
|
9
|
+
|
10
|
+
def self.reboot(machine)
|
11
|
+
@logger = Log4r::Logger.new('vagrant::linux::reboot')
|
12
|
+
|
13
|
+
if shutting?(machine)
|
14
|
+
@logger.debug('A shutdown is already in progress')
|
15
|
+
elsif rebooting?(machine)
|
16
|
+
@logger.debug('A reboot is already in progress')
|
17
|
+
elsif pending_schutdown?(machine)
|
18
|
+
@logger.debug('A shutdown is already scheduled')
|
19
|
+
else
|
20
|
+
machine.communicate.sudo('sync && reboot')
|
21
|
+
end
|
22
|
+
|
23
|
+
machine.ui.info(I18n.t('vagrant.guests.capabilities.rebooting'))
|
24
|
+
|
25
|
+
@logger.debug('Waiting for machine to finish rebooting')
|
26
|
+
|
27
|
+
wait_remaining = MAX_REBOOT_RETRY_DURATION
|
28
|
+
begin
|
29
|
+
wait_for_reboot(machine)
|
30
|
+
rescue Vagrant::Errors::MachineGuestNotReady
|
31
|
+
raise if wait_remaining < 0
|
32
|
+
|
33
|
+
@logger.warn('Machine not ready, cannot start reboot yet.'\
|
34
|
+
' Trying again')
|
35
|
+
sleep 5
|
36
|
+
wait_remaining -= 5
|
37
|
+
retry
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.wait_for_reboot(machine)
|
42
|
+
while machine.guest.ready? &&
|
43
|
+
(shutting?(machine) || rebooting?(machine))
|
44
|
+
sleep 5
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.shutting?(machine)
|
49
|
+
# https://en.wikipedia.org/wiki/Runlevel
|
50
|
+
machine.communicate.test("[ $(runlevel | sed 's/.* //') == 0 ]")
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.rebooting?(machine)
|
54
|
+
# https://en.wikipedia.org/wiki/Runlevel
|
55
|
+
machine.communicate.test("[ $(runlevel | sed 's/.* //') == 6 ]")
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.pending_schutdown?(machine)
|
59
|
+
machine.communicate.test('test -f /run/systemd/shutdown/scheduled')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module RebootLinux
|
5
|
+
class Plugin < Vagrant.plugin('2')
|
6
|
+
name 'Reboot Linux guest'
|
7
|
+
description 'Reboot Linux guest support.'
|
8
|
+
guest_capability 'linux', 'reboot' do
|
9
|
+
require_relative 'cap/reboot'
|
10
|
+
Cap::Reboot
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Add the lib directory to the load path so we can get the version file out.
|
2
|
+
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
|
3
|
+
|
4
|
+
require 'vagrant_reboot_linux/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'vagrant_reboot_linux'
|
8
|
+
gem.version = VagrantPlugins::Cap::VERSION
|
9
|
+
gem.platform = Gem::Platform::RUBY
|
10
|
+
gem.license = 'MIT'
|
11
|
+
gem.authors = 'WANG YU-CHIH'
|
12
|
+
gem.email = 'secret104278@gmail.com'
|
13
|
+
gem.homepage = "https://github.com/secret104278/vagrant_reboot_linux"
|
14
|
+
gem.description = 'Guest capability for linux to reboot.'
|
15
|
+
gem.summary = 'Guest capability for linux to reboot.'
|
16
|
+
|
17
|
+
gem.files = `git ls-files -z`.split("\x0")
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant_reboot_linux
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- WANG YU-CHIH
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Guest capability for linux to reboot.
|
14
|
+
email: secret104278@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".gitignore"
|
20
|
+
- Gemfile
|
21
|
+
- example/Vagrantfile
|
22
|
+
- lib/vagrant_reboot_linux.rb
|
23
|
+
- lib/vagrant_reboot_linux/cap/reboot.rb
|
24
|
+
- lib/vagrant_reboot_linux/plugin.rb
|
25
|
+
- lib/vagrant_reboot_linux/version.rb
|
26
|
+
- vagrant_reboot_linux.gemspec
|
27
|
+
homepage: https://github.com/secret104278/vagrant_reboot_linux
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.7.9
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: Guest capability for linux to reboot.
|
51
|
+
test_files: []
|