Sha256: f12fa866935a5e98922e0ab363c1c8965f9abf98570924d82dc59dd54487585c

Contents?: true

Size: 572 Bytes

Versions: 2

Compression:

Stored size: 572 Bytes

Contents

# frozen_string_literal: true

module Pups
  class Runit
    attr_accessor :env, :exec, :cd, :name

    def initialize(name)
      @name = name
    end

    def setup
      `mkdir -p /etc/service/#{name}`
      run = "/etc/service/#{name}/run"
      File.open(run, "w") { |f| f.write(run_script) }
      `chmod +x #{run}`
    end

    def run_script
      "#!/bin/bash
exec 2>&1
#{env_script}
#{cd_script}
#{exec}
"
    end

    def cd_script
      "cd #{@cd}" if @cd
    end

    def env_script
      @env&.map { |k, v| "export #{k}=#{v}" }&.join("\n")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pups-1.2.1 lib/pups/runit.rb
pups-1.2.0 lib/pups/runit.rb