[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r12600: Make dbhost configureable (tor/trunk/contrib/auto-naming)



Author: weasel
Date: 2007-11-29 06:20:26 -0500 (Thu, 29 Nov 2007)
New Revision: 12600

Modified:
   tor/trunk/contrib/auto-naming/build-approved-routers
   tor/trunk/contrib/auto-naming/db-config.rb
   tor/trunk/contrib/auto-naming/db.rb
   tor/trunk/contrib/auto-naming/process-consensus
   tor/trunk/contrib/auto-naming/update-named-status.rb
Log:
Make dbhost configureable

Modified: tor/trunk/contrib/auto-naming/build-approved-routers
===================================================================
--- tor/trunk/contrib/auto-naming/build-approved-routers	2007-11-29 06:14:41 UTC (rev 12599)
+++ tor/trunk/contrib/auto-naming/build-approved-routers	2007-11-29 11:20:26 UTC (rev 12600)
@@ -30,7 +30,7 @@
 
 verbose = ARGV.first == "-v"
 
-db = Db.new($CONFIG['database']['dbname'], $CONFIG['database']['user'], $CONFIG['database']['password'])
+db = Db.new($CONFIG['database']['dbhost'], $CONFIG['database']['dbname'], $CONFIG['database']['user'], $CONFIG['database']['password'])
 
 db.transaction_begin
 named = db.query2("

Modified: tor/trunk/contrib/auto-naming/db-config.rb
===================================================================
--- tor/trunk/contrib/auto-naming/db-config.rb	2007-11-29 06:14:41 UTC (rev 12599)
+++ tor/trunk/contrib/auto-naming/db-config.rb	2007-11-29 11:20:26 UTC (rev 12600)
@@ -1,6 +1,8 @@
 $CONFIG             = {} unless $CONFIG
 $CONFIG['database'] = {} unless $CONFIG['database']
 
+# if you use postgres' "ident sameuser" auth set dbhost to ''
+$CONFIG['database']['dbhost'] = 'localhost';
 $CONFIG['database']['dbname'] = 'tornaming';
 $CONFIG['database']['user'] = 'tornaming';
 $CONFIG['database']['password'] = 'x';

Modified: tor/trunk/contrib/auto-naming/db.rb
===================================================================
--- tor/trunk/contrib/auto-naming/db.rb	2007-11-29 06:14:41 UTC (rev 12599)
+++ tor/trunk/contrib/auto-naming/db.rb	2007-11-29 11:20:26 UTC (rev 12600)
@@ -39,8 +39,8 @@
 end
 
 class Db
-	def initialize(database, user, password)
-		@dbh = DBI.connect("dbi:Pg:#{database}:localhost", user, password);
+	def initialize(host, database, user, password)
+		@dbh = DBI.connect("dbi:Pg:#{database}:#{host}", user, password);
 		@dbh['AutoCommit'] = false
 		@transaction = false
 		@pre_initial_transaction=true

Modified: tor/trunk/contrib/auto-naming/process-consensus
===================================================================
--- tor/trunk/contrib/auto-naming/process-consensus	2007-11-29 06:14:41 UTC (rev 12599)
+++ tor/trunk/contrib/auto-naming/process-consensus	2007-11-29 11:20:26 UTC (rev 12600)
@@ -31,7 +31,7 @@
 require 'db-config'
 require 'update-named-status'
 
-$db = Db.new($CONFIG['database']['dbname'], $CONFIG['database']['user'], $CONFIG['database']['password'])
+$db = Db.new($CONFIG['database']['dbhost'], $CONFIG['database']['dbname'], $CONFIG['database']['user'], $CONFIG['database']['password'])
 
 $router_cache = {}
 $nickname_cache = {}

Modified: tor/trunk/contrib/auto-naming/update-named-status.rb
===================================================================
--- tor/trunk/contrib/auto-naming/update-named-status.rb	2007-11-29 06:14:41 UTC (rev 12599)
+++ tor/trunk/contrib/auto-naming/update-named-status.rb	2007-11-29 11:20:26 UTC (rev 12600)
@@ -28,7 +28,12 @@
 require 'db-config'
 
 def do_update(verbose)
-	now = "TIMESTAMP '" + $db.query_row("SELECT max(last_seen) AS max FROM router_claims_nickname")['max'].to_s + "'"
+	now = $db.query_row("SELECT max(last_seen) AS max FROM router_claims_nickname")['max']
+	unless now == ''
+		STDERR.puts "Could not find the latest last_seen timestamp.  Is the database empty still?"
+		return
+	end
+	now = "TIMESTAMP '" + now.to_s + "'"
 
 	denamed = $db.do("
 			UPDATE router_claims_nickname
@@ -56,7 +61,7 @@
 end
 
 if __FILE__ == $0
-	$db = Db.new($CONFIG['database']['dbname'], $CONFIG['database']['user'], $CONFIG['database']['password'])
+	$db = Db.new($CONFIG['database']['dbhost'], $CONFIG['database']['dbname'], $CONFIG['database']['user'], $CONFIG['database']['password'])
 	verbose = ARGV.first == "-v"
 
 	$db.transaction_begin