Class: EM::FTPD::App

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/em-ftpd/app.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(config_path) ⇒ Object



29
30
31
# File 'lib/em-ftpd/app.rb', line 29

def self.start(config_path)
  self.instance.start(config_path)
end

Instance Method Details

#daemonise!(config) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/em-ftpd/app.rb', line 10

def daemonise!(config)
  return unless config.daemonise

  ## close unneeded descriptors,
  $stdin.reopen("/dev/null")
  $stdout.reopen("/dev/null","w")
  $stderr.reopen("/dev/null","w")

  ## drop into the background.
  pid = fork
  if pid
    ## parent: save pid of child, then exit
    if config.pid_file
      File.open(config.pid_file, "w") { |io| io.write pid }
    end
    exit!
  end
end

#start(config_path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/em-ftpd/app.rb', line 33

def start(config_path)
  config_data = File.read(config_path)
  config = EM::FTPD::Configurator.new
  config.instance_eval(config_data)
  config.check!
  update_procline(config.name)

  EventMachine.epoll

  EventMachine::run do
    puts "Starting ftp server on 0.0.0.0:#{config.port}"
    EventMachine::start_server("0.0.0.0", config.port, EM::FTPD::Server, config.driver, *config.driver_args)

    daemonise!(config)
    change_gid(config.gid)
    change_uid(config.uid)
    setup_signal_handlers
  end
end