From db48fcdab01193cfd0fb10085fbf5f89d7c08182 Mon Sep 17 00:00:00 2001 From: "John R. Dennison" Date: Thu, 15 Apr 2021 05:19:49 +0000 Subject: [PATCH] Trap INT/TERM; add TERM signal handler; add quiting/restarting status messages --- bot.v3.1.2.pl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bot.v3.1.2.pl b/bot.v3.1.2.pl index 140d62e..7e30f77 100644 --- a/bot.v3.1.2.pl +++ b/bot.v3.1.2.pl @@ -218,6 +218,8 @@ print "\n".debug("Becoming a daemon...")."\n"; daemonize(); $SIG{HUP} = "readconfig"; # sighup = reread config file +$SIG{INT} = "writedb"; # sigint = force write of players database +$SIG{TERM} = "quit"; # sigterm = write db and quit game CONNECT: # cheese. @@ -325,6 +327,7 @@ sub parse { sts("WHO $opts{botchan}"); (my $opcmd = $opts{botopcmd}) =~ s/%botnick%/$opts{botnick}/eg; sts($opcmd); + chanmsg ("*** IdleRPG has returned ***"); $lasttime = time(); # start rpcheck() } } @@ -845,6 +848,8 @@ sub parse { else { $opts{reconnect} = 0; writedb(); + chanmsg ("IdleRPG is taking a short break and shall return shortly."); + fq (); sts("QUIT :DIE from $arg[0]",1); } } @@ -915,6 +920,8 @@ sub parse { } else { writedb(); + chanmsg("*** IdleRPG is restarting ***"); + fq(); sts("QUIT :RESTART from $arg[0]",1); close($sock); exec("perl $0"); @@ -2350,3 +2357,12 @@ sub readconfig { } } } + +# signal handler to permit sane quitting from the command line +sub quit { + $opts{reconnect} = 0; + writedb(); + chanmsg ("IdleRPG is taking a short break and shall return shortly."); + fq (); + sts("QUIT :DIE from terminal",1); +}