Switched from Auto-Flatfile to SQLite for database backend.

This commit is contained in:
Elijah Perrault committed 2011-02-09 20:16:32 -07:00
1 parent a0c58bb471
commit cd2d91a430
3 files changed
+15 -8

No files matched your search

+12 -6
View File
@@ -14,6 +14,8 @@ use feature qw(switch);
use Sys::Hostname; use Sys::Hostname;
use IO::Socket; use IO::Socket;
use IO::Select; use IO::Select;
use DBI;
use DBD::SQLite;
use Class::Unload; use Class::Unload;
use FindBin qw($Bin); use FindBin qw($Bin);
our $Bin = $Bin; ## no critic qw(NamingConventions::Capitalization Variables::ProhibitPackageVars) our $Bin = $Bin; ## no critic qw(NamingConventions::Capitalization Variables::ProhibitPackageVars)
@@ -33,7 +35,7 @@ BEGIN {
use Lib::Auto; use Lib::Auto;
use API::Std qw(conf_get err); use API::Std qw(conf_get err);
use API::Log qw(println alog dbug); use API::Log qw(println alog dbug);
use DB::Flatfile; #use DB::Flatfile;
use Parser::Config; use Parser::Config;
use Parser::Lang; use Parser::Lang;
use Parser::IRC; use Parser::IRC;
@@ -165,8 +167,12 @@ println ' Success';
# Expire old logs. # Expire old logs.
API::Log::expire_logs(); API::Log::expire_logs();
# Load database. # Connect to database.
DB::load(); if (!-e "$Bin/../etc/auto.db") {
system "touch $Bin/../etc/auto.db";
system "chmod a+x $Bin/../etc/auto.db";
}
our $DB = DBI->connect("dbi:SQLite:dbname=$Bin/../etc/auto.db", q{}, q{});
# Parse privileges. # Parse privileges.
our (%PRIVILEGES); our (%PRIVILEGES);
@@ -451,7 +457,7 @@ sub signal_term
{ {
API::Std::event_run('on_sigterm'); API::Std::event_run('on_sigterm');
foreach (keys %SOCKET) { API::IRC::quit($_, 'Caught SIGTERM'); } foreach (keys %SOCKET) { API::IRC::quit($_, 'Caught SIGTERM'); }
DB::flush(); $DB->disconnect;
dbug '!!! Caught SIGTERM; terminating...'; dbug '!!! Caught SIGTERM; terminating...';
alog '!!! Caught SIGTERM; terminating...'; alog '!!! Caught SIGTERM; terminating...';
if (-e "$Bin/auto.pid") { if (-e "$Bin/auto.pid") {
@@ -466,7 +472,7 @@ sub signal_int
{ {
API::Std::event_run('on_sigint'); API::Std::event_run('on_sigint');
foreach (keys %SOCKET) { API::IRC::quit($_, 'Caught SIGINT'); } foreach (keys %SOCKET) { API::IRC::quit($_, 'Caught SIGINT'); }
DB::flush(); $DB->disconnect;
dbug '!!! Caught SIGINT; terminating...'; dbug '!!! Caught SIGINT; terminating...';
alog '!!! Caught SIGINT; terminating...'; alog '!!! Caught SIGINT; terminating...';
if (-e "$Bin/auto.pid") { if (-e "$Bin/auto.pid") {
@@ -504,7 +510,7 @@ sub signal_perldie
return if $EXCEPTIONS_BEING_CAUGHT; return if $EXCEPTIONS_BEING_CAUGHT;
alog 'Perl Fatal: '.$diemsg.' -- Terminating program!'; alog 'Perl Fatal: '.$diemsg.' -- Terminating program!';
foreach (keys %SOCKET) { API::IRC::quit($_, 'A fatal error occurred!'); } foreach (keys %SOCKET) { API::IRC::quit($_, 'A fatal error occurred!'); }
DB::flush(); $DB->disconnect;
if (-e "$Bin/auto.pid") { if (-e "$Bin/auto.pid") {
unlink "$Bin/auto.pid"; unlink "$Bin/auto.pid";
} }
+1
View File
@@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log
3.0 Indev 3.0 Indev
================================================================== ==================================================================
* Switched from Auto-Flatfile to SQLite for database backend.
* Added a Badwords module. * Added a Badwords module.
* Added kick() to API::IRC. * Added kick() to API::IRC.
* Added DBI and DBD::SQLite to core dependencies. * Added DBI and DBD::SQLite to core dependencies.
+2 -2
View File
@@ -144,7 +144,7 @@ sub cmd_shutdown
dbug "Got SHUTDOWN from ".$data{nick}."!".$data{user}."@".$data{host}."/".$data{svr}."! Shutting down. . ."; dbug "Got SHUTDOWN from ".$data{nick}."!".$data{user}."@".$data{host}."/".$data{svr}."! Shutting down. . .";
alog "Got SHUTDOWN from ".$data{nick}."!".$data{user}."@".$data{host}."/".$data{svr}."! Shutting down. . ."; alog "Got SHUTDOWN from ".$data{nick}."!".$data{user}."@".$data{host}."/".$data{svr}."! Shutting down. . .";
quit($_, "SHUTDOWN from ".$data{nick}."/".$data{svr}) foreach (keys %Auto::SOCKET); quit($_, "SHUTDOWN from ".$data{nick}."/".$data{svr}) foreach (keys %Auto::SOCKET);
DB::flush(); $Auto::DB->disconnect;
system("rm $Auto::Bin/auto.pid"); system("rm $Auto::Bin/auto.pid");
exit; exit;
@@ -166,7 +166,7 @@ sub cmd_restart
dbug "Got RESTART from ".$data{nick}."!".$data{user}."@".$data{host}."/".$data{svr}."! Restarting. . ."; dbug "Got RESTART from ".$data{nick}."!".$data{user}."@".$data{host}."/".$data{svr}."! Restarting. . .";
alog "Got RESTART from ".$data{nick}."!".$data{user}."@".$data{host}."/".$data{svr}."! Restarting. . ."; alog "Got RESTART from ".$data{nick}."!".$data{user}."@".$data{host}."/".$data{svr}."! Restarting. . .";
quit($_, "RESTART from ".$data{nick}."/".$data{svr}) foreach (keys %Auto::SOCKET); quit($_, "RESTART from ".$data{nick}."/".$data{svr}) foreach (keys %Auto::SOCKET);
DB::flush(); $Auto::DB->disconnect;
system("rm $Auto::Bin/auto.pid") if -e "$Auto::Bin/auto.pid"; system("rm $Auto::Bin/auto.pid") if -e "$Auto::Bin/auto.pid";
# Time to come back from the dead! # Time to come back from the dead!