{"id":13462962,"url":"https://github.com/nesquena/dante","last_synced_at":"2025-04-03T02:09:48.526Z","repository":{"id":1898007,"uuid":"2824580","full_name":"nesquena/dante","owner":"nesquena","description":"Turn any ruby code into a daemon.","archived":false,"fork":false,"pushed_at":"2014-04-18T18:22:10.000Z","size":191,"stargazers_count":314,"open_issues_count":3,"forks_count":14,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-24T08:26:30.270Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nesquena.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-11-22T01:34:03.000Z","updated_at":"2025-03-22T23:05:57.000Z","dependencies_parsed_at":"2022-09-08T11:12:10.909Z","dependency_job_id":null,"html_url":"https://github.com/nesquena/dante","commit_stats":null,"previous_names":["bazaarlabs/dante"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nesquena%2Fdante","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nesquena%2Fdante/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nesquena%2Fdante/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nesquena%2Fdante/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nesquena","download_url":"https://codeload.github.com/nesquena/dante/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246922247,"owners_count":20855345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T13:00:42.508Z","updated_at":"2025-04-03T02:09:48.507Z","avatar_url":"https://github.com/nesquena.png","language":"Ruby","funding_links":[],"categories":["Background Processing","Gems"],"sub_categories":["Daemonizing","Misc"],"readme":"# Dante\n\nTurn any ruby into a daemon.\n\n## Description\n\nDante is the simplest possible thing that will work to turn arbitrary ruby code into an executable that\ncan be started via command line or start/stop a daemon, and will store a pid file for you.\n\nIf you need to create a ruby executable and you want standard daemon start/stop with pid files\nand no hassle, this gem will be a great way to get started.\n\n## Installation\n\nAdd to your Gemfile:\n\n```ruby\n# Gemfile\n\ngem \"dante\"\n```\n\nor to your gemspec:\n\n```ruby\n# mygem.gemspec\n\nGem::Specification.new do |s|\n  s.add_dependency \"dante\"\nend\n```\n\n## Usage\n\nDante is meant to be used from any \"bin\" executable. For instance, to create a binary for a web server, create a file in `bin/myapp`:\n\n```ruby\n#!/usr/bin/env ruby\n\nrequire File.expand_path(\"../../myapp.rb\", __FILE__)\n\nDante.run('myapp') do |opts|\n  # opts: host, pid_path, port, daemonize, user, group\n  Thin::Server.start('0.0.0.0', opts[:port]) do\n    use Rack::CommonLogger\n    use Rack::ShowExceptions\n    run MyApp\n  end\nend\n```\n\nBe sure to properly make your bin executable:\n\n```\nchmod +x bin/myapp\n```\n\n### CLI\n\nThis gives your binary several useful things for free:\n\n```\n./bin/myapp\n```\n\nwill start the app undaemonized in the terminal, handling trapping and stopping the process.\n\n```\n./bin/myapp -l /var/log/myapp.log\n```\n\nwill start the app undaemonized in the terminal and redirect all stdout and stderr to the specified logfile.\n\n```\n./bin/myapp -p 8080 -d -P /var/run/myapp.pid -l /var/log/myapp.log\n```\n\nwill daemonize and start the process, storing the pid in the specified pid file.\nAll stdout and stderr will be redirected to the specified logfile. If no logfile is specified in daemon mode then all \nstdout and stderr will be directed to /var/log/\u003cmyapp name\u003e.log.\n\n```\n./bin/myapp -k -P /var/run/myapp.pid\n```\n\nwill stop all daemonized processes for the specified pid file.\n\n```\n./bin/myapp --help\n```\n\nWill return a useful help banner message explaining the simple usage.\n\n### Advanced\n\nIn many cases, you will need to add custom flags/options or a custom description to your executable. You can do this\neasily by using `Dante::Runner` more explicitly:\n\n```ruby\n#!/usr/bin/env ruby\n\nrequire File.expand_path(\"../../myapp.rb\", __FILE__)\n\n# Set default port to 8080\nrunner = Dante::Runner.new('myapp', :port =\u003e 8080)\n# Sets the description in 'help'\nrunner.description = \"This is myapp\"\n# Setup custom 'test' option flag\nrunner.with_options do |opts|\n  opts.on(\"-t\", \"--test TEST\", String, \"Test this thing\") do |test|\n    options[:test] = test\n  end\nend\n# Create validation hook for options\nrunner.verify_options_hook = lambda { |opts|\n  raise Exception.new(\"Must supply test parameter\") if opts[:test].nil?\n}\n# Parse command-line options and execute the process\nrunner.execute do |opts|\n  # opts: host, pid_path, port, daemonize, user, group\n  Thin::Server.start('0.0.0.0', opts[:port]) do\n    puts opts[:test] # Referencing my custom option\n    use Rack::CommonLogger\n    use Rack::ShowExceptions\n    run MyApp\n  end\nend\n```\n\nNow you would be able to do:\n\n```\n./bin/myapp -t custom\n```\n\nand the `opts` would contain the `:test` option for use in your script. In addition, help will now contain\nyour customized description in the banner.\n\nYou can also use dante programmatically to start, stop and restart arbitrary code:\n\n```ruby\n# daemon start\nDante::Runner.new('gitdocs').execute(:daemonize =\u003e true, :pid_path =\u003e @pid, :log_path =\u003e @log_path) { something! }\n# daemon stop\nDante::Runner.new('gitdocs').execute(:kill =\u003e true, :pid_path =\u003e @pid)\n# daemon restart\nDante::Runner.new('gitdocs').execute(:daemonize =\u003e true, :restart =\u003e true, :pid_path =\u003e @pid) { something! }\n```\n\nso you can use dante as part of a more complex CLI executable.\n\n## God\n\nDante can be used well in conjunction with the excellent God process manager. Simply, use Dante to daemonize a process\nand then you can easily use God to monitor:\n\n```ruby\n# /etc/god/myapp.rb\n\nGod.watch do |w|\n  w.name            = \"myapp\"\n  w.interval        = 30.seconds\n  w.start           = \"ruby /path/to/myapp/bin/myapp -d\"\n  w.stop            = \"ruby /path/to/myapp/bin/myapp -k\"\n  w.start_grace     = 15.seconds\n  w.restart_grace   = 15.seconds\n  w.pid_file        = \"/var/run/myapp.pid\"\n\n  w.behavior(:clean_pid_file)\n\n  w.start_if do |start|\n    start.condition(:process_running) do |c|\n      c.interval = 5.seconds\n      c.running = false\n    end\n  end\nend\n```\n\nand that's all. Of course now you can also easily daemonize as well as start/stop the process on the command line as well.\n\n## Copyright\n\nCopyright © 2011 Nathan Esquenazi. See [LICENSE](https://github.com/bazaarlabs/dante/blob/master/LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnesquena%2Fdante","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnesquena%2Fdante","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnesquena%2Fdante/lists"}