Class: Runit::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/runit/config.rb

Defined Under Namespace

Classes: Service

Constant Summary collapse

TERM_SIGNAL =
Deprecated.

we should move this to ‘GDK::Service` when cleaning up Procfile based services

{
  'webpack' => 'KILL'
}.freeze
PERMISSION_READONLY =

User read-write, group and global read-only

0o644
PERMISSION_EXECUTION =

User read write and execute, group and global read and execute

0o755
TEMPLATE_PATH =
'support/templates'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gdk_root) ⇒ Config

Returns a new instance of Config.

Parameters:

  • gdk_root (Pathname)


25
26
27
# File 'lib/runit/config.rb', line 25

def initialize(gdk_root)
  @gdk_root = gdk_root
end

Instance Attribute Details

#gdk_rootObject (readonly)

Returns the value of attribute gdk_root.



8
9
10
# File 'lib/runit/config.rb', line 8

def gdk_root
  @gdk_root
end

Instance Method Details

#log_dirObject



29
30
31
# File 'lib/runit/config.rb', line 29

def log_dir
  gdk_root.join('log')
end

#render(services: services_from_procfile) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/runit/config.rb', line 45

def render(services: services_from_procfile)
  FileUtils.mkdir_p(services_dir)
  FileUtils.mkdir_p(log_dir)

  max_service_length = services.map { |svc| svc.name.size }.max

  services.each_with_index do |service, i|
    create_runit_service(service)
    create_runit_down(service)
    create_runit_control_t(service)
    create_runit_log_service(service)
    create_runit_log_config(service, max_service_length, i)
    enable_runit_service(service)
  end

  FileUtils.rm(stale_service_links(services))
end

#run_envObject



41
42
43
# File 'lib/runit/config.rb', line 41

def run_env
  @run_env ||= generate_run_env
end

#services_dirObject



33
34
35
# File 'lib/runit/config.rb', line 33

def services_dir
  gdk_root.join('services')
end

#services_from_procfileObject

Deprecated.

This will be removed when all services have been converted to GDK::Services

Load a list of services from Procfile



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/runit/config.rb', line 82

def services_from_procfile
  GDK::Output.abort 'GDK services appear missing, have you run `gdk install` ?' unless procfile_path.exist?

  procfile_path.readlines.filter_map do |line|
    line.chomp!
    next if line.start_with?('#')

    name, command = line.split(': ', 2)
    next unless name && command

    delete_exec_prefix!(name, command)

    Service.new(name, command, {})
  end
end


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/runit/config.rb', line 63

def stale_service_links(services)
  service_names = services.map(&:name)
  dir_matcher = %w[. ..]

  stale_entries = Dir.entries(services_dir).reject do |svc|
    service_names.include?(svc) || dir_matcher.include?(svc)
  end

  stale_entries.filter_map do |entry|
    path = services_dir.join(entry)
    next unless File.symlink?(path)

    path
  end
end

#sv_dir(service) ⇒ Object



37
38
39
# File 'lib/runit/config.rb', line 37

def sv_dir(service)
  gdk_root.join('sv', service.name)
end