Sha256: 39002b44f321d0b110cfd5089234aa2bb30507cb6f37bcc671c465f931527c63

Contents?: true

Size: 834 Bytes

Versions: 34

Compression:

Stored size: 834 Bytes

Contents

# run command/block as a background daemon
module Wunderbar
  def self.submit(cmd=nil)
    fork do
      # detach from tty
      Process.setsid
      fork and exit

      # clear working directory and mask
      Dir.chdir '/'
      File.umask 0000

      # close open files
      STDIN.reopen '/dev/null'
      STDOUT.reopen '/dev/null', 'a'
      STDERR.reopen STDOUT

      # clear environment of cgi cruft
      require 'cgi'
      ENV.keys.select {|key| key =~ /^HTTP_/}.each do |key|
        ENV.delete key.dup.untaint
      end
      ::CGI::QueryExtension.public_instance_methods.each do |method|
        ENV.delete method.to_s.upcase
      end

      # setup environment
      ENV['USER'] ||= $USER
      ENV['HOME'] ||= $HOME

      # run cmd and/or block
      system cmd if cmd
      yield if block_given?
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
wunderbar-0.18.3 lib/wunderbar/job-control.rb
wunderbar-0.18.2 lib/wunderbar/job-control.rb
wunderbar-0.18.1 lib/wunderbar/job-control.rb
wunderbar-0.18.0 lib/wunderbar/job-control.rb
wunderbar-0.17.3 lib/wunderbar/job-control.rb
wunderbar-0.17.2 lib/wunderbar/job-control.rb
wunderbar-0.17.0 lib/wunderbar/job-control.rb
wunderbar-0.17.1 lib/wunderbar/job-control.rb
wunderbar-0.16.15 lib/wunderbar/job-control.rb
wunderbar-0.16.14 lib/wunderbar/job-control.rb
wunderbar-0.16.13 lib/wunderbar/job-control.rb
wunderbar-0.16.12 lib/wunderbar/job-control.rb
wunderbar-0.16.11 lib/wunderbar/job-control.rb
wunderbar-0.16.10 lib/wunderbar/job-control.rb
wunderbar-0.16.9 lib/wunderbar/job-control.rb
wunderbar-0.16.8 lib/wunderbar/job-control.rb
wunderbar-0.16.7 lib/wunderbar/job-control.rb
wunderbar-0.16.6 lib/wunderbar/job-control.rb
wunderbar-0.16.5 lib/wunderbar/job-control.rb
wunderbar-0.16.4 lib/wunderbar/job-control.rb