summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorPreston Cody <codeman@gentoo.org>2007-12-26 05:18:17 +0000
committerPreston Cody <codeman@gentoo.org>2007-12-26 05:18:17 +0000
commit81ccb2db0a61d3b6b89a9926bef210d3058977be (patch)
tree3662c08d7065a32b3bd37e5f778246a4695e17bf /server
parentmove connection string building into its own function (diff)
downloadscire-81ccb2db0a61d3b6b89a9926bef210d3058977be.tar.gz
scire-81ccb2db0a61d3b6b89a9926bef210d3058977be.tar.bz2
scire-81ccb2db0a61d3b6b89a9926bef210d3058977be.zip
copied config reading from the client
added DBI. added connection code. tested, works. svn path=/branches/new-fu/; revision=264
Diffstat (limited to 'server')
-rwxr-xr-xserver/scireserver.pl36
1 files changed, 33 insertions, 3 deletions
diff --git a/server/scireserver.pl b/server/scireserver.pl
index 2c7a718..30251e5 100755
--- a/server/scireserver.pl
+++ b/server/scireserver.pl
@@ -2,13 +2,25 @@
use strict;
use warnings;
+use DBI;
+use Data::Dumper;
$| = 1;
-my $jobdir = "/tmp/scirejobs";
+
+my $SCIRE_CONFIG_FILE = '../etc/scireserver.conf'; #will be /etc/scire.conf when released.
+my %conf;
+
+my $conf_file = (defined($conf{config})) ? $conf{config} : $SCIRE_CONFIG_FILE;
+read_config_file($conf_file);
+Dumper(\%conf);
+#Connect to the Database.
+my $connect_string = "DBI:$conf{db_type}:$conf{db_name};host=$conf{db_host}";
+#print STDERR "Connecting to $connect_string\n";
+my $dbh = DBI->connect($connect_string, $conf{db_user}, $conf{db_passwd}, { RaiseError => 1 } )
+ or die "Could not connect to database: $DBI::errstr";
while(<>) {
- my $line = $_;
- chomp $line;
+ chomp( my $line = $_);
if($line =~ /^IDENTIFY (.+)$/) {
my $rand_int = int(rand(3));
if($rand_int == 0) {
@@ -25,3 +37,21 @@ while(<>) {
print "ERROR Unknown command\n";
}
}
+
+
+sub read_config_file {
+ my $conf_file = shift;
+ open(FH, "< ${conf_file}") or die("Couldn't open the config file ${conf_file}: $!");
+ while (<FH>) {
+ chomp;
+ next if /^\s*(?:#|$)/;
+ if(/^\s*(.+?)\s*=\s*(.+?)\s*(?:#.*)?$/) {
+ unless(defined($conf{lc($1)})) { #Don't overwrite anything specified in cmdline
+ $conf{lc($1)} = $2;
+ }
+ }
+ }
+ close(FH) or die("Couldn't close the config file ${conf_file}: $!");
+# print "Conf file $conf_file read.\n";
+}
+