class PleaseRun::Platform::SystemdUser

The platform implementation for systemd user services.

Public Instance Methods

environment_data() click to toggle source
# File lib/pleaserun/platform/systemd-user.rb, line 33
def environment_data
  ENV.collect { |k,v| "#{k}=#{v}" }.join("\n")
end
files() click to toggle source
# File lib/pleaserun/platform/systemd-user.rb, line 14
def files
  begin
    # TODO(sissel): Make it easy for subclasses to extend validation on attributes.
    insist { program } =~ /^\//
  rescue Insist::Failure
    raise PleaseRun::Configurable::ValidationError, "In systemd, the program must be a full path. You gave '#{program}'."
  end

  if !File.directory?(home)
    raise PleaseRun::Configurable::ValidationError, "HOME (#{home}) is not a directory. Cannot continue."
  end

  return Enumerator::Generator.new do |enum|
    enum.yield(safe_filename("{{{home}}}/.config/systemd/user/{{{ name }}}.environment"), environment_data)
    enum.yield(safe_filename("{{{home}}}/.config/systemd/user/{{{ name }}}.service"), render_template("program.service"))
    enum.yield(safe_filename("{{{home}}}/.config/systemd/user/{{{ name }}}-prestart.sh"), render_template("prestart.sh"), 0755) if prestart
  end
end
home() click to toggle source
# File lib/pleaserun/platform/systemd-user.rb, line 6
def home
  @home ||= ENV["HOME"]
  if @home.nil? || @home.empty?
    raise PleaseRun::Configurable::ValidationError, "As a normal user (not root), I need to know where your home directory is, but the HOME environment variable seems to be not set."
  end
  @home
end
install_actions() click to toggle source
# File lib/pleaserun/platform/systemd-user.rb, line 37
def install_actions
  return ["systemctl --user daemon-reload"]
end