| 1 | 1 | simandl | #!/usr/bin/env perl |
| 2 | | | use strict; |
| 3 | | | use warnings; |
| 4 | | | use diagnostics; |
| 5 | | | |
| 6 | | | use lib "./lib"; |
| 7 | | | use HotSaNICparser; |
| 8 | | | |
| 9 | | | # read global settings |
| 10 | | | # |
| 11 | | | my %CONFIG=HotSaNICparser::get_config("./"); |
| 12 | | | |
| 13 | | | my $PIDFILE=$CONFIG{VARDIR}."/run/diagram.pid"; |
| 14 | | | my $PID=HotSaNICparser::get_pid(0,$PIDFILE,"diagram"); # <<<--- second parameter not functional yet! |
| 15 | | | if ($PID > 0) { |
| 16 | | | print "diagram process already running on PID $PID\nchecking if stalled...\n"; |
| 17 | | | if (-e $PIDFILE) { |
| 18 | | | my $runtime=time-(stat($PIDFILE))[10]; |
| 19 | | | print "process running $runtime sec\n"; |
| 20 | | | if ($runtime > 1800) { |
| 21 | | | print "Killing probably stalled diagram process on $PID\n"; |
| 22 | | | kill 9,$PID; |
| 23 | | | } |
| 24 | | | else { print "seems ok - exiting normally.\n"; exit 0; } |
| 25 | | | } |
| 26 | | | } |
| 27 | | | |
| 28 | | | open FILE,">$PIDFILE"; |
| 29 | | | print FILE $$; |
| 30 | | | close FILE; |
| 31 | | | |
| 32 | | | my $LOGNAME=$CONFIG{LOGDIR}."/diagram.log"; |
| 33 | | | |
| 34 | | | if (! -e $CONFIG{WEBDIR}) { mkdir $CONFIG{WEBDIR},0755; } |
| 35 | | | |
| 36 | | | if ( ($CONFIG{DIAGRAMLOG} ne "all") && (-e $LOGNAME) ) { unlink $LOGNAME; } |
| 37 | | | |
| 38 | | | chdir "./modules"; |
| 39 | | | opendir DIR,"."; |
| 40 | | | my @files=grep /[a-zA-Z]+/,readdir DIR; |
| 41 | | | closedir DIR; |
| 42 | | | |
| 43 | | | foreach my $entry (@files) { |
| 44 | | | if ( (-d $entry) && ($entry ne "CVS") ) { |
| 45 | | | print "----- modules/$entry -----\n"; |
| 46 | | | if (index($CONFIG{SHOW},$entry) >= 0) { |
| 47 | | | chdir "./$entry"; |
| 48 | | | if (-e "diagrams.pl") { system "./diagrams.pl"; } elsif (-e "diagrams") { system "./diagrams"; } |
| 49 | | | chdir ".."; |
| 50 | | | } |
| 51 | | | else { print "Module not in SHOW - skipping...\n"; } |
| 52 | | | } |
| 53 | | | } |
| 54 | | | |
| 55 | | | unlink $PIDFILE; |
| 56 | | | |