Module: SvCtl
- Defined in:
- lib/svctl.rb,
lib/svctl/service.rb,
lib/svctl/version.rb,
lib/svctl/cli/command.rb
Defined Under Namespace
Constant Summary collapse
- RUNSVDIR =
Directory with runlevels
'/etc/runit/runsvdir'
- SERVICE_DIR =
Directory with available services
'/etc/runit/services'
- VERSION =
'20.09.0'
Class Method Summary collapse
-
.all_services ⇒ Array<Service>
List all available services.
-
.disable(service, runlevel = 'current') ⇒ Object
Disable service from selected runlevel.
-
.enable(service, runlevel = 'current') ⇒ Object
Enable service in selected runlevel.
-
.runlevel ⇒ String
Current runlevel.
-
.runlevel_services(runlevel = 'current') ⇒ Array<Service>
List seervices from selected runlevel.
-
.runlevels ⇒ Array<String>
List all runlevels.
-
.switch(runlevel) ⇒ Object
Switch to new runlevel.
Class Method Details
.all_services ⇒ Array<Service>
List all available services
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
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
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 |
.runlevel ⇒ String
Returns 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
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 |
.runlevels ⇒ Array<String>
List all runlevels
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
84 85 86 |
# File 'lib/svctl.rb', line 84 def self.switch(runlevel) system('runsvchdir', runlevel) end |