Module: SvCtl

Defined in:
lib/svctl.rb,
lib/svctl/service.rb,
lib/svctl/version.rb,
lib/svctl/cli/command.rb

Defined Under Namespace

Modules: Cli Classes: Service

Constant Summary collapse

RUNSVDIR =

Directory with runlevels

'/etc/runit/runsvdir'
SERVICE_DIR =

Directory with available services

'/etc/runit/services'
VERSION =
'18.09.0'

Class Method Summary collapse

Class Method Details

.all_servicesArray<Service>

List all available services

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/svctl.rb', line 13

def self.all_services
  svdir = File.join(SERVICE_DIR)
  ret = []

  Dir.entries(svdir).each do |v|
    next if %w(. ..).include?(v)

    ret << Service.new(v, nil)
  end

  ret
end

.disable(service, runlevel = 'current') ⇒ Object

Disable service from selected runlevel

Parameters:

  • service (String)
  • runlevel (String) (defaults to: 'current')


55
56
57
58
59
60
# File 'lib/svctl.rb', line 55

def self.disable(service, runlevel = 'current')
  sv = Service.new(service, runlevel)
  fail 'service not found' unless sv.exist?

  sv.disable if sv.enabled?
end

.enable(service, runlevel = 'current') ⇒ Object

Enable service in selected runlevel

Parameters:

  • service (String)
  • runlevel (String) (defaults to: 'current')


45
46
47
48
49
50
# File 'lib/svctl.rb', line 45

def self.enable(service, runlevel = 'current')
  sv = Service.new(service, runlevel)
  fail 'service not found' unless sv.exist?

  sv.enable
end

.runlevelString

Returns current runlevel

Returns:

  • (String)

    current runlevel



78
79
80
# File 'lib/svctl.rb', line 78

def self.runlevel
  File.basename(File.readlink(File.join(RUNSVDIR, 'current')))
end

.runlevel_services(runlevel = 'current') ⇒ Array<Service>

List seervices from selected runlevel

Parameters:

  • runlevel (String) (defaults to: 'current')

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/svctl.rb', line 29

def self.runlevel_services(runlevel = 'current')
  svdir = File.join(RUNSVDIR, runlevel)
  ret = []

  Dir.entries(svdir).each do |v|
    next if %w(. ..).include?(v)

    ret << Service.new(v, runlevel)
  end

  ret
end

.runlevelsArray<String>

List all runlevels

Returns:

  • (Array<String>)


64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/svctl.rb', line 64

def self.runlevels
  ret = []

  Dir.entries(RUNSVDIR).each do |v|
    next if %w(. .. current previous).include?(v)
    next unless Dir.exist?(File.join(RUNSVDIR, v))

    ret << v
  end

  ret
end

.switch(runlevel) ⇒ Object

Switch to new runlevel

Parameters:

  • runlevel (String)


84
85
86
# File 'lib/svctl.rb', line 84

def self.switch(runlevel)
  system('runsvchdir', runlevel)
end