Module: Rumpy
- Defined in:
- lib/rumpy.rb
Defined Under Namespace
Modules: Bot
Class Method Summary collapse
-
.pid_file(bot) ⇒ Object
Determine the name of file where thid pid will stored to.
-
.run(bot) ⇒ Object
Start bot without detaching.
-
.start(bot) ⇒ Object
Start bot in new process, detach this process and save the pid of process in pid_file.
-
.stop(bot) ⇒ Object
Determine the name of pid_file, read pid from this file and try to kill process with this pid.
Class Method Details
.pid_file(bot) ⇒ Object
Determine the name of file where thid pid will stored to
49 50 51 52 53 |
# File 'lib/rumpy.rb', line 49 def self.pid_file(bot) pid_file = bot.pid_file pid_file = bot.class.to_s.downcase + '.pid' unless pid_file pid_file end |
.run(bot) ⇒ Object
Start bot without detaching
44 45 46 |
# File 'lib/rumpy.rb', line 44 def self.run(bot) bot.start end |
.start(bot) ⇒ Object
Start bot in new process, detach this process and save the pid of process in pid_file
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rumpy.rb', line 12 def self.start(bot) pf = pid_file bot return false if File.exist? pf bot.log_file = "#{bot.class.to_s.downcase}.log" pid = fork do bot.start end Process.detach pid File.open(pf, 'w') do |file| file.puts pid end true end |
.stop(bot) ⇒ Object
Determine the name of pid_file, read pid from this file and try to kill process with this pid
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rumpy.rb', line 30 def self.stop(bot) pf = pid_file bot return false unless File.exist? pf begin File.open(pf) do |file| Process.kill :TERM, file.gets.strip.to_i end ensure File.unlink pf end true end |