#
#
+package main;
+
require 5.10.1;
use warnings;
die "$root/local doesn't exist, please RTFM" unless -d "$root/local";
die "$root/local/DXVars.pm doesn't exist, please RTFM" unless -e "$root/local/DXVars.pm";
- mkdir "$root/local_cmd", 0777 unless -d "$root/local_cmd";
-
+ # create some directories
+ mkdir "$root/local_cmd", 02777 unless -d "$root/local_cmd";
+ mkdir "$root/local_data", 02777 unless -d "$root/local_data";
# try to create and lock a lockfile (this isn't atomic but
# should do for now
- $lockfn = "$root/local/cluster.lck"; # lock file name
+ $lockfn = "$root/local_data/cluster.lck"; # lock file name
if (-w $lockfn) {
open(CLLOCK, "$lockfn") or die "Can't open Lockfile ($lockfn) $!";
my $pid = <CLLOCK>;
if ($pid) {
chomp $pid;
- die "Lockfile ($lockfn) and process $pid exist, another cluster running?" if kill 0, $pid;
+ if (kill 0, $pid) {
+ warn "Lockfile ($lockfn) and process $pid exist, another cluster running?\n";
+ exit 1;
+ }
}
unlink $lockfn;
close CLLOCK;
$systime = time;
}
+
use Mojo::IOLoop;
use DXVars;
+use SysVar;
+
use Msg;
use IntMsg;
use Internet;
$clusterport $mycall $decease $is_win $routeroot $me $reqreg $bumpexisting
$allowdxby $dbh $dsn $dbuser $dbpass $do_xml $systime_days $systime_daystart
$can_encode $maxconnect_user $maxconnect_node $idle_interval $log_flush_interval
- $broadcast_debug
+ $broadcast_debug
);
@inqueue = (); # the main input queue, an array of hashes
our $ending; # signal that we are ending;
our $broadcast_debug; # allow broadcasting of debug info down "enhanced" user connections
-
+our $clssecs; # the amount of cpu time the DXSpider process have consumed
+our $cldsecs; # the amount of cpu time any child processes have consumed
# send a message to call on conn and disconnect
AGWMsg::init(\&new_channel);
}
-our $io_disconnected;
-
-sub idle_loop
-{
- my $timenow = time;
-
- BPQMsg::process();
-# DXChannel::process();
-
- # $DB::trace = 0;
-
- # do timed stuff, ongoing processing happens one a second
- if ($timenow != $systime) {
- reap() if $zombies;
- $systime = $timenow;
- my $days = int ($systime / 86400);
- if ($systime_days != $days) {
- $systime_days = $days;
- $systime_daystart = $days * 86400;
- }
- IsoTime::update($systime);
- DXCron::process(); # do cron jobs
- DXCommandmode::process(); # process ongoing command mode stuff
- DXXml::process();
- DXProt::process(); # process ongoing ak1a pcxx stuff
- DXConnect::process();
- DXMsg::process();
- DXDb::process();
- DXUser::process();
- DXDupe::process();
- DXCron::process(); # do cron jobs
- IsoTime::update($systime);
- DXProt::process(); # process ongoing ak1a pcxx stuff
- DXConnect::process();
- DXUser::process();
- AGWMsg::process();
-
- Timer::handler();
- DXLog::flushall();
- }
-
- if (defined &Local::process) {
- eval {
- Local::process(); # do any localised processing
- };
- dbg("Local::process error $@") if $@;
- }
-
- while ($ending) {
- my $dxchan;
-
- dbg("DXSpider Ending $ending");
-
- unless ($io_disconnected++) {
-
- # disconnect users
- foreach $dxchan (DXChannel::get_all_users) {
- $dxchan->disconnect;
- }
-
- # disconnect nodes
- foreach $dxchan (DXChannel::get_all_nodes) {
- next if $dxchan == $main::me;
- $dxchan->disconnect(2);
- }
- $main::me->disconnect;
- }
-
- Mojo::IOLoop->stop if --$ending <= 0;
- }
-}
sub setup_start
{
}
STDOUT->autoflush(1);
+
# try to load the database
if (DXSql::init($dsn)) {
$dbh = DXSql->new($dsn);
# initialise User file system
dbg("loading user file system ...");
- DXUser->init($userfn, 1);
+ DXUser::init(1);
# look for the sysop and the alias user and complain if they aren't there
{
#open(DB::OUT, "|tee /tmp/aa");
}
+our $io_disconnected;
+
+sub idle_loop
+{
+ BPQMsg::process();
+
+ if (defined &Local::process) {
+ eval {
+ Local::process(); # do any localised processing
+ };
+ dbg("Local::process error $@") if $@;
+ }
+
+ while ($ending) {
+ my $dxchan;
+
+ dbg("DXSpider Ending $ending");
+
+ unless ($io_disconnected++) {
+
+ # disconnect users
+ foreach $dxchan (DXChannel::get_all_users) {
+ $dxchan->disconnect;
+ }
+
+ # disconnect nodes
+ foreach $dxchan (DXChannel::get_all_nodes) {
+ next if $dxchan == $main::me;
+ $dxchan->disconnect(2);
+ }
+ $main::me->disconnect;
+ }
+
+ Mojo::IOLoop->stop if --$ending <= 0;
+ }
+}
+
+sub per_sec
+{
+ my $timenow = time;
+
+ reap() if $zombies;
+ $systime = $timenow;
+ my $days = int ($systime / 86400);
+ if ($systime_days != $days) {
+ $systime_days = $days;
+ $systime_daystart = $days * 86400;
+ }
+ IsoTime::update($systime);
+ DXCron::process(); # do cron jobs
+ DXCommandmode::process(); # process ongoing command mode stuff
+ DXXml::process();
+ DXProt::process(); # process ongoing ak1a pcxx stuff
+ DXConnect::process();
+ DXMsg::process();
+ DXDb::process();
+ DXUser::process();
+ DXDupe::process();
+ DXCron::process(); # do cron jobs
+ IsoTime::update($systime);
+ DXProt::process(); # process ongoing ak1a pcxx stuff
+ DXConnect::process();
+ DXUser::process();
+ AGWMsg::process();
+
+ Timer::handler();
+ DXLog::flushall();
+}
+
+sub per_10_sec
+{
+
+}
+
+
+sub per_minute
+{
+
+}
+
+sub per_10_minute
+{
+
+}
+
+sub per_hour
+{
+
+}
+
+sub per_day
+{
+
+}
setup_start();
my $main_loop = Mojo::IOLoop->recurring($idle_interval => \&idle_loop);
my $log_flush_loop = Mojo::IOLoop->recurring($log_flush_interval => \&DXLog::flushall);
+my $cpusecs_loop = Mojo::IOLoop->recurring(5 => sub {my @t = times; $clssecs = $t[0]+$t[1]; $cldsecs = $t[2]+$t[3]});
+my $persec = Mojo::IOLoop->recurring(1 => \&per_sec);
+my $per10sec = Mojo::IOLoop->recurring(10 => \&per_10_sec);
+my $permin = Mojo::IOLoop->recurring(60 => \&per_minute);
+my $per10min = Mojo::IOLoop->recurring(600 => \&per_10_minute);
+my $perhour = Mojo::IOLoop->recurring(3600 => \&per_hour);
+my $perday = Mojo::IOLoop->recurring(86400 => \&per_day);
Web::start_node();