[pskmail] flmon.pl with working logfile...

  • From: "Rein Couperus" <rein@xxxxxxxxxxxx>
  • To: pskmail@xxxxxxxxxxxxx
  • Date: Tue, 3 Jul 2012 10:48:16 +0200 (CEST)

Hi folks,

for those who need it, here is a simplified version of flmon.pl.
flmon.pl is a script which will 
* start the pskmail server and fldigi in the right sequence
* restart server and fldigi in case fldigi crashes.

After making it executable ('chmod +x flmon.pl') you can start it with './flmon.pl'.
It will generate a logfile when you start it as './flmon.pl | tee -a flmon.log'.
The logfile contains the restart date/times.

works here...

Rein Pa0R

--
http://pa0r.blogspirit.com
#! /usr/bin/perl -w

                
use File::stat;
use Time::localtime;

my $thing = shift(@ARGV);
my $mode = 1;
 if (defined $thing) {
#        print "$thing\n";
         $mode = 0;
 }

        # fldigi status file
        $file = "$ENV{HOME}/.fldigi/status_log.txt";
        
        if (-e "$ENV{HOME}/.pskmail/fldigirunning") {
                `rm $ENV{HOME}/.pskmail/fldigirunning`;
        }
        
$pid = fork();

if ($pid == 0) {
        
        # spawning a child running the restarter...
        
#       print "starting child process \n";

();
        
        
        while (1) {
                
                $tm = ctime(time());
                
                
                print "Starting at $tm \n";
                
#               print "killing the server\n";
                `killall rflinkserver.pl`;
                
                sleep 2;
#               print "killing fldigi \n";
                `killall fldigi`;
                
                sleep 4;

                
                `touch $ENV{HOME}/.pskmail/fldigirunning`;

                `fldigi > /dev/null &`;
                
                sleep 10;
                
                `xterm -e pskmail_server > /dev/null &`;
                
                
                $tm = ctime(time());
                

                
                while (-e "$ENV{HOME}/.pskmail/fldigirunning") {        
                        sleep 30;
                }
                
        }
        
} else {
        
        sleep 10;
        
        `touch $ENV{HOME}/.fldigi/status_log.txt`;
        
#       print "starting monitor process\n";
        
        while (1) {
                                
                $td = time();
                
                $update = $td - (stat($file)->mtime);
        
                
#               print $update, "\n";

                if ($update > 300) { # max. 3 minutes...
                                $dt = ctime(time());
        
                                print "Fldigi died, restarting at $dt \n";
                                
                                `killall rflinkserver.pl`;
                                
                                sleep 2;
                                
                                `killall fldigi`;
                                
                                sleep 2;
                                
                                if (-e "$ENV{HOME}/.pskmail/fldigirunning") {   
                                        `rm $ENV{HOME}/.pskmail/fldigirunning`;
                                }
                                
                                
                }
                
                sleep 10;  # look every 10 seconds

        }
        
}

exit (0);

Other related posts:

  • » [pskmail] flmon.pl with working logfile... - Rein Couperus