Created
July 4, 2011 19:28
-
-
Save ryansch/1063822 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'daemon_controller' | |
require 'socket' | |
REPO_DIR = '/path/to/repos' | |
WHITELIST = %w{hostthis} | |
LISTEN = '1.2.3.4' | |
PORT = '9418' | |
PID_FILE = 'git-daemon.pid' | |
LOG_FILE = 'git-daemon.log' | |
LOCK_FILE = "#{PID_FILE}.lock" | |
CWD = File.dirname(__FILE__) | |
task :default => :start | |
namespace :git do | |
def expanded_whitelist | |
WHITELIST.collect do |repo| | |
File.join(REPO_DIR, repo) | |
end.join(' ') | |
end | |
def get_controller | |
git_opts = [] | |
git_opts << "--pid-file=#{PID_FILE}" | |
git_opts << "--export-all" | |
git_opts << "--reuseaddr" | |
git_opts << "--listen=#{LISTEN}" | |
git_opts << "--base-path=#{REPO_DIR}" | |
daemonize_opts = [] | |
daemonize_opts << '-a' | |
daemonize_opts << "-e #{LOG_FILE}" | |
daemonize_opts << "-o #{LOG_FILE}" | |
daemonize_opts << "-c #{CWD}" | |
daemonize_opts << "-v" | |
controller = DaemonController.new( | |
:identifier => 'Git Daemon', | |
:start_command => "daemonize #{daemonize_opts.join ' '} /usr/local/bin/git daemon #{git_opts.join ' '} #{expanded_whitelist}", | |
:ping_command => lambda{TCPSocket.new(LISTEN, PORT)}, | |
:pid_file => PID_FILE, | |
:log_file => LOG_FILE) | |
end | |
desc "Start git-daemon" | |
task :start do | |
puts 'Starting git-daemon' | |
puts "Listening on #{LISTEN}" | |
puts "Serving: #{expanded_whitelist}" | |
controller = get_controller | |
controller.start | |
puts "Started pid: #{controller.pid}" | |
end | |
desc "Stop git-daemon" | |
task :stop do | |
puts "Stopping git-daemon" | |
controller = get_controller | |
controller.stop | |
end | |
end | |
desc "Start" | |
multitask :start => [ 'git:start' ] | |
desc "Stop" | |
multitask :stop => [ 'git:stop' ] | |
desc "Restart" | |
task :restart => [:stop, :start] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment