From 0d00d6a8f6eaf15d2a3e5125e599f9735c85d5d6 Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 17 Mar 2015 15:03:33 -0700 Subject: added support for tmp_users db. not backward compatible with prior config files (seq_file changed to seq_dir) --- Gemfile.lock | 6 +++--- README.md | 18 ++++++++++++++++++ config/default.yaml | 6 +++--- lib/tapicero/loop.rb | 19 +++++++++++++++++++ lib/tapicero/version.rb | 2 +- lib/tapicero_daemon.rb | 20 ++++++++------------ tapicero.gemspec | 2 +- test/badconfig.yaml | 4 +--- test/config.yaml | 7 ++++--- test/integration/tmp_user_test.rb | 37 +++++++++++++++++++++++++++++++++++++ test/support/integration_test.rb | 16 ++++++++-------- test/test_helper.rb | 9 +++++++++ 12 files changed, 112 insertions(+), 34 deletions(-) create mode 100644 lib/tapicero/loop.rb create mode 100644 test/integration/tmp_user_test.rb diff --git a/Gemfile.lock b/Gemfile.lock index 5841ead..5b033ed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,9 @@ PATH remote: . specs: - tapicero (0.6) + tapicero (0.6.1) couchrest (~> 1.1.3) - couchrest_changes (~> 0.1.1) + couchrest_changes (= 0.2.0) daemons syslog_logger (~> 2.0.0) yajl-ruby (~> 1.1.0) @@ -15,7 +15,7 @@ GEM mime-types (~> 1.15) multi_json (~> 1.0) rest-client (~> 1.6.1) - couchrest_changes (0.1.1) + couchrest_changes (0.2.0) couchrest (~> 1.1.3) syslog_logger (~> 2.0.0) yajl-ruby diff --git a/README.md b/README.md index 665efa4..bf7fb27 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,24 @@ the deamon wrapper. You can do this like this: ruby -I lib lib/tapicero.rb +Changes +-------------------- + +0.6.1 + +UPGRADING: the config option 'seq_file' is no long used, now 'seq_dir' is used +(defaults to "/var/run/tapicero"). + +* prevent username and password from leaking in processlist +* support for tmp_users database + +0.6.0 + +* do not log error if the db or design doc already exists + (since another tapicero instance probably created it) +* pid now created successfully on server boot +* don't die when couchdb is restarted + License -------------------- diff --git a/config/default.yaml b/config/default.yaml index de9f279..cb43fa9 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -12,9 +12,9 @@ connection: prefix: "" suffix: "" -# file to store the last processed user record in so we can resume after -# a restart: -seq_file: "/var/log/leap/tapicero.seq" +# directory to store the sequence file, which contains the last processed record sequence +# allow us to resume after a restart +seq_dir: "/var/run/tapicero" # Configure log_file like this if you want to log to a file instead of syslog: # log_file: "/var/log/leap/tapicero.log" diff --git a/lib/tapicero/loop.rb b/lib/tapicero/loop.rb new file mode 100644 index 0000000..9c06e52 --- /dev/null +++ b/lib/tapicero/loop.rb @@ -0,0 +1,19 @@ +module Tapicero + class Loop + def listen(db_name) + loop do + begin + users = CouchRest::Changes.new(db_name) + UserEventHandler.new(users) + users.listen + Tapicero.logger.info('Lost contact with couchdb, will try again in 10 seconds') + sleep 10 + rescue SystemCallError => exc + Tapicero.logger.info('Problem connecting to couchdb (#{exc}). Will try again in 10 seconds.') + sleep 10 + retry + end + end + end + end +end diff --git a/lib/tapicero/version.rb b/lib/tapicero/version.rb index 759b47b..83ed50f 100644 --- a/lib/tapicero/version.rb +++ b/lib/tapicero/version.rb @@ -1,5 +1,5 @@ module Tapicero - VERSION = "0.6" + VERSION = "0.6.1" REQUIRE_PATHS = ['lib'] FLAGS = [] CONFIGS = ['config/default.yaml', '/etc/leap/tapicero.yaml'] diff --git a/lib/tapicero_daemon.rb b/lib/tapicero_daemon.rb index 86f924e..26f8e00 100644 --- a/lib/tapicero_daemon.rb +++ b/lib/tapicero_daemon.rb @@ -5,23 +5,19 @@ # Daemons.run('tapicero_daemon.rb') # require 'tapicero' +require 'tapicero/loop' require 'extends/couchrest' require 'tapicero/user_event_handler' module Tapicero module Daemon - while true - begin - users = CouchRest::Changes.new('users') - UserEventHandler.new(users) - users.listen - Tapicero.logger.info('Lost contact with couchdb, will try again in 10 seconds') - sleep 10 - rescue SystemCallError => exc - Tapicero.logger.info('Problem connecting to couchdb (#{exc}). Will try again in 10 seconds.') - sleep 10 - retry - end + users_thread = Thread.new do + Tapicero::Loop.new.listen('users') end + tmp_users_thread = Thread.new do + Tapicero::Loop.new.listen('tmp_users') + end + users_thread.join + tmp_users_thread.join end end diff --git a/tapicero.gemspec b/tapicero.gemspec index eae60d8..a709ef5 100644 --- a/tapicero.gemspec +++ b/tapicero.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.executables << 'tapicero' s.add_dependency "couchrest", "~> 1.1.3" - s.add_dependency "couchrest_changes", "~> 0.1.1" + s.add_dependency "couchrest_changes", "= 0.2.0" s.add_dependency "daemons" s.add_dependency "yajl-ruby", "~> 1.1.0" s.add_dependency "syslog_logger", "~> 2.0.0" diff --git a/test/badconfig.yaml b/test/badconfig.yaml index 4941806..263185a 100644 --- a/test/badconfig.yaml +++ b/test/badconfig.yaml @@ -13,8 +13,6 @@ connection: prefix: "tapicero_test" suffix: "" -# file to store the last processed user record in so we can resume after -# a restart: -seq_file: "/tmp/tapicero_test.seq" +seq_dir: "/tmp/tapicero_test" log_file: "/tmp/tapicero_test.log" log_level: debug diff --git a/test/config.yaml b/test/config.yaml index 601c104..28da68c 100644 --- a/test/config.yaml +++ b/test/config.yaml @@ -12,8 +12,9 @@ connection: prefix: "tapicero_test" suffix: "" -# file to store the last processed user record in so we can resume after -# a restart: -seq_file: "/tmp/tapicero_test.seq" log_file: "/tmp/tapicero_test.log" log_level: debug + +# the directory to store the last processed user record in so +# we can resume after a restart: +seq_dir: "/tmp/tapicero" diff --git a/test/integration/tmp_user_test.rb b/test/integration/tmp_user_test.rb new file mode 100644 index 0000000..dff8f4e --- /dev/null +++ b/test/integration/tmp_user_test.rb @@ -0,0 +1,37 @@ +require_relative '../test_helper.rb' + +class TmpUserTest < Tapicero::IntegrationTest + + def setup + TapiceroProcess.run_with_config("test/config.yaml") + create_user(false, 'tmp_users') + sleep 0.1 + end + + def teardown + delete_user(true, 'tmp_users') + end + + def test_creates_user_db + assert_database_exists user_database + end + + def test_configures_security + assert_equal config.options[:security], user_database.get('_security') + end + + def test_stores_design_docs + assert_equal ['_design/docs', '_design/syncs', '_design/transactions'], + design_docs(user_database).map{|doc| doc["id"]}.sort + end + + def test_deletes_user_db + assert_database_exists user_database + delete_user(false, 'tmp_users') + assert !host.databases.include?(user_database.name), 'user db must not exist' + end + + def design_docs(db) + db.documents(startkey: '_design', endkey: '_design'.succ)["rows"] + end +end diff --git a/test/support/integration_test.rb b/test/support/integration_test.rb index 552b0a1..86553c2 100644 --- a/test/support/integration_test.rb +++ b/test/support/integration_test.rb @@ -5,16 +5,16 @@ module Tapicero # create a dummy record for the user # so that tapicero will get a new user event # - def create_user(fast = false) - result = database.save_doc :some => :content + def create_user(fast = false, db_name = 'users') + result = database(db_name).save_doc :some => :content raise RuntimeError.new(result.inspect) unless result['ok'] sleep 1 unless fast # allow tapicero to do its job @user = {'_id' => result["id"], '_rev' => result["rev"]} end - def delete_user(fast = false) + def delete_user(fast = false, db_name = 'users') return if @user.nil? or @user['_deleted'] - result = database.delete_doc @user + result = database(db_name).delete_doc @user raise RuntimeError.new(result.inspect) unless result['ok'] @user['_deleted'] = true sleep 1 unless fast # allow tapicero to do its job @@ -26,12 +26,12 @@ module Tapicero puts 'failed to find per user db' end - def database - @database ||= host.database!(database_name) + def database(db_name='users') + @database ||= host.database!(database_name_with_prefix(db_name)) end - def database_name - config.complete_db_name('users') + def database_name_with_prefix(db_name) + config.complete_db_name(db_name) end def host diff --git a/test/test_helper.rb b/test/test_helper.rb index 31eaa2b..1442148 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -33,6 +33,15 @@ MiniTest.after_run { TapiceroProcess.kill! } +# delete prior user dbs so they don't fill up the local couchdb. +CouchRest::Server.new.tap do |server| + server.databases.each do |db_name| + if db_name =~ /^user-[a-f0-9]{32}$/ + server.database(db_name).delete! + end + end +end + puts puts " REMINDER: check /tmp/tapicero.log for errors" puts \ No newline at end of file -- cgit v1.2.3 From 25b34acce7612f58c5d40819de79734b08cdfb8f Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 17 Mar 2015 15:03:54 -0700 Subject: if using rbenv, pin ruby version to same as used on production deploy servers. --- .ruby-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..f3a9c9a --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +1.9.3-p194 -- cgit v1.2.3