nesquena/dante sits at 326 stars on GitHub, written primarily in Ruby. Turn any ruby code into a daemon.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Dante is the simplest possible thing that will work to turn arbitrary ruby code into an executable that
can be started via command line or start/stop a daemon, and will store a pid file for you.
If you need to create a ruby executable and you want standard daemon start/stop with pid files
and no hassle, this gem will be a great way to get started.
Requirements
Dante daemonizes with fork, so it needs MRI (CRuby) 2.7 or newer on Unix: Linux, macOS or a BSD. It does not
run on Windows or JRuby, which have no fork.
Installation
Add to your Gemfile:
# Gemfile
gem "dante"
or to your gemspec:
# mygem.gemspec
Gem::Specification.new do |s|
s.add_dependency "dante"
end
Usage
Dante 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:
#!/usr/bin/env ruby
require File.expand_path("../../myapp.rb", __FILE__)
Dante.run('myapp') do |opts|
# opts: host, pid_path, port, daemonize, user, group
Thin::Server.start('0.0.0.0', opts[:port]) do
use Rack::CommonLogger
use Rack::ShowExceptions
run MyApp
end
end
Be sure to properly make your bin executable:
chmod +x bin/myapp
CLI
This gives your binary several useful things for free:
./bin/myapp
will start the app undaemonized in the terminal, handling trapping and stopping the process.
./bin/myapp -l /var/log/myapp.log
will start the app undaemonized in the terminal and redirect all stdout and stderr to the specified logfile.
will daemonize and start the process, storing the pid in the specified pid file. It reports the daemon as
started once the daemon has kept running for a second, and as not started if it exits before then.
All stdout and stderr will be redirected to the specified logfile. If no logfile is specified in daemon mode then all
stdout and stderr will be directed to /var/log/.log.
will switch to the user nobody before starting, with the group given by -G. When started as root, the group
defaults to the user's primary group, and the process takes on the user's supplementary groups (plus the -G
group, if given). The switch happens before the pid file and the log file are written, so both must be in
directories that user can write: the defaults, /var/run/myapp.pid and /var/log/myapp.log, are not, and the
daemon would fail to start. Keep the pid file and the log in directories that only the daemon's user (or root) can
write, never in one that other users can write, such as /tmp: another user could put a file or a symlink of
their own at that path. On most Linux systems /var/run is emptied at boot, so create its directory at each boot
(systemd's RuntimeDirectory=, below, or a tmpfiles.d entry) rather than once.
./bin/myapp -k -P /var/run/myapp.pid
will stop the daemon whose pid is in the specified pid file: it sends SIGTERM, waits up to 5 seconds for the
daemon to exit, and then removes the pid file. If the daemon is still running, it says "Failed to kill daemonized
process" and keeps the pid file.
./bin/myapp -k -f -P /var/run/myapp.pid
will do the same, and if the daemon survives SIGTERM, send it SIGKILL (-f/--force, or :force => true) and
wait up to 5 more seconds.
./bin/myapp --help
Will return a useful help banner message explaining the simple usage. These are all the built-in options:
-p, --port PORT Specify port
(default: )
-P, --pid FILE save PID in FILE when using -d option.
(default: /var/run/myapp.pid)
-d, --daemon Daemonize mode
-l, --log FILE Logfile for output
(default: /var/log/myapp.log)
-k, --kill [PORT] Stop the daemon in the pid file (PORT is ignored)
-u, --user USER User to run as
-G, --group GROUP Group to run as
-f, --force Force kill if SIGTERM fails
-?, --help Display this usage information.
Advanced
In many cases, you will need to add custom flags/options or a custom description to your executable. You can do this
easily by using Dante::Runner more explicitly:
#!/usr/bin/env ruby
require File.expand_path("../../myapp.rb", __FILE__)
# Set default port to 8080
runner = Dante::Runner.new('myapp', :port => 8080)
# Sets the description in 'help'
runner.description = "This is myapp"
# Setup custom 'test' option flag
runner.with_options do |opts|
opts.on("-t", "--test TEST", String, "Test this thing") do |test|
options[:test] = test
end
end
# Create validation hook for options
runner.verify_options_hook = lambda { |opts|
raise Exception.new("Must supply test parameter") if opts[:test].nil?
}
# Parse command-line options and execute the process
runner.execute do |opts|
# opts: host, pid_path, port, daemonize, user, group
Thin::Server.start('0.0.0.0', opts[:port]) do
puts opts[:test] # Referencing my custom option
use Rack::CommonLogger
use Rack::ShowExceptions
run MyApp
end
end
Now you would be able to do:
./bin/myapp -t custom
and the opts would contain the :test option for use in your script. In addition, help will now contain
your customized description in the banner.
You can also use dante programmatically to start, stop and restart arbitrary code:
so you can use dante as part of a more complex CLI executable.
Options from somewhere other than ARGV
execute parses the command-line options in ARGV. Inside a program that has options of its own (a test runner,
say, or a Rake task), pass dante the options to parse with :argv instead, to Dante::Runner.new, Dante.run
or execute:
systemd stops it with SIGTERM, which dante handles. To have dante daemonize instead, use Type=forking with the
pid file and the log in directories systemd creates for that user:
Use User= and Group= rather than -u and -G under systemd, so that the process starts as that user and the
directories systemd creates belong to it.
Log rotation
The daemon opens its log file once, for appending, and has no SIGHUP handler: SIGHUP stops it. So rotate the log
with logrotate's copytruncate, rather than a postrotate script that sends SIGHUP:
copytruncate copies the log and empties it in place, and the daemon carries on writing at the start of the
emptied file. Lines written between the copy and the truncation are lost.
God
Dante can be used well in conjunction with the excellent God process manager. Simply, use Dante to daemonize a process
and then you can easily use God to monitor:
# /etc/god/myapp.rb
God.watch do |w|
w.name = "myapp"
w.interval = 30.seconds
w.start = "ruby /path/to/myapp/bin/myapp -d"
w.stop = "ruby /path/to/myapp/bin/myapp -k"
w.start_grace = 15.seconds
w.restart_grace = 15.seconds
w.pid_file = "/var/run/myapp.pid"
w.behavior(:clean_pid_file)
w.start_if do |start|
start.condition(:process_running) do |c|
c.interval = 5.seconds
c.running = false
end
end
end
and that's all. Of course now you can also easily daemonize as well as start/stop the process on the command line as well.
TopGit's last sync did not record any GitHub topics for nesquena/dante. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on nesquena/dante?
The most recent commit recorded on nesquena/dante was 16 days ago, based on the GitHub push timestamp. The repository has 14 forks — one of the better signals of community interest.
How many stars does nesquena/dante have?
nesquena/dante has 326 GitHub stars — refresh the page for the live number, or check github.com/nesquena/dante. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What language is nesquena/dante written in?
nesquena/dante is written primarily in Ruby. GitHub's language field is based on the largest share of bytes in the default branch.
Where do I read more about nesquena/dante?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/nesquena/dante is the definitive source.
Read full README in the tab above.
Still deciding about dante?
One click hands the question to an AI along with this page — see what it says about dante.