Class: Vidibus::Recording::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/vidibus/recording/daemon.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Daemon

Returns a new instance of Daemon.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vidibus/recording/daemon.rb', line 12

def initialize(args)
  @options = {:pid_dir => "#{Rails.root}/tmp/pids"}
  options = OptionParser.new do |options|
    options.banner = "Usage: #{File.basename($0)} start|stop|restart"
    options.on('-h', '--help', 'Show this message') do
      puts options
      exit 1
    end
  end
  @args = options.parse!(args)
end

Instance Method Details

#daemonizeObject



24
25
26
27
28
# File 'lib/vidibus/recording/daemon.rb', line 24

def daemonize
  dir = @options[:pid_dir]
  Dir.mkdir(dir) unless File.exists?(dir)
  run_process('recording', dir)
end

#runObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/vidibus/recording/daemon.rb', line 34

def run
  Dir.chdir(Rails.root)
  log = File.join(Rails.root, 'log', 'recording.log')
  Vidibus::Recording.logger = ActiveSupport::BufferedLogger.new(log)
  Vidibus::Recording.monitor
rescue => e
  Vidibus::Recording.logger.fatal(e)
  STDERR.puts(e.message)
  exit 1
end

#run_process(name, dir) ⇒ Object



30
31
32
# File 'lib/vidibus/recording/daemon.rb', line 30

def run_process(name, dir)
  Daemons.run_proc(name, :dir => dir, :dir_mode => :normal) { run }
end