Ruby i skrypt startowy do SVN
Opublikowane przez Jarosław Zabiełło
Subversion to świetny, darmowy system wersjonowania kodu. Jest znacznie lepszy od starego CVS’a. Niestety, nigdzie nie mogłem się doszukać skryptu startującego do serwera. Co gorsze, skrytp svnserve w ogóle nie ma opcji zapisu numeru swojego procesu co utrudnia pisanie kodu który go “zabije”. Na szczęście Linux posiada komendę pidof. Poniżej gotowy skrypt napisany w Ruby. Należy go umieścić w /etc/init.d, dodać atrybuty wykonywalności (chmod a+x subversion.rb) i dodać linki symboliczne aby startowała utomatycznie razem ze startem serwera (pod Debianem/Ubuntu robi to komenda update-rc.d -f subversion.rb defaults, pod RedHatem/CentOS/Fedorą jest do tego komenda chkconfig)
#!/usr/bin/env ruby
$USER = "nobody"
$APP = "/usr/bin/svnserve"
$DIR = "/home/SVN"
$PID = "/var/run/svnserve.pid"
def script action
def start
system(%Q|su -c "#{$APP} -d -r #{$DIR}" #{$USER}|)
system(%Q|echo `pidof -o %PPID #{$APP}` > #{$PID}|)
end
def stop
return false if not File.exists?($PID)
system(%Q|/bin/kill -TERM #{File.read($PID)}|)
true
end
print "#{$APP} #{action}..."
$defout.flush # unbuffered output
case action
when :start
start()
puts "done"
when :stop
if not stop()
puts "#{File.basename($APP)} cannot be stopped because it cannot find #{$PID}"
else
puts "done"
end
when :restart
stop()
start()
puts "done"
end
end
case ARGV.first
when "start": script :start
when "stop": script :stop
when "restart": script :restart
end
unless %w{start stop restart}.include? ARGV.first
puts "Usage: sudo #{__FILE__} {start|stop|restart}"
exit
end


Dlaczego nie uzywasz svn+httpd?
Bo nie używam httpd.