Permalink
Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 55 lines (42 sloc) 1.46 KB
#!/usr/bin/env ruby
# coding: utf-8
require 'time_tap'
TimeTap.load_user_config!
require 'optparse'
OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options]"
opts.on("-f", "--foreground", "Run in foreground (default).") do
TimeTap.config[:background] = false
end
opts.on("-b", "--background", "Run in background.") do
TimeTap.config[:background] = true
end
opts.on("-p", "--port PORT", "Use specified port for server. (default #{TimeTap.config['port']})") do |value|
TimeTap.config[:port] = value
end
opts.on("-l", "--log-level LEVEL", "Use specified port for server. (default #{TimeTap.config['port']})") do |value|
TimeTap.config[:log_level] = value
end
opts.on("-i", "--install", "Sets TimeTap to be launched automatically at login, and boots it.") do
TimeTap.install_launcher!
TimeTap.install_config!
TimeTap.reload_launcher!
# TimeTap::reload_launcher! uses `exec` so it never gets here
exit
end
end.parse!
TimeTap.config[:foreground] = !TimeTap.config[:background]
if TimeTap.config[:background]
require 'time_tap/daemon'
pid = fork {
# Try to replace "ruby" with "TimeTap" in the command string (for "ps -A" & co.)
$0 = 'TimeTap'
Process.daemon(true)
TimeTap.start
}
else
TimeTap.logger = Logger.new($stdout)
TimeTap.logger.level = Logger.const_get(TimeTap.config[:log_level].upcase) if TimeTap.config[:log_level]
TimeTap.logger.info '[TimeTap] Going foreground...'
TimeTap.start
end