Git, Bazaar, Mercurial - Subversion pod obstrzałem

Posted by Jarosław Zabiełło Wed, 19 Mar 2008 11:00:00 GMT

Świat technologii IT zmienia się coraz szybciej. Nie minęło wiele lat od dosyć masowego przechodzenia CVS do Subversion a już zanosi się na kolejną rewolucję. Tak jak wcześniej atakowany był CVS, teraz atakowany jest Subversion. Atakowany jest przez rozproszone systemy kontroli wersji.

Read more...

Tags , , , , ,  | 23 comments

Subversion /etc/init.d script

Posted by Jarosław Zabiełło Sat, 07 Oct 2006 00:57:00 GMT

Postanowiłem troszkę poprawić napisany wcześniej skrypt startowy do Subversion. Dorzuciłem też wersję w Pythonie.

#!/usr/bin/env ruby

VERBOSE = true
USER = "nobody"
APP = "/usr/bin/svnserve"
DIR = "/home/svn-repository"
PID = "/var/run/svnserve.pid"

def script action
  def start
    unless File.exists?(PID)
      system %Q|su -c "#{APP} -d -r #{DIR}" #{USER}|
      system "echo `pidof -o %PPID #{APP}` > #{PID}"
    end
  end
  def stop
    return false unless File.exists?(PID)
    system "/bin/kill -TERM #{File.read(PID)}"
    system "/bin/rm -f #{PID}"
    true
  end
  puts "#{APP} #{action}"  if VERBOSE
  $defout.flush # unbuffered output
  case action
    when :start
      start
    when :stop
      puts "#{File.basename(APP)} cannot be stopped because it cannot find #{PID}" unless stop
    when :restart
      stop
      start
  end
end

if %w{start stop restart}.include? ARGV.first
  script ARGV.first.to_sym
else
  puts "Usage: sudo #{__FILE__} {start|stop|restart}"
end

Ten sam skrypt w Pythonie:

#!/usr/bin/env python

import os, sys

VERBOSE = True
USER = "nobody"
APP = "/usr/bin/svnserve"
DIR = "/home/svn-repository"
PID = "/var/run/svnserve.pid"

def script(action):
  def start():
    if not os.path.exists(PID):
      os.system('su -c "%s -d -r %s" %s' % (APP, DIR, USER))
      os.system('echo `pidof -o %%PPID %s` > %s' % (APP, PID))
  def stop():
    if not os.path.exists(PID): return False
    os.system('/bin/kill -TERM %s' % file(PID).read())
    return True
  if VERBOSE: print "%s %s" % (APP, action),
  if action == 'start':
    start()
  elif action == 'stop':
    if not stop():
      print "%s cannot be stopped because it cannot find %s" % (os.path.basename(APP), PID)
  elif action == 'restart':
    stop()
    start()

if len(sys.argv) == 2 and sys.argv[1] in ('start', 'stop', 'restart'):
  script(sys.argv[1])
else:
  if VERBOSE:  print "Usage: sudo %s {start|stop|restart}" % sys.argv[0]

Posted in ,  | Tags , ,  | 2 comments

Ruby i skrypt startowy do SVN

Posted by Jarosław Zabiełło Thu, 05 Oct 2006 14:37:00 GMT

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

Posted in  | Tags , ,  | 2 comments