start/stop ttserver
Sho Hashimoto [Sun, 4 Jul 2010 10:41:09 +0000 (19:41 +0900)]
14 files changed:
History.txt [new file with mode: 0644]
Manifest.txt [new file with mode: 0644]
PostInstall.txt [new file with mode: 0644]
README.rdoc [new file with mode: 0644]
Rakefile [new file with mode: 0644]
lib/shinagawaseaside.rb [new file with mode: 0644]
lib/shinagawaseaside/ShinagawaSeaside.rb [new file with mode: 0644]
lib/shinagawaseaside/task.rb [new file with mode: 0644]
samples/Rakefile [new file with mode: 0644]
script/console [new file with mode: 0755]
script/destroy [new file with mode: 0755]
script/generate [new file with mode: 0755]
test/test_helper.rb [new file with mode: 0644]
test/test_shinagawaseaside.rb [new file with mode: 0644]

diff --git a/History.txt b/History.txt
new file mode 100644 (file)
index 0000000..88be685
--- /dev/null
@@ -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 (file)
index 0000000..4dc2ef9
--- /dev/null
@@ -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 (file)
index 0000000..3e3dbdd
--- /dev/null
@@ -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 (file)
index 0000000..2ae4aaa
--- /dev/null
@@ -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 (file)
index 0000000..7edef5d
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,26 @@
+require 'rubygems'\r
+gem 'hoe', '>= 2.1.0'\r
+require 'hoe'\r
+require 'fileutils'\r
+require './lib/shinagawaseaside'\r
+\r
+Hoe.plugin :newgem\r
+# Hoe.plugin :website\r
+# Hoe.plugin :cucumberfeatures\r
+\r
+# Generate all the Rake tasks\r
+# Run 'rake -T' to see list of generated tasks (from gem root directory)\r
+$hoe = Hoe.spec 'shinagawaseaside' do\r
+  self.developer 'FIXME full name', 'FIXME email'\r
+  self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required\r
+  self.rubyforge_name       = self.name # TODO this is default value\r
+  # self.extra_deps         = [['activesupport','>= 2.0.2']]\r
+\r
+end\r
+\r
+require 'newgem/tasks'\r
+Dir['tasks/**/*.rake'].each { |t| load t }\r
+\r
+# TODO - want other tests/tasks run by default? Add them to the list\r
+# remove_task :default\r
+# task :default => [:spec, :features]\r
diff --git a/lib/shinagawaseaside.rb b/lib/shinagawaseaside.rb
new file mode 100644 (file)
index 0000000..e2e6827
--- /dev/null
@@ -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 (file)
index 0000000..83878b0
--- /dev/null
@@ -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 (file)
index 0000000..027a711
--- /dev/null
@@ -0,0 +1,3 @@
+
+puts 'load task'
+
diff --git a/samples/Rakefile b/samples/Rakefile
new file mode 100644 (file)
index 0000000..cd27e6f
--- /dev/null
@@ -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 (executable)
index 0000000..e061bac
--- /dev/null
@@ -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 (executable)
index 0000000..e48464d
--- /dev/null
@@ -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 (executable)
index 0000000..c27f655
--- /dev/null
@@ -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 (file)
index 0000000..33220e8
--- /dev/null
@@ -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 (file)
index 0000000..e5c4020
--- /dev/null
@@ -0,0 +1,11 @@
+require File.dirname(__FILE__) + '/test_helper.rb'\r
+\r
+class TestShinagawaseaside < Test::Unit::TestCase\r
+\r
+  def setup\r
+  end\r
+  \r
+  def test_truth\r
+    assert true\r
+  end\r
+end\r