[pskmail] server/fldigi monitor/restart script for testing

  • From: "Rein Couperus" <rein@xxxxxxxxxxxx>
  • To: pskmail@xxxxxxxxxxxxx
  • Date: Thu, 28 Jun 2012 09:51:18 +0200 (CEST)

I am testing a small perl script which  (re-)starts fldigi and the pskmail server 
after a crash.

It will work when you can normally start fldigi with 'fldigi' and the server 
with 'pskmail_server'.

The script monitors the ~/.fldigi/status_log.txt file, and when it does 
not see any action for 5 minutes it kills the server and the modem, 
and restarts them in the right sequence.
The automatic mode switching will generate at least one file change per minute...

This works also when there is a problem on server...

To start using the script:
* Grab a terminal
* Copy flmon.pl into your user directory (cp flmon.pl ~)
* Make the script executable (chmod +x flmon.pl)
* Start the script in quiet mode (./flmon.pl quiet)

You will see the server and fldigi being killed, and restarted.
Leave the flmon running...

I am interested to know if this also works for you...

73,

Rein PA0R

(ps: the PI4TUE server has an fldigi crash abt 1x per week at the moment...)

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

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

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

        # 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) {
                
                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());
                
                print "Starting at $tm \n";
                
                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);
        
                if ($mode == 0) { 
                        print "file $file was updated $update seconds ago\n";
                }
                
#               print $update, "\n";

                if ($update > 300) { # max. 5 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`;
                                }
                                
                                
                }       elsif ($update > 120) {
                        print "Fldigi sleeping? No uodates since $update 
seconds\n";
                }
                
                sleep 10;  # look every 10 seconds

        }
        
}

exit (0);

Other related posts:

  • » [pskmail] server/fldigi monitor/restart script for testing - Rein Couperus