BGUL 2008/11/16: Subversion na serwerze KWI

Zgodnie z obietnicą, krótka notatka jak założyć Subversion na serwerze KWI z dostępem przez SSH.

# zalogowanie sie na serwer
$ ssh username@kwi.pb.bialystok.pl

$ mkdir repos
$ cd repos

# stworzenie repozytorium
$ svnadmin create repo1

$ logout
Connection to kwi.pb.bialystok.pl closed.

I teraz możemy stworzyć podstawową strukturę katalogów repozytorium:


$ svn mkdir svn+ssh://username@kwi.pb.bialystok.pl/home/username/repos/project1/trunk -m "Tworze trunk"
$ svn mkdir svn+ssh://username@kwi.pb.bialystok.pl/home/username/repos/project1/tags -m "Tworze tags"
$ svn mkdir svn+ssh://username@kwi.pb.bialystok.pl/home/username/repos/project1/branches -m "Tworze branches"

Stworzmy jakis przykladowy projekt w C:

$ mkdir projekt
$ cd projekt
$ vim main.c 
# i wpisz jakas tresc
$ touch README.txt 
# pusty plik readme

Import projektu do repozytorium:

# będąc w katalogu projektu:
$ svn import . svn+ssh://username@kwi.pb.bialystok.pl/home/username/repos/project1/trunk -m "Poczatkowy import projektu"
Dodawanie       main.c
Dodawanie       README.txt
Zatwierdzona wersja 4.

$ cd ..
# usuwamy niepotrzebna poczatkowy katalog z projektem:
$ rm -rf projekt

# i pobieramy projekt z repozytorium
$ svn checkout svn+ssh://username@kwi.pb.bialystok.pl/home/username/repos/project1/trunk projekt
A    projekt/main.c
A    projekt/README.txt
Pobrano wersję 4.

Voila! Mamy działające repozytorium. Kilka komend do obsługi:

$ svn commit  .  -m "Wysylanie do repozytorium"
# pobieranie z repozytorium: 
$ svn up . 
# log:
$ svn log
# Dodawanie plików/katalogół do repozytorium
$ svn add nowykatalog
# podobnie jak add mamy "rm"  do usuwania, "mv" do przenoszenia itd.

Posted by Hubert Łępicki Wed, 26 Nov 2008 20:20:00 GMT


BGUL Ruby in Linux example source code

This might be useful for these present at today’s BGUL meeting, but not only. Basically, I have demonstrated how to develop simple script useful for sysadmins, that checks if web pages are up and running, and stores results in MySQL database.

Additional cleanup, error handling and comments added (in Polish, sorry).

Full code is here

main.rb

#!/usr/bin/ruby
#
# Główny plik programu
# utuchamianie:
# $ ruby main.rb
# lub
# $ ./main.rb

# Dołączamy nasze biblioteki
require 'config'
require 'site_test'

# i bibliotekę do obsługi MySQL
require 'mysql'

begin
  # Najpierw łączymy się z bazą danych
  connection = Mysql::init()
  # wpiszcie swoje dane poniżej (hasło tu jest puste, ale jak trzeba to nie zapomnijcie)
  connection.connect("localhost", "root", "", "tester")

  for url in Config.instance.urls # w pętli sprawdź wszystkie strony
    # przetestuj URL
    puts "Testuje... " +url
    test = SiteTest.new(url)
    puts Time.new.strftime('%Y-%m-%d %H:%M:%S')
    connection.query("INSERT into site_tests VALUES ('', '#{Time.new.strftime('%Y%m%d%H%M%S')}', '#{url}', '#{test.code}', '#{test.message}')")
  end

rescue Mysql::Error => e # odpowiednik sekcji "catch" z Javy/C++
  puts "Oops, mamy error bazy danych: "+e
ensure # wykonaj zawsze -> patrz "finally" w javie
  connection.close()
end

config.rb

require "yaml"
require "singleton"

# Daje dostęp do danych zapianych w pliku konfiguracyjnym
class Config
  include Singleton

  attr_reader :urls, :timeout

  def initialize
    # Pliki YAML przegląda się podobnie do plików XML przy pomocy XPath
    options = YAML::parse( File.open( "configuration.yml" ) )
    @urls = options.select("/urls/*").collect { |el| el.value }
    @timeout = options.select("/timeout")[0].value.to_i # konwersja stringa do integera
  end
end

site_test.rb

require 'net/http'
require 'uri'
require 'config'

# Klasa ta przy inicjalizacji testuje dostępność strony, zapisując we właściwościach "code" i "message" status
class SiteTest

  attr_accessor :code, :message

  def initialize(url) # konstruktor z parametrem
    begin
      adres = URI.parse(url)
      path = "/"
      path = adres.path if adres.path != ""
      req = Net::HTTP::Get.new(path)
      res = Net::HTTP.start(adres.host, adres.port) {|http|
        http.read_timeout = http.open_timeout = Config.instance.timeout
        http.request(req)
      }

      @code = res.code
      @message = res.message
    rescue Timeout::Error => e
      @code = 0
      @message = "Timeout of #{Config.instance.timeout} seconds exceeded"
    rescue SocketError =>e
      @code = -1 # tak oznaczmy sobie "inny błąd", np. nie ma takiego hosta
      @message = e.to_s
    end

  end
end
# To jest zwykły plik YAML
urls:
    - http://www.wp.pl
    - http://slashdot.org
    - http://gazeta.pl
    - http://bgul.org
    - http://microsoftruby.com

timeout: 10

Posted by Hubert Łępicki Wed, 29 Oct 2008 22:53:00 GMT


BGUL / JTeam meetings - 02.04.2008 and 09.04.2008 ][

Posted by Hubert Łępicki Wed, 09 Apr 2008 21:33:00 GMT


JTeam/Bgul Example rails 2.0 application

Posted by Hubert Łępicki Thu, 03 Apr 2008 21:36:00 GMT


BGUL / JTeam meetings - 02.04.2008 and 09.04.2008

This is announcement for our local Linux/Java community at Bialystok Technical University but… I’m a speaker at next two meetings of BGUL, together with JTeam. Subject - JRuby on Rails - I’ll try to prepare some cool examples of code that you might expect to appear on this blog this weekend / next week even before the first meeting.

Exactly when and where? This will appear on JTeam and/or BGUL web sites.

Everyone is invited!

Posted by Hubert Łępicki Fri, 28 Mar 2008 22:34:00 GMT