Module: SvCtl
- Defined in:
- lib/svctl.rb,
lib/svctl/service.rb,
lib/svctl/version.rb,
lib/svctl/item_file.rb,
lib/svctl/cli/command.rb
Defined Under Namespace
Modules: Cli Classes: ItemFile, Service
Constant Summary collapse
- RUNSVDIR =
Directory with runlevels
'/etc/runit/runsvdir'.freeze
- SERVICE_DIR =
Directory with available services
'/etc/runit/services'.freeze
- PROTECTED_SERVICES_FILE =
A list of protected services
'/run/runit/protected-services.txt'.freeze
- VERSION =
'24.05.0'.freeze
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.
-
.protect(service_pattern) ⇒ Object
Ignore service changes on system configuration switch.
-
.protected_services ⇒ Array<String>
List protected services.
-
.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.
-
.unprotect(service_pattern) ⇒ Object
Do not ignore service changes on system configuration switch.
Class Method Details
.all_services ⇒ Array<Service>
List all available services
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/svctl.rb', line 17 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
59 60 61 62 63 64 |
# File 'lib/svctl.rb', line 59 def self.disable(service, runlevel = 'current') sv = Service.new(service, runlevel) raise 'service not found' unless sv.exist? sv.disable if sv.enabled? end |
.enable(service, runlevel = 'current') ⇒ Object
Enable service in selected runlevel
49 50 51 52 53 54 |
# File 'lib/svctl.rb', line 49 def self.enable(service, runlevel = 'current') sv = Service.new(service, runlevel) raise 'service not found' unless sv.exist? sv.enable end |
.protect(service_pattern) ⇒ Object
Ignore service changes on system configuration switch
68 69 70 71 72 |
# File 'lib/svctl.rb', line 68 def self.protect(service_pattern) ItemFile.new(PROTECTED_SERVICES_FILE) do |list| list << service_pattern end end |
.protected_services ⇒ Array<String>
List protected services
84 85 86 87 88 89 90 91 92 |
# File 'lib/svctl.rb', line 84 def self.protected_services ret = nil ItemFile.new(PROTECTED_SERVICES_FILE) do |list| ret = list.get end ret end |
.runlevel ⇒ String
Returns current runlevel.
110 111 112 |
# File 'lib/svctl.rb', line 110 def self.runlevel File.basename(File.readlink(File.join(RUNSVDIR, 'current'))) end |
.runlevel_services(runlevel = 'current') ⇒ Array<Service>
List seervices from selected runlevel
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/svctl.rb', line 33 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
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/svctl.rb', line 96 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
116 117 118 |
# File 'lib/svctl.rb', line 116 def self.switch(runlevel) system('runsvchdir', runlevel) end |
.unprotect(service_pattern) ⇒ Object
Do not ignore service changes on system configuration switch
76 77 78 79 80 |
# File 'lib/svctl.rb', line 76 def self.unprotect(service_pattern) ItemFile.new(PROTECTED_SERVICES_FILE) do |list| list.delete(service_pattern) end end |