Sha256: 70190194760cff893516ab30fa744dc0f95f6c04f3bbb0439f5d52b19996319b

Contents?: true

Size: 966 Bytes

Versions: 113

Compression:

Stored size: 966 Bytes

Contents

lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))

if File.exist?(File.join(lib_dir, 'daemons.rb'))
  $LOAD_PATH.unshift lib_dir
else
  begin; require 'rubygems'; rescue ::Exception; end
end

require 'daemons'
require 'optparse'
require 'logger'
require 'ostruct'


class MyApp < Logger::Application
  def initialize(args)
    super(self.class)
    @options = OpenStruct.new(:daemonize => true)
    opts = OptionParser.new do |opts|
      opts.banner = 'Usage: myapp [options]'
      opts.separator ''
      opts.on('-N','--no-daemonize',"Don't run as a daemon") do
        @options.daemonize = false
      end
    end
    @args = opts.parse!(args)
  end
  
  def run
    Daemons.run_proc('myapp',{:ARGV => @args, :ontop => !@options.daemonize}) do
      puts "@options.daemonize: #{@options.daemonize}"
      STDOUT.sync = true
      loop do
        print '.'
        sleep(2)
      end
    end
  end
end


myapp = MyApp.new(ARGV)
myapp.run

Version data entries

113 entries across 113 versions & 13 rubygems

Version Path
classiccms-0.3.9 vendor/bundle/gems/daemons-1.1.8/examples/run/ctrl_optionparser.rb
classiccms-0.3.8 vendor/bundle/gems/daemons-1.1.8/examples/run/ctrl_optionparser.rb
classiccms-0.3.7 vendor/bundle/gems/daemons-1.1.8/examples/run/ctrl_optionparser.rb
classiccms-0.3.6 vendor/bundle/gems/daemons-1.1.8/examples/run/ctrl_optionparser.rb
classiccms-0.3.5 vendor/bundle/gems/daemons-1.1.8/examples/run/ctrl_optionparser.rb
classiccms-0.3.4 vendor/bundle/gems/daemons-1.1.8/examples/run/ctrl_optionparser.rb
classiccms-0.3.3 vendor/bundle/gems/daemons-1.1.8/examples/run/ctrl_optionparser.rb
classiccms-0.3.2 vendor/bundle/gems/daemons-1.1.8/examples/run/ctrl_optionparser.rb
classiccms-0.3.1 vendor/bundle/gems/daemons-1.1.8/examples/run/ctrl_optionparser.rb
classiccms-0.3.0 vendor/bundle/gems/daemons-1.1.8/examples/run/ctrl_optionparser.rb
classiccms-0.2.4.pre vendor/bundle/gems/daemons-1.1.8/examples/run/ctrl_optionparser.rb
daemons-1.1.8 examples/run/ctrl_optionparser.rb
daemons-1.1.6 examples/run/ctrl_optionparser.rb
daemons-1.1.5 examples/run/ctrl_optionparser.rb
daemons-1.1.4 examples/run/ctrl_optionparser.rb
daemons-1.1.3 examples/run/ctrl_optionparser.rb
ghazel-daemons-1.0.13.1 examples/run/ctrl_optionparser.rb
ghazel-daemons-1.0.12.1 examples/run/ctrl_optionparser.rb
daemons-1.1.2 examples/run/ctrl_optionparser.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/daemons-1.0.10/examples/run/ctrl_optionparser.rb