class ForemanDebian::Initd::Engine

Public Class Methods

new(app, export_path = nil) click to toggle source
# File lib/foreman_debian/initd/engine.rb, line 7
def initialize(app, export_path = nil)
  @app = app
  @export_path = Pathname.new(export_path || '/etc/init.d')
  @system_export_path = Pathname.new('/etc/init.d')
  setup
end

Public Instance Methods

create_script(name, command, user) click to toggle source
# File lib/foreman_debian/initd/engine.rb, line 14
def create_script(name, command, user)
  pidfile = pidfile(name)
  args = Shellwords.split(command)
  script = args.shift
  name = "#{@app}-#{name}"
  script_path = @export_path.join(name)
  Script.new(script_path, name, name, user, script, args, pidfile)
end
disable_start_process_on_boot(path) click to toggle source
# File lib/foreman_debian/initd/engine.rb, line 68
def disable_start_process_on_boot(path)
  exec_command("update-rc.d -f #{path.basename} remove") if path.dirname.eql? @system_export_path
end
enable_start_process_on_boot(path) click to toggle source
# File lib/foreman_debian/initd/engine.rb, line 64
def enable_start_process_on_boot(path)
  exec_command("update-rc.d #{path.basename} defaults") if path.dirname.eql? @system_export_path
end
install(script) click to toggle source
# File lib/foreman_debian/initd/engine.rb, line 23
def install(script)
  FileUtils.mkdir_p(script.path.dirname)
  File.open(script.path, 'w') do |file|
    file.puts(script.render)
    file.chmod(0755)
    export_file(script.path)
  end
end
remove_file(path) click to toggle source
Calls superclass method ForemanDebian::EngineHelper#remove_file
# File lib/foreman_debian/initd/engine.rb, line 72
def remove_file(path)
  stop_process(path)
  disable_start_process_on_boot(path)
  super(path)
end
start() click to toggle source
# File lib/foreman_debian/initd/engine.rb, line 32
def start
  threads = []
  each_file do |path|
    threads << Thread.new do
      start_process(path)
      @output.info "  start  #{path.to_s}"
    end
    enable_start_process_on_boot(path)
  end
  ThreadsWait.all_waits(*threads)
end
start_process(path) click to toggle source
# File lib/foreman_debian/initd/engine.rb, line 56
def start_process(path)
  exec_command("#{path.to_s} start")
end
stop() click to toggle source
# File lib/foreman_debian/initd/engine.rb, line 44
def stop
  threads = []
  each_file do |path|
    @output.info "   stop  #{path.to_s}"
    threads << Thread.new do
      stop_process(path)
    end
    disable_start_process_on_boot(path)
  end
  ThreadsWait.all_waits(*threads)
end
stop_process(path) click to toggle source
# File lib/foreman_debian/initd/engine.rb, line 60
def stop_process(path)
  exec_command("#{path.to_s} stop")
end