Skip to content

Commit

Permalink
Merge pull request #756 from eightbitraptor/mvh-void-support
Browse files Browse the repository at this point in the history
Add support for VoidLinux
  • Loading branch information
mizzy authored Oct 24, 2024
2 parents 7f7f973 + 82c5f2c commit c466779
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/specinfra/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Command
require 'specinfra/command/module/zfs'
require 'specinfra/command/module/ss'
require 'specinfra/command/module/openrc'
require 'specinfra/command/module/runit'

# Base
require 'specinfra/command/base'
Expand Down Expand Up @@ -407,3 +408,9 @@ module Command
require 'specinfra/command/poky/base/inventory'
require 'specinfra/command/poky/base/package'
require 'specinfra/command/poky/base/service'

# VoidLinux (inherit Linux)
require 'specinfra/command/voidlinux'
require 'specinfra/command/voidlinux/base'
require 'specinfra/command/voidlinux/base/package'
require 'specinfra/command/voidlinux/base/service'
11 changes: 11 additions & 0 deletions lib/specinfra/command/module/runit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Specinfra
module Command
module Module
module Runit
include Specinfra::Command::Module::Service::Runit
extend Specinfra::Command::Module::Service::Delegator
def_delegator_service_under :runit
end
end
end
end
24 changes: 24 additions & 0 deletions lib/specinfra/command/module/service/runit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ def check_is_running_under_runit(service)
def check_is_enabled_under_runit(service)
"test ! -f /etc/sv/#{escape(service)}/down"
end

def enable_under_runit(service)
"ln -s /etc/sv/#{service} /var/service/"
end

def disable_under_runit(service)
"rm /var/service/#{service}"
end

def start_under_runit(service)
"sv up /var/service/#{service}"
end

def stop_under_runit(service)
"sv down /var/service/#{service}"
end

def restart_under_runit(service)
"sv restart /var/service/#{service}"
end

def reload_under_runit(service)
"sv reload /var/service/#{service}"
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/specinfra/command/voidlinux.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Specinfra::Command::Voidlinux < Specinfra::Command::Linux
end
2 changes: 2 additions & 0 deletions lib/specinfra/command/voidlinux/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Specinfra::Command::Voidlinux::Base < Specinfra::Command::Linux::Base
end
21 changes: 21 additions & 0 deletions lib/specinfra/command/voidlinux/base/package.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Specinfra::Command::Voidlinux::Base::Package < Specinfra::Command::Linux::Base::Package
class << self
def check_is_installed(package, version=nil)
"xbps-query -S #{escape(package)} | grep -q 'state: installed'"
end

alias :check_is_installed_by_xbps :check_is_installed

def get_version(package, opts=nil)
"xbps-query -S #{package} | sed -nE 's/^pkgver: #{package}-([^\)+])/\1/p'"
end

def install(package, version=nil, option='')
"xbps-install --yes #{package}"
end

def remove(package, option='')
"xbps-remove --yes #{option} #{package}"
end
end
end
5 changes: 5 additions & 0 deletions lib/specinfra/command/voidlinux/base/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Specinfra::Command::Voidlinux::Base::Service < Specinfra::Command::Linux::Base::Service
class << self
include Specinfra::Command::Module::Runit
end
end
1 change: 1 addition & 0 deletions lib/specinfra/helper/detect_os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ def detect
require 'specinfra/helper/detect_os/redhat'
require 'specinfra/helper/detect_os/solaris'
require 'specinfra/helper/detect_os/suse'
require 'specinfra/helper/detect_os/voidlinux'
11 changes: 11 additions & 0 deletions lib/specinfra/helper/detect_os/voidlinux.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Specinfra::Helper::DetectOs::Voidlinux < Specinfra::Helper::DetectOs
def detect
if run_command("ls /etc/os-release").success?
line = run_command("cat /etc/os-release").stdout

if line =~ /^ID="void"/
{ :family => 'voidlinux', :release => nil }
end
end
end
end
16 changes: 16 additions & 0 deletions spec/command/module/service/runit_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe Specinfra::Command::Module::Service::Runit do
class Specinfra::Command::Module::Service::Runit::Test < Specinfra::Command::Base
extend Specinfra::Command::Module::Service::Runit
end
let(:klass) { Specinfra::Command::Module::Service::Runit::Test }
it { expect(klass.check_is_enabled_under_runit('httpd')).to eq 'test ! -f /etc/sv/httpd/down' }
it { expect(klass.check_is_running_under_runit('httpd')).to eq "sv status httpd | grep -E '^run: '" }
it { expect(klass.enable_under_runit('httpd')).to eq 'ln -s /etc/sv/httpd /var/service/' }
it { expect(klass.disable_under_runit('httpd')).to eq 'rm /var/service/httpd' }
it { expect(klass.start_under_runit('httpd')).to eq 'sv up /var/service/httpd' }
it { expect(klass.stop_under_runit('httpd')).to eq 'sv down /var/service/httpd' }
it { expect(klass.restart_under_runit('httpd')).to eq 'sv restart /var/service/httpd' }
it { expect(klass.reload_under_runit('httpd')).to eq 'sv reload /var/service/httpd' }
end
9 changes: 9 additions & 0 deletions spec/command/voidlinux/package_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

require 'spec_helper'

set :os, { :family => 'voidlinux' }

describe get_command(:check_package_is_installed, 'httpd') do
it { should eq "xbps-query -S httpd | grep -q 'state: installed'" }
end
24 changes: 24 additions & 0 deletions spec/command/voidlinux/service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'

property[:os] = nil
set :os, :family => 'voidlinux'

describe get_command(:enable_service, 'nginx') do
it { should eq 'ln -s /etc/sv/nginx /var/service/' }
end

describe get_command(:disable_service, 'nginx') do
it { should eq 'rm /var/service/nginx' }
end

describe get_command(:start_service, 'nginx') do
it { should eq 'sv up /var/service/nginx' }
end

describe get_command(:stop_service, 'nginx') do
it { should eq 'sv down /var/service/nginx' }
end

describe get_command(:restart_service, 'nginx') do
it { should eq 'sv restart /var/service/nginx' }
end

0 comments on commit c466779

Please sign in to comment.