Class: ForemanDebian::Initd::Engine
- Inherits:
-
Object
- Object
- ForemanDebian::Initd::Engine
show all
- Includes:
- EngineHelper
- Defined in:
- lib/foreman_debian/initd/engine.rb
Instance Method Summary
collapse
#cleanup, #each_file, #exec_command, #export_file, #get_files, #pidfile, #setup
Constructor Details
#initialize(app, export_path = nil) ⇒ Engine
Returns a new instance of Engine.
7
8
9
10
11
12
|
# 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
|
Instance Method Details
#create_script(name, command, user) ⇒ Object
14
15
16
17
18
19
20
21
|
# 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) ⇒ Object
68
69
70
|
# 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) ⇒ Object
64
65
66
|
# 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) ⇒ Object
23
24
25
26
27
28
29
30
|
# 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) ⇒ Object
72
73
74
75
76
|
# 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 ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
|
# 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) ⇒ Object
56
57
58
|
# File 'lib/foreman_debian/initd/engine.rb', line 56
def start_process(path)
exec_command("#{path.to_s} start")
end
|
#stop ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
|
# 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) ⇒ Object
60
61
62
|
# File 'lib/foreman_debian/initd/engine.rb', line 60
def stop_process(path)
exec_command("#{path.to_s} stop")
end
|