Clean up shutdown.
This commit is contained in:
1 parent
55071e09d0
commit
df401193dc
4 files changed
+17
-22
No files matched your search
@@ -438,9 +438,6 @@ API::Std::cmd_add('SHUTDOWN', 2, 'cmd.shutdown', \%Core::Cmd::HELP_SHUTDOWN, \&C
|
|||||||
API::Std::cmd_add('RESTART', 2, 'cmd.restart', \%Core::Cmd::HELP_RESTART, \&Core::Cmd::cmd_restart);
|
API::Std::cmd_add('RESTART', 2, 'cmd.restart', \%Core::Cmd::HELP_RESTART, \&Core::Cmd::cmd_restart);
|
||||||
API::Std::cmd_add('REHASH', 2, 'cmd.rehash', \%Core::Cmd::HELP_REHASH, \&Core::Cmd::cmd_rehash);
|
API::Std::cmd_add('REHASH', 2, 'cmd.rehash', \%Core::Cmd::HELP_REHASH, \&Core::Cmd::cmd_rehash);
|
||||||
API::Std::cmd_add('HELP', 2, 0, \%Core::Cmd::HELP_HELP, \&Core::Cmd::cmd_help);
|
API::Std::cmd_add('HELP', 2, 0, \%Core::Cmd::HELP_HELP, \&Core::Cmd::cmd_help);
|
||||||
# Core events.
|
|
||||||
API::Std::event_add('on_shutdown');
|
|
||||||
|
|
||||||
|
|
||||||
# Infinite while loop.
|
# Infinite while loop.
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -481,9 +478,7 @@ while (1) {
|
|||||||
delete $SOCKET{$sockid};
|
delete $SOCKET{$sockid};
|
||||||
if (!keys %SOCKET) {
|
if (!keys %SOCKET) {
|
||||||
# No more connections, stop the program.
|
# No more connections, stop the program.
|
||||||
$Auto::DB->disconnect;
|
|
||||||
API::Std::event_run('on_shutdown');
|
API::Std::event_run('on_shutdown');
|
||||||
if (-e "$Bin/auto.pid") { unlink "$Bin/auto.pid"; }
|
|
||||||
dbug '* No more IRC connections, shutting down.';
|
dbug '* No more IRC connections, shutting down.';
|
||||||
alog '* No more IRC connections, shutting down.';
|
alog '* No more IRC connections, shutting down.';
|
||||||
sleep 1;
|
sleep 1;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log
|
|||||||
|
|
||||||
3.0 Indev
|
3.0 Indev
|
||||||
===============================================================================
|
===============================================================================
|
||||||
|
* Clean up shutdown.
|
||||||
* Created event on_shutdown.
|
* Created event on_shutdown.
|
||||||
* Shutdown if there are no more IRC connections.
|
* Shutdown if there are no more IRC connections.
|
||||||
* Added the ability to use printf(3) % variables in trans().
|
* Added the ability to use printf(3) % variables in trans().
|
||||||
|
|||||||
+2
-4
@@ -142,8 +142,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);
|
||||||
$Auto::DB->disconnect;
|
API::Std::event_run('on_shutdown');
|
||||||
system("rm $Auto::Bin/auto.pid");
|
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
# To appease PerlCritic.
|
# To appease PerlCritic.
|
||||||
@@ -164,8 +163,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);
|
||||||
$Auto::DB->disconnect;
|
API::Std::event_run('on_shutdown');
|
||||||
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!
|
||||||
if ($Auto::DEBUG) {
|
if ($Auto::DEBUG) {
|
||||||
|
|||||||
+14
-13
@@ -7,10 +7,13 @@ use warnings;
|
|||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use Sys::Hostname;
|
use Sys::Hostname;
|
||||||
use feature qw(switch);
|
use feature qw(switch);
|
||||||
use API::Std qw(conf_get err);
|
use API::Std qw(hook_add conf_get err);
|
||||||
use API::Log qw(println dbug alog);
|
use API::Log qw(println dbug alog);
|
||||||
our $VERSION = 3.000000;
|
our $VERSION = 3.000000;
|
||||||
|
|
||||||
|
# Core events.
|
||||||
|
API::Std::event_add('on_shutdown');
|
||||||
|
|
||||||
# Update checker.
|
# Update checker.
|
||||||
sub checkver
|
sub checkver
|
||||||
{
|
{
|
||||||
@@ -203,6 +206,13 @@ sub rehash
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Shutdown.
|
||||||
|
hook_add('on_shutdown', 'shutdown.core_cleanup', sub {
|
||||||
|
if (defined $Auto::DB) { $Auto::DB->disconnect; }
|
||||||
|
if (-e "$Auto::Bin/auto.pid") { unlink "$Auto::Bin/auto.pid"; }
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
###################
|
###################
|
||||||
# Signal handlers #
|
# Signal handlers #
|
||||||
###################
|
###################
|
||||||
@@ -211,13 +221,10 @@ sub rehash
|
|||||||
sub signal_term
|
sub signal_term
|
||||||
{
|
{
|
||||||
API::Std::event_run('on_sigterm');
|
API::Std::event_run('on_sigterm');
|
||||||
|
API::Std::event_run('on_shutdown');
|
||||||
foreach (keys %Auto::SOCKET) { API::IRC::quit($_, 'Caught SIGTERM'); }
|
foreach (keys %Auto::SOCKET) { API::IRC::quit($_, 'Caught SIGTERM'); }
|
||||||
$Auto::DB->disconnect;
|
|
||||||
dbug '!!! Caught SIGTERM; terminating...';
|
dbug '!!! Caught SIGTERM; terminating...';
|
||||||
alog '!!! Caught SIGTERM; terminating...';
|
alog '!!! Caught SIGTERM; terminating...';
|
||||||
if (-e "$Auto::Bin/auto.pid") {
|
|
||||||
unlink "$Auto::Bin/auto.pid";
|
|
||||||
}
|
|
||||||
sleep 1;
|
sleep 1;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@@ -226,13 +233,10 @@ sub signal_term
|
|||||||
sub signal_int
|
sub signal_int
|
||||||
{
|
{
|
||||||
API::Std::event_run('on_sigint');
|
API::Std::event_run('on_sigint');
|
||||||
|
API::Std::event_run('on_shutdown');
|
||||||
foreach (keys %Auto::SOCKET) { API::IRC::quit($_, 'Caught SIGINT'); }
|
foreach (keys %Auto::SOCKET) { API::IRC::quit($_, 'Caught SIGINT'); }
|
||||||
$Auto::DB->disconnect;
|
|
||||||
dbug '!!! Caught SIGINT; terminating...';
|
dbug '!!! Caught SIGINT; terminating...';
|
||||||
alog '!!! Caught SIGINT; terminating...';
|
alog '!!! Caught SIGINT; terminating...';
|
||||||
if (-e "$Auto::Bin/auto.pid") {
|
|
||||||
unlink "$Auto::Bin/auto.pid";
|
|
||||||
}
|
|
||||||
sleep 1;
|
sleep 1;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@@ -266,10 +270,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 %Auto::SOCKET) { API::IRC::quit($_, 'A fatal error occurred!'); }
|
foreach (keys %Auto::SOCKET) { API::IRC::quit($_, 'A fatal error occurred!'); }
|
||||||
$Auto::DB->disconnect;
|
API::Std::event_run('on_shutdown');
|
||||||
if (-e "$Auto::Bin/auto.pid") {
|
|
||||||
unlink "$Auto::Bin/auto.pid";
|
|
||||||
}
|
|
||||||
sleep 1;
|
sleep 1;
|
||||||
println 'FATAL: '.$diemsg;
|
println 'FATAL: '.$diemsg;
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
Reference in new issue
Block a user