From c74868872258600e2c3a299510121cc0d84a6abc Mon Sep 17 00:00:00 2001 From: Sho Hashimoto Date: Sun, 4 Jul 2010 19:41:09 +0900 Subject: [PATCH 1/1] start/stop ttserver --- History.txt | 4 ++ Manifest.txt | 11 ++++ PostInstall.txt | 7 +++ README.rdoc | 48 +++++++++++++++++++ Rakefile | 26 ++++++++++ lib/shinagawaseaside.rb | 74 ++++++++++++++++++++++++++++++ lib/shinagawaseaside/ShinagawaSeaside.rb | 6 ++ lib/shinagawaseaside/task.rb | 3 + samples/Rakefile | 8 +++ script/console | 10 ++++ script/destroy | 14 ++++++ script/generate | 14 ++++++ test/test_helper.rb | 3 + test/test_shinagawaseaside.rb | 11 ++++ 14 files changed, 239 insertions(+), 0 deletions(-) create mode 100644 History.txt create mode 100644 Manifest.txt create mode 100644 PostInstall.txt create mode 100644 README.rdoc create mode 100644 Rakefile create mode 100644 lib/shinagawaseaside.rb create mode 100644 lib/shinagawaseaside/ShinagawaSeaside.rb create mode 100644 lib/shinagawaseaside/task.rb create mode 100644 samples/Rakefile create mode 100755 script/console create mode 100755 script/destroy create mode 100755 script/generate create mode 100644 test/test_helper.rb create mode 100644 test/test_shinagawaseaside.rb diff --git a/History.txt b/History.txt new file mode 100644 index 0000000..88be685 --- /dev/null +++ b/History.txt @@ -0,0 +1,4 @@ +=== 0.0.1 2010-07-04 + +* 1 major enhancement: + * Initial release diff --git a/Manifest.txt b/Manifest.txt new file mode 100644 index 0000000..4dc2ef9 --- /dev/null +++ b/Manifest.txt @@ -0,0 +1,11 @@ +History.txt +Manifest.txt +PostInstall.txt +README.rdoc +Rakefile +lib/shinagawaseaside.rb +script/console +script/destroy +script/generate +test/test_helper.rb +test/test_shinagawaseaside.rb diff --git a/PostInstall.txt b/PostInstall.txt new file mode 100644 index 0000000..3e3dbdd --- /dev/null +++ b/PostInstall.txt @@ -0,0 +1,7 @@ + +For more information on shinagawaseaside, see http://shinagawaseaside.rubyforge.org + +NOTE: Change this information in PostInstall.txt +You can also delete it if you don't want it. + + diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..2ae4aaa --- /dev/null +++ b/README.rdoc @@ -0,0 +1,48 @@ += shinagawaseaside + +* http://github.com/#{github_username}/#{project_name} + +== DESCRIPTION: + +FIX (describe your package) + +== FEATURES/PROBLEMS: + +* FIX (list of features or problems) + +== SYNOPSIS: + + FIX (code sample of usage) + +== REQUIREMENTS: + +* FIX (list of requirements) + +== INSTALL: + +* FIX (sudo gem install, anything else) + +== LICENSE: + +(The MIT License) + +Copyright (c) 2010 FIXME full name + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..7edef5d --- /dev/null +++ b/Rakefile @@ -0,0 +1,26 @@ +require 'rubygems' +gem 'hoe', '>= 2.1.0' +require 'hoe' +require 'fileutils' +require './lib/shinagawaseaside' + +Hoe.plugin :newgem +# Hoe.plugin :website +# Hoe.plugin :cucumberfeatures + +# Generate all the Rake tasks +# Run 'rake -T' to see list of generated tasks (from gem root directory) +$hoe = Hoe.spec 'shinagawaseaside' do + self.developer 'FIXME full name', 'FIXME email' + self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required + self.rubyforge_name = self.name # TODO this is default value + # self.extra_deps = [['activesupport','>= 2.0.2']] + +end + +require 'newgem/tasks' +Dir['tasks/**/*.rake'].each { |t| load t } + +# TODO - want other tests/tasks run by default? Add them to the list +# remove_task :default +# task :default => [:spec, :features] diff --git a/lib/shinagawaseaside.rb b/lib/shinagawaseaside.rb new file mode 100644 index 0000000..e2e6827 --- /dev/null +++ b/lib/shinagawaseaside.rb @@ -0,0 +1,74 @@ +$:.unshift(File.dirname(__FILE__)) unless + $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) + +module ShinagawaSeaside + VERSION = '0.0.1' + + def ShinagawaSeaside::set(ttdb, opts) + p ttdb + p opts + + ttdb = ttdb.map{|db| + name = db[:name] + port = db[:port].to_i + basedir = opts[:basedir] + { + :cmd => 'ttserver', + :basedir => basedir, + :name => name, + :port => port, + :pidfile => "#{basedir}/#{name}.pid", + :dbname => "#{basedir}/#{name}.tch#bnum=1000000" + } + } + + desc 'start TokyoTyrant server' + task 'ttstart' do + puts 'starting TokyoTyrant servers..' + for tt in ttdb do + Dir.mkdir(tt[:basedir]) if !File.exists?(tt[:basedir]) + puts '' + puts "name=>#{tt[:name]}, port=>#{tt[:port]}, pid=>#{tt[:pidfile]}" + if File.exists?(tt[:pidfile]) + pid = open(tt[:pidfile]).read + puts "existing process - pid:#{pid}" + else + system("#{tt[:cmd]} -port #{tt[:port]} -dmn -pid #{tt[:pidfile]} #{tt[:dbname]}") + puts 'done' + end + end + end + + desc 'stop TokyoTyrant server' + task 'ttstop' do + puts 'stopping TokyoTyrant servers..' + for tt in ttdb do + if File.exists?(tt[:pidfile]) + pid = open(tt[:pidfile]).read + puts '' + puts "name=>#{tt[:name]}, port=>#{tt[:port]}, pid=>#{pid}" + system("kill -TERM #{pid}") + count = 0 + loop do + sleep 0.1 + if !File.exists?(tt[:pidfile]) + puts 'done' + break + end + if (count+=1) > 100 + puts "hanging process - pid:#{pid}" + break + end + end + else + puts 'no process found' + end + end + end + + desc 'restart TokyoTyrant server' + task 'ttrestart' => ['ttstop', 'ttstart'] + + end + +end diff --git a/lib/shinagawaseaside/ShinagawaSeaside.rb b/lib/shinagawaseaside/ShinagawaSeaside.rb new file mode 100644 index 0000000..83878b0 --- /dev/null +++ b/lib/shinagawaseaside/ShinagawaSeaside.rb @@ -0,0 +1,6 @@ + +module ShinagawaSeaside::Task +desc 'shinagawa' +task 'shinagawa' do + puts 'start shinagawa' +end diff --git a/lib/shinagawaseaside/task.rb b/lib/shinagawaseaside/task.rb new file mode 100644 index 0000000..027a711 --- /dev/null +++ b/lib/shinagawaseaside/task.rb @@ -0,0 +1,3 @@ + +puts 'load task' + diff --git a/samples/Rakefile b/samples/Rakefile new file mode 100644 index 0000000..cd27e6f --- /dev/null +++ b/samples/Rakefile @@ -0,0 +1,8 @@ +require 'rubygems' +require '../lib/shinagawaseaside' + +ttdb = [ { :name => 'users', :port => 20010}, + { :name => 'videos',:port => 20011}, + { :name => 'comments', :port => 20012} ] + +ShinagawaSeaside::set(ttdb, :basedir => File.dirname(__FILE__)+'/ttdb') diff --git a/script/console b/script/console new file mode 100755 index 0000000..e061bac --- /dev/null +++ b/script/console @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby +# File: script/console +irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb' + +libs = " -r irb/completion" +# Perhaps use a console_lib to store any extra methods I may want available in the cosole +# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}" +libs << " -r #{File.dirname(__FILE__) + '/../lib/shinagawaseaside.rb'}" +puts "Loading shinagawaseaside gem" +exec "#{irb} #{libs} --simple-prompt" \ No newline at end of file diff --git a/script/destroy b/script/destroy new file mode 100755 index 0000000..e48464d --- /dev/null +++ b/script/destroy @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) + +begin + require 'rubigen' +rescue LoadError + require 'rubygems' + require 'rubigen' +end +require 'rubigen/scripts/destroy' + +ARGV.shift if ['--help', '-h'].include?(ARGV[0]) +RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit] +RubiGen::Scripts::Destroy.new.run(ARGV) diff --git a/script/generate b/script/generate new file mode 100755 index 0000000..c27f655 --- /dev/null +++ b/script/generate @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) + +begin + require 'rubigen' +rescue LoadError + require 'rubygems' + require 'rubigen' +end +require 'rubigen/scripts/generate' + +ARGV.shift if ['--help', '-h'].include?(ARGV[0]) +RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit] +RubiGen::Scripts::Generate.new.run(ARGV) diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..33220e8 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,3 @@ +require 'stringio' +require 'test/unit' +require File.dirname(__FILE__) + '/../lib/shinagawaseaside' diff --git a/test/test_shinagawaseaside.rb b/test/test_shinagawaseaside.rb new file mode 100644 index 0000000..e5c4020 --- /dev/null +++ b/test/test_shinagawaseaside.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/test_helper.rb' + +class TestShinagawaseaside < Test::Unit::TestCase + + def setup + end + + def test_truth + assert true + end +end -- 1.6.3