Class: ForemanDebian::Initd::Engine

Inherits:
Object
  • Object
show all
Includes:
EngineHelper
Defined in:
lib/foreman_debian/initd/engine.rb

Instance Method Summary collapse

Methods included from EngineHelper

#cleanup, #each_file, #exec_command, #export_file, #pidfile, #setup

Constructor Details

#initialize(app, user, export_path = nil) ⇒ Engine

Returns a new instance of Engine.



7
8
9
10
11
12
13
# File 'lib/foreman_debian/initd/engine.rb', line 7

def initialize(app, user, export_path = nil)
  @app = app
  @user = user
  @export_path = Pathname.new(export_path || '/etc/init.d')
  @system_export_path = Pathname.new('/etc/init.d')
  setup
end

Instance Method Details

#create_script(name, command) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/foreman_debian/initd/engine.rb', line 15

def create_script(name, command)
  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

#install(script) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/foreman_debian/initd/engine.rb', line 24

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) ⇒ Object



57
58
59
60
# File 'lib/foreman_debian/initd/engine.rb', line 57

def remove_file(path)
  stop_file(path)
  super(path)
end

#startObject



33
34
35
36
37
# File 'lib/foreman_debian/initd/engine.rb', line 33

def start
  each_file do |path|
    start_file(path)
  end
end

#start_file(path) ⇒ Object



45
46
47
48
49
# File 'lib/foreman_debian/initd/engine.rb', line 45

def start_file(path)
  exec_command("#{path.to_s} start")
  @output.info " start  #{path.to_s}"
  exec_command("update-rc.d #{path.basename} defaults") if path.dirname.eql? @system_export_path
end

#stopObject



39
40
41
42
43
# File 'lib/foreman_debian/initd/engine.rb', line 39

def stop
  each_file do |path|
    stop_file(path)
  end
end

#stop_file(path) ⇒ Object



51
52
53
54
55
# File 'lib/foreman_debian/initd/engine.rb', line 51

def stop_file(path)
  exec_command("#{path.to_s} stop")
  @output.info "  stop  #{path.to_s}"
  exec_command("update-rc.d #{path.basename} remove") if path.dirname.eql? @system_export_path
end