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}"
endTen 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]

Kanały IRC![[Dilber w Onecie]](/images/larry.png)


Tak z ciekawości: dlaczego svnserve?
Subversion chyba lepiej działa z kontenera WEBDAV (Apache).
A jeśli Apache jest zbyt zasobożerny to osobiście wolałbym svn+ssh. Rozwiązanie bezpieczniejsze i łatwe w limitowaniu uprawnień.
Nie mam Apache, tylko Lighttpd.