nesquena / dante

Turn any ruby code into a daemon.
MIT License
313 stars 17 forks source link

Remove 'port' from dante's default options #6

Closed jphastings closed 9 years ago

jphastings commented 11 years ago

Hi, I'm planning on using Dante for a script which doesn't open any ports (it listens and emits to MQs) - I think there ought to be a way for folks to remove the -p PORT option (or any other) from dante's default listings.

LouisKottmann commented 11 years ago

+1

There is no reason to make port a default option.

I'm working on removing it via metaprogramming for now...

pirj commented 10 years ago
  1. And host as well.
  2. It does not make any sense to --kill [PORT], since it should be described by pid, and pid file name does not depend on port, and kill_arg is never used in stop.
  3. Probably it's not a good idea to kill running pid when there's a loop, probably there's a shutdown procedure involved somewhere in user's code trap 'INT', while dante insists on putting it to ensure:
Dante.run('myapp') do |opts|
  begin
    loop do
      sleep 1
    end
  ensure do
    p "SHUTDOWN!"
  end
end
  1. There's some inconsistency between command line options and opts passed to a block: docs: # opts: host, pid_path, port, daemonize, user, group code: {:host=>"0.0.0.0", :pid_path=>"/var/run/myapp.pid", :log_path=>false, :debug=>true} Why log_path is false by default, not /var/log/myapp.log as help mentions? Is there a CLI option to override host?
  2. Why is debug on by default? Do we really need debug here at all?
  3. myapp [-p port] [-P file] [-d] [-k] - no -L, -u, -G, -l mentioned.

Sorry for putting this as a list, this is all related to options.

pirj commented 10 years ago

Besides that, when running without -d option, it's impossible to stop app with ^C:

$ ./1.rb --pid ./1.pid --log 1.log
Starting myapp service...
^C^C^C^C[1]    21801 killed     ./1.rb --pid ./1.pid --log 1.log

From another terminal:

$ ./1.rb --pid ./1.pid --log 1.log -k
No myapp processes are running
$ ps aux g 1
pirj     21801  4.9  1.6  65644 53772 pts/7    Sl+  19:48   0:42 ruby ./1.rb --pid ./1.pid --log 1.log

Killed it with kill 21801. Odd.

LouisKottmann commented 10 years ago

You can remove the switches with this code:

class OptionParser
  def remove_switch(short_name, long_name)
    @stack[2].long.reject! { |k| k == long_name }
    @stack[2].short.reject! { |k| k == short_name }
  end
end

And then whenever you have the opts, you can do:

opts.remove_switch("port", "p")

This will remove the switches in --help but it is obviously a hack!

jatap commented 10 years ago

+1 in order to get a clean solution.

krainboltgreene commented 9 years ago

Moved to new repository: libdante/dante.gem/issues/4