Sha256: 0c18fcd8f08debd408cd90c0f42933b0fb1a87a63ee5b00b05901bae5fd56b31

Contents?: true

Size: 965 Bytes

Versions: 11

Compression:

Stored size: 965 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

11 entries across 9 versions & 3 rubygems

Version Path
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.1.0/gems/daemons-1.4.1/examples/run/ctrl_optionparser.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.0.0/gems/daemons-1.4.1/examples/run/ctrl_optionparser.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/2.6.0/gems/daemons-1.4.1/examples/run/ctrl_optionparser.rb
daemons-1.4.1 examples/run/ctrl_optionparser.rb
daemons-1.4.0 examples/run/ctrl_optionparser.rb
daemons-1.3.1 examples/run/ctrl_optionparser.rb
daemons-1.3.0 examples/run/ctrl_optionparser.rb
daemons-1.2.6 examples/run/ctrl_optionparser.rb
daemons-1.2.5 examples/run/ctrl_optionparser.rb
arcabouco-0.2.13 vendor/bundle/gems/daemons-1.2.4/examples/run/ctrl_optionparser.rb
daemons-1.2.4 examples/run/ctrl_optionparser.rb