Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] Make mem and cpu dynamic #156

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,35 @@
VAGRANTFILE_API_VERSION = "2"

Vagrant.require_version ">= 2.0.1"
host = RbConfig::CONFIG['host_os']

# List memory
if host =~ /darwin/
$detected_cpus = `sysctl -n hw.ncpu`.to_i
# conver to MB
$mem = `sysctl -n hw.memsize`.to_i / 1024 / 1024
elsif host =~ /linux/
$detected_cpus = `nproc`.to_i
$mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024
else
# else windows commands
$detected_cpus = `wmic cpu get NumberOfCores`.split("\n")[2].to_i
$mem = `wmic OS get TotalVisibleMemorySize`.split("\n")[2].to_i / 1024
end

# Use whichever is larger, 1/2 the RAM or 4GB.
$mem = [$mem / 2, 4096].max
$detected_cpus = [$detected_cpus / 2, 1].max

$cpus = ENV.fetch("ISLANDORA_VAGRANT_CPUS", "1")
$memory = ENV.fetch("ISLANDORA_VAGRANT_MEMORY", "4096")
$memory = ENV.fetch("ISLANDORA_VAGRANT_MEMORY", $mem)

$hostname = ENV.fetch("ISLANDORA_VAGRANT_HOSTNAME", "islandora8")
$virtualBoxDescription = ENV.fetch("ISLANDORA_VAGRANT_VIRTUALBOXDESCRIPTION", "Islandora 8")

$vms_running = `VBoxManage list runningvms | wc -l | sed 's/[^0-9]//g'`.to_i
$cpus_checks = ENV.fetch("ISLANDORA_VAGRANT_CPUS", "")

# Available boxes are 'ubuntu/xenial64' and 'centos/7'
$vagrantBox = ENV.fetch("ISLANDORA_DISTRO", "ubuntu/bionic64")

Expand Down Expand Up @@ -42,8 +65,18 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.network :forwarded_port, guest: 8081, host: 8081 # API-X

config.vm.provider "virtualbox" do |vb|
if $vms_running == 0
if $cpus_checks == ""
vb.customize ["modifyvm", :id, "--ioapic", "on"]
vb.customize ["modifyvm", :id, "--cpus", $detected_cpus]
else
vb.customize ["modifyvm", :id, "--cpus", $cpus]
end
else
vb.customize ["modifyvm", :id, "--cpus", $cpus]
end

vb.customize ["modifyvm", :id, "--memory", $memory]
vb.customize ["modifyvm", :id, "--cpus", $cpus]
vb.customize ["modifyvm", :id, "--description", $virtualBoxDescription]
vb.customize ["modifyvm", :id, "--audio", "none"]
end
Expand Down