Module: Capistrano::SimpleSystemd::Helpers

Defined in:
lib/capistrano/simple_systemd/helpers.rb

Instance Method Summary collapse

Instance Method Details

#compile(template_path) ⇒ Object



28
29
30
# File 'lib/capistrano/simple_systemd/helpers.rb', line 28

def compile(template_path)
  ERB.new(File.new(template_path).read).result(binding)
end

#each_service_template(&block) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/capistrano/simple_systemd/helpers.rb', line 4

def each_service_template(&block)
  service_file_local_dir = Capistrano::SimpleSystemd::Paths::SERVICE_FILE_LOCAL_DIR

  Dir
    .glob(File.join(service_file_local_dir, '*.service.erb'))
    .each { |template_file| block.call(template_file) }
end

#invoke_on_all(task) ⇒ Object



12
13
14
15
16
17
# File 'lib/capistrano/simple_systemd/helpers.rb', line 12

def invoke_on_all(task)
  each_service_template do |template|
    basename = File.basename(template, '.service.erb')
    invoke! "systemd:#{basename}:#{task}"
  end
end

#upload_template(template, service_file_name) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/capistrano/simple_systemd/helpers.rb', line 20

def upload_template(template, service_file_name)
  file_content = compile(File.absolute_path(template))
  tmp_path     = "#{fetch(:tmp_dir)}/#{service_file_name}"

  upload! StringIO.new(file_content), tmp_path
  sudo :mv, tmp_path, "#{fetch(:service_file_remote_dir)}/#{service_file_name}"
end