Class: Foreman::Export::SystemdUser
- Inherits:
-
Base
- Object
- Base
- Foreman::Export::SystemdUser
- Defined in:
- lib/foreman/export/systemd_user.rb
Instance Method Summary collapse
- #app ⇒ Object
- #export ⇒ Object
-
#initialize(location, engine, options = {}) ⇒ SystemdUser
constructor
A new instance of SystemdUser.
- #location ⇒ Object
Constructor Details
#initialize(location, engine, options = {}) ⇒ SystemdUser
7 8 9 10 11 12 13 14 15 |
# File 'lib/foreman/export/systemd_user.rb', line 7 def initialize location, engine, ={} super # what a pain in the ass # template is obviously not intended to be overriden unless @options.has_key?(:template) template = File.("../../../../data/export/systemd_user", __FILE__) @options = { template: template }.merge(@options).freeze end end |
Instance Method Details
#app ⇒ Object
17 18 19 |
# File 'lib/foreman/export/systemd_user.rb', line 17 def app [:app] || File.basename(FileUtils.pwd) end |
#export ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/foreman/export/systemd_user.rb', line 25 def export super Dir["#{location}/#{app}*.target"] .concat(Dir["#{location}/#{app}*.service"]) .concat(Dir["#{location}/#{app}*.target.wants/#{app}*.service"]) .each do |file| clean file end Dir["#{location}/#{app}*.target.wants"].each do |file| clean_dir file end process_master_names = [] engine.each_process do |name, process| service_fn = "#{app}-#{name}@.service" write_template "systemd_user/process.service.erb", service_fn, binding create_directory("#{app}-#{name}.target.wants") 1.upto(engine.formation[name]) .collect { |num| engine.port_for(process, num) } .collect { |port| "#{app}-#{name}@#{port}.service" } .each do |process_name| create_symlink("#{app}-#{name}.target.wants/#{process_name}", "../#{service_fn}") rescue Errno::EEXIST # This is needed because rr-mocks do not call the origial cleanup end write_template "systemd_user/process_master.target.erb", "#{app}-#{name}.target", binding process_master_names << "#{app}-#{name}.target" end write_template "systemd_user/master.target.erb", "#{app}.target", binding run_command "test -f /var/lib/systemd/linger/$USER || loginctl enable-linger" run_command "systemctl --user enable #{app}.target" run_command "systemctl --user restart #{app}.target" end |
#location ⇒ Object
21 22 23 |
# File 'lib/foreman/export/systemd_user.rb', line 21 def location super || "#{ENV["HOME"]}/.config/systemd/user" end |