Sha256: a9cb13e2993c0e5ca5c5aa84ad1823c511685f5599676413c19e383a5f479c47

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 KB

Contents

#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-

APP_ROOT ||= File.expand_path(File.dirname($0)) + "/../"

if defined?(DAEMONIZE) || ARGV.include?('--daemonize') # для демонизации бина
  ARGV.delete('--daemonize')

  # Stolen from activesupport
  module Process
    def self.daemon
      exit if fork                     # Parent exits, child continues.
      Process.setsid                   # Become session leader.
      exit if fork                     # Zap session leader. See [1].
      return 0
    end
  end

  Process.daemon

  if ARGV.include?('--pidfile')
    pidfile = nil

    ARGV.each_index do |i|
      if ARGV[i] == '--pidfile' && ARGV.length > i
        pidfile = ARGV[i+1]

        ARGV.delete('--pidfile')
        ARGV.delete(pidfile) if pidfile
        break
      end
    end

    if pidfile
      File.open(pidfile, 'w'){|f| f.write($$) }
    end
  end
end

require 'rubygems'

# Define RAILS_ENV
ARGV.each_index do |i|
  if ARGV[i] == '-e' && ARGV.length > i
    ENV['RAILS_ENV'] = ARGV[i+1]
    break
  end
end

# -h for show help, Rails not needed
NO_RAILS = true if ARGV.include?('-h') && !defined?(NO_RAILS)

# Set defaults
ENV['RAILS_ENV'] ||= 'development'

if !defined?(Rails) && !defined?(NO_RAILS)
  # Load rails envoronment if not yet and we need it
  require File.join(APP_ROOT, %w{config environment})
else
  require 'active_support'
end

# Load BinScript class source (from gem)
require 'bin_script' if !defined?(BinScript) || !BinScript.respond_to?(:run_script)

# Call script runner
BinScript.run_script

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bin_script-0.1.5 bin/bin_helper
bin_script-0.1.4 bin/bin_helper
bin_script-0.1.3 bin/bin_helper
bin_script-0.1.2 bin/bin_helper