]> pd.if.org Git - newsd/commitdiff
Improved robustness of server startup
authorNathan Wagner <nw@hydaspes.if.org>
Sat, 6 Oct 2012 18:59:32 +0000 (18:59 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Sat, 6 Oct 2012 18:59:32 +0000 (18:59 +0000)
Makefile
Net-Server-NNTP/lib/Net/Server/NNTP.pm
newsd

index 306b50b921260835beac1e030221e5c54da91d57..54a369c3741548371e9ae0d6f35edfbd96a0cd77 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,8 +20,8 @@ control.ctl:
 newsdb:
        -dropdb news
        createdb -O news -T template0 -E SQL_ASCII news
-       psql -d news -c 'alter database news set search_path to nntp,public'
-       psql -d news -c 'alter database news set client_min_messages to warning'
+       $(PSQL) -c 'alter database news set search_path to nntp,public'
+       $(PSQL) -c 'alter database news set client_min_messages to warning'
 
 preserve:
        sudo su -c 'psql -1 --set ON_ERROR_STOP=1 -U news -d news -f preserve.sql' news
index 3b6eb21eb4fd7d4cec4e78515741b321e6adeab2..bcc881f09c0a25d33fa03c099e4c891db19bcb54 100644 (file)
@@ -1108,10 +1108,20 @@ sub connect_to_storage {
 
        # TODO use a config parameter optionally here
        my $dsn = $ENV{'DBI_DSN'};
-       $dsn = 'dbi:Pg:dbname=news' unless defined $dsn;
+       $dsn = qq{dbi:Pg:dbname=news} unless defined $dsn;
        $s->log(4, "connecting to $dsn");
 
-       $s->{db} = DBI->connect($dsn,'','',{AutoCommit => 0,RaiseError=>1});
+       eval {
+               $s->{db} = DBI->connect($dsn,'','',{AutoCommit => 0,RaiseError=>1});
+               $s->log(4, "Can't connect to DB: $DBI::errstr") unless $s->{db};
+       };
+       if ($@) {
+               $s->log(4, "Can't connect to DB: $DBI::errstr");
+               die $@;
+       }
+       $s->log(4, "connected to $dsn");
+
+       # TODO abort if can't connect
        $s->{db}->{PrintError} = 0;
 
        $s->{db}->do("set CLIENT_ENCODING to 'SQL_ASCII'");
diff --git a/newsd b/newsd
index a84a5a3f7f62166edba37d32b2a91c18dbc1058e..babb9f6af4297d0a2c9cceb5dfea4d04e199d0b5 100755 (executable)
--- a/newsd
+++ b/newsd
@@ -3,6 +3,8 @@
 use strict;
 use warnings;
 
+$ENV{PGHOST} ||= '/var/run/postgresql';
+
 use Net::Server::NNTP::Postgres;
 
 use Carp;