def daemonize
      exit if fork
      Process.setsid
      exit if fork
      Dir.chdir('/')
      $stdin.reopen(@stdin)
      $stdout.reopen(@stdout, 'a').sync = true
      $stderr.reopen(@stderr, 'a').sync = true
      File.open(@pid, 'w') {|f| f.write(Process.pid) }
      at_exit { delete_pid }
      trap('TERM') { exit }
    end
def daemonize
      exit if fork
      Process.setsid
      exit if fork
      Dir.chdir('/')
      $stdin.reopen(@stdin)
      $stdout.reopen(@stdout, 'a').sync = true
      $stderr.reopen(@stderr, 'a').sync = true
      File.open(@pid, 'w') {|f| f.write(Process.pid) }
      at_exit { delete_pid }
      trap('TERM') { exit }
    end
Fork process into background twice to release it from
 the controlling tty. Point open file descriptors shared
 with the parent process to separate destinations (e.g. /dev/null).