package ONO::Cron::Service;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################
use strict;
use ONO::IO;
use ONO::DB;
use ONO::Cron::Service::Minutely;
use ONO::Cron::Service::Hourly;
use ONO::Cron::Service::Daily;
use ONO::Cron::Service::Weekly;
use ONO::Cron::Service::Monthly;
use ONO::Cron::Service::ToolBox;
use ONO::Core;
use ONO::Lib::DateTime::ToolBox;
use ONO::Lib::Code::RandomID;
###############################################################################
# ONO
###############################################################################
#: Cron Service is ONO's non-configurable cron service, running a number of
#: important features in the background.
sub run {
#: The main Service module, used to launch all other stuff.
print "\n[RUN] ONO Service Task Manager\n";
print " I'm here: $FindBin::Bin/service.pl\n";
my (
$sec,$min,$hour,
$mday,$mon,$year,
$wday,$yday,$timestamp,
) = ONO::Lib::DateTime::ToolBox->get;
my $weekday = ucfirst ONO::Lib::DateTime::ToolBox->day_name($wday);
my $vpath = ONO::IO->path;
print " Document Root: $vpath\n";
print " Current time: $hour:$min:$sec ($mday.$mon.$year)\n";
print " Weekday: $weekday ($wday) / UNIX timestamp: $timestamp secs\n";
ONO::IO->mkpath("var/ono/data/service/lastrun",777);
ONO::IO->store("var/ono/data/service/lastrun/service.txt",$timestamp);
my $switches;
if ($ARGV[0] =~ /^-/) {
$switches = $ARGV[0];
$ARGV[0] = $ARGV[1];
}
if ($switches =~ /v/) {
print " Verbose is ON\n";
print " Use -F to force executing ALL jobs (hourly, daily, ...)\n";
print " Use -M, -H, -D, -W, O to force specific jobs to run (note that -O is monthly)\n";
} else {
print " Verbose is OFF (I'll be silent now...)\n[BYE]\n\n";
}
my $db = &connect();
my $DATA;
my $devstation_switches = "";
if (ONO::IO->devstation) {
$switches .= $devstation_switches;
}
$DATA .= ONO::Cron::Service::Minutely->run( $db,$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$timestamp,$switches);
if ($switches =~ /F/ || $switches =~ /H/ || $min == 1) {
$DATA .= ONO::Cron::Service::Hourly->run( $db,$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$timestamp,$switches);
}
if ($switches =~ /F/ || $switches =~ /D/ || ($min == 11 && $hour == 1)) {
$DATA .= ONO::Cron::Service::Daily->run( $db,$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$timestamp,$switches);
}
if ($switches =~ /F/ || $switches =~ /W/ || ($min == 21 && $hour == 2 && $wday == 2)) {
$DATA .= ONO::Cron::Service::Weekly->run( $db,$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$timestamp,$switches);
}
if ($switches =~ /F/ || $switches =~ /O/ || ($min == 31 && $hour == 3 && $mday == 3)) {
$DATA .= ONO::Cron::Service::Monthly->run( $db,$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$timestamp,$switches);
}
$DATA .= ONO::Cron::Service::ToolBox->print("ONO Service Tasks finished",$switches);
$DATA .= ONO::Cron::Service::ToolBox->print("BYE!",$switches);
ONO::IO->store("var/ono/data/service/report.txt",$DATA);
}
###############################################################################
# subroutines
###############################################################################
sub connect {
#: Connect to the main ONO database.
my $db;
if (ONO::IO->exists("etc/sql/ono.conf")) {
$db = ONO::DB->connect("ono");
}
return $db;
}
sub timestamp {
#: Generate a human-readable timestamp.
my (
$sec,$min,$hour,
$mday,$mon,$year,
$wday,$yday,$timestamp,
) = ONO::Lib::DateTime::ToolBox->get;
return "$hour:$min:$sec $mday.$mon.$year";
}
###############################################################################
# end of script
###############################################################################
1;
__END__