Sha256: f7841507743af163575c4b0e920b463cdd0bb11e06f59b888c11cfad5a47d7e0
Contents?: true
Size: 1.88 KB
Versions: 2
Compression:
Stored size: 1.88 KB
Contents
#!/usr/bin/env ruby require "bundler" Bundler.setup(:default) require "ginatra" require "logger" def logger return @logger if @logger @logger = Logger.new(STDOUT) @logger.level = Logger::INFO @logger.formatter = Proc.new {|s, t, n, msg| "[#{t}] #{msg}\n"} @logger end module Ginatra::Daemon SYMLINK_DIR = File.expand_path('~/.ginatra/symlinks') PID_FILE = File.expand_path('~/.ginatra/daemon.pid') HELP = <<HELP Usage: ginatra-daemon [ start | stop | restart | status ] Commands: start - Starts the Git Daemon servimg Ginatra's Repositories stop - Stops the Git Daemon restart - Restarts the Git Daemon status - Is the Git Daemon on or off? HELP def self.start # Create Symlinks FileUtils.mkdir_p(SYMLINK_DIR) logger.info "Creating Symlinks" dirs = Ginatra::Config.git_dirs.map{|path| Dir.glob(path)}.flatten FileUtils.ln_sf(dirs, SYMLINK_DIR) # Start Process if File.exists?(PID_FILE) logger.warn "Ginatra Daemon running at pid:#{File.new(PID_FILE).read}" else logger.info "Starting ginatra-daemon" Kernel.fork do system "git daemon --reuseaddr --base-path=#{SYMLINK_DIR} --pid-file=#{PID_FILE} #{SYMLINK_DIR}/*" end end end def self.stop # Stop Process pid = File.new(PID_FILE).read.to_i logger.warn "Sending INT to #{pid}" FileUtils.rm(PID_FILE) Process.kill(:INT, pid) # Remove Symlinks links = Dir.glob("#{SYMLINK_DIR}/*") logger.warn "Removing Symlinks" FileUtils.rm(links) end def self.restart self.stop self.start end def self.status if File.exists?(PID_FILE) logger.info "Ginatra Daemon running at pid:#{File.new(PID_FILE).read}" else logger.info "Ginatra Daemon not running" end end end command = ARGV[0] if command !~ /^(stop|status|start|restart)$/ puts Ginatra::Daemon::HELP else Ginatra::Daemon.send(command) end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ginatra-2.2.6 | bin/ginatra-daemon |
ginatra-2.2.5 | bin/ginatra-daemon |