Skip to content

Commit d65d4f5

Browse files
committed
Added better error handling to vlogger script in case that the mysql database connection is not available.
1 parent 6a6ebe9 commit d65d4f5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

server/scripts/vlogger

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,14 @@ if ( $OPTS{'d'} ) {
252252
}
253253

254254
# test the connection
255-
my $dbh = DBI->connect( $DBI_DSN, $DBI_USER, $DBI_PASS )
256-
or die "DBI Error: $!";
257-
$dbh->disconnect;
255+
eval {
256+
my $dbh = DBI->connect( $DBI_DSN, $DBI_USER, $DBI_PASS )
257+
or die "DBI Error: $!";
258+
$dbh->disconnect;
259+
};
260+
if ($@) {
261+
print "MySQL Connection problem\n";
262+
}
258263

259264
# SIGALRM dumps the tracker hash
260265
$SIG{ALRM} = \&dump_tracker;
@@ -503,7 +508,8 @@ sub open_errorlog {
503508

504509
# sub to update the database with the tracker data
505510
sub dump_tracker {
506-
if ( keys(%tracker) > 0 ) {
511+
eval {
512+
if ( keys(%tracker) > 0 ) {
507513
my $dbh = DBI->connect( $DBI_DSN, $DBI_USER, $DBI_PASS )
508514
or warn "DBI Error: $!";
509515
foreach my $key ( keys(%tracker) ) {
@@ -529,6 +535,10 @@ sub dump_tracker {
529535
%tracker = ();
530536
}
531537
alarm $DBI_DUMP;
538+
};
539+
if ($@) {
540+
print "Unable to store vlogger data in database\n";
541+
}
532542
}
533543

534544
# print usage info

0 commit comments

Comments
 (0)