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, #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
|
#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
56
57
58
59
|
# File 'lib/foreman_debian/initd/engine.rb', line 56
def remove_file(path)
stop_file(path)
super(path)
end
|
#start ⇒ Object
32
33
34
35
36
|
# File 'lib/foreman_debian/initd/engine.rb', line 32
def start
each_file do |path|
start_file(path)
end
end
|
#start_file(path) ⇒ Object
44
45
46
47
48
|
# File 'lib/foreman_debian/initd/engine.rb', line 44
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
|
#stop ⇒ Object
38
39
40
41
42
|
# File 'lib/foreman_debian/initd/engine.rb', line 38
def stop
each_file do |path|
stop_file(path)
end
end
|
#stop_file(path) ⇒ Object
50
51
52
53
54
|
# File 'lib/foreman_debian/initd/engine.rb', line 50
def stop_file(path)
exec_command("#{path.to_s} stop")
@output.info " stop #{path.to_s}"
exec_command("update-rc.d -f #{path.basename} remove") if path.dirname.eql? @system_export_path
end
|