1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00

Scheduler crontab fixed

This commit is contained in:
Daniel Neto 2023-02-21 17:17:01 -03:00
parent 44d94c61b1
commit 27ed1e6819
9 changed files with 211 additions and 113 deletions

View file

@ -35,7 +35,7 @@ RUN apt update
# Install dependencies # Install dependencies
RUN apt-get update -y && apt-get upgrade -y \ RUN apt-get update -y && apt-get upgrade -y \
&& apt install -y --no-install-recommends dos2unix bash-completion lsof cron rsync ca-certificates apt-transport-https software-properties-common curl \ && apt install -y --no-install-recommends dos2unix bash-completion lsof rsyslog cron rsync ca-certificates apt-transport-https software-properties-common curl \
&& curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp \ && curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp \
&& chmod a+rx /usr/local/bin/yt-dlp \ && chmod a+rx /usr/local/bin/yt-dlp \
&& apt install -y --no-install-recommends sshpass nano net-tools curl apache2 php8.1 libapache2-mod-php8.1 php8.1-mysql php8.1-sqlite3 php8.1-curl php8.1-gd php8.1-intl \ && apt install -y --no-install-recommends sshpass nano net-tools curl apache2 php8.1 libapache2-mod-php8.1 php8.1-mysql php8.1-sqlite3 php8.1-curl php8.1-gd php8.1-intl \
@ -70,7 +70,11 @@ RUN mkdir ~/build \
COPY deploy/nginx/nginx.conf /usr/local/nginx/conf/nginx.conf COPY deploy/nginx/nginx.conf /usr/local/nginx/conf/nginx.conf
COPY deploy/crontab /etc/cron.d/crontab COPY deploy/crontab /etc/cron.d/crontab
RUN dos2unix /etc/cron.d/crontab
RUN chmod 0644 /etc/cron.d/crontab RUN chmod 0644 /etc/cron.d/crontab
RUN chmod +x /etc/cron.d/crontab
RUN service cron start
RUN crontab /etc/cron.d/crontab
# Configure AVideo # Configure AVideo
RUN dos2unix /usr/local/bin/docker-entrypoint && \ RUN dos2unix /usr/local/bin/docker-entrypoint && \

View file

@ -1,4 +1,4 @@
# m h dom mon dow command # m h dom mon dow command
1 1 * * * pip3 install --upgrade youtube-dl 1 1 * * * pip3 install --upgrade youtube-dl > /proc/1/fd/1 2>/proc/1/fd/2
* * * * * php /var/www/html/AVideo/plugin/Scheduler/run.php * * * * * php /var/www/html/AVideo/plugin/Scheduler/run.php > /proc/1/fd/1 2>/proc/1/fd/2
#2 1 * * * php /var/www/html/AVideo/plugin/CDN/tools/moveMissingFiles.php #2 1 * * * php /var/www/html/AVideo/plugin/CDN/tools/moveMissingFiles.php > /proc/1/fd/1 2>/proc/1/fd/2

View file

@ -129,10 +129,14 @@ chmod 777 /var/www/html/AVideo/videos/avideo.log
echo "deny access to .compose" echo "deny access to .compose"
echo "Deny from all" > /var/www/html/AVideo/.compose/.htaccess echo "Deny from all" > /var/www/html/AVideo/.compose/.htaccess
cd /var/www/html/AVideo/install && php updatedb.php
cd /var/www/html/AVideo/Encoder/install && php reencodeAllVideos.php
echo "crontab starting"
cron
apache2-foreground apache2-foreground
echo "apache2-foreground done" echo "apache2-foreground done"
cd /var/www/html/AVideo/install && php updatedb.php && installPluginsTables.php 4
cd /var/www/html/AVideo/Encoder/install && php reencodeAllVideos.php
#eof #eof

View file

@ -4592,7 +4592,7 @@ function remove_utf8_bom($text) {
function getCacheDir() { function getCacheDir() {
$p = AVideoPlugin::loadPlugin("Cache"); $p = AVideoPlugin::loadPlugin("Cache");
if (empty($p)) { if (empty($p)) {
return addLastSlash(sys_get_temp_dir()); return addLastSlash(_sys_get_temp_dir());
} }
return $p->getCacheDir(); return $p->getCacheDir();
} }

View file

@ -90,8 +90,6 @@ class Scheduler_commands extends ObjectYPT {
foreach ($fullData as $row) { foreach ($fullData as $row) {
$rows[] = $row; $rows[] = $row;
} }
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
} }
return $rows; return $rows;
} }
@ -112,8 +110,6 @@ class Scheduler_commands extends ObjectYPT {
foreach ($fullData as $row) { foreach ($fullData as $row) {
$rows[] = $row; $rows[] = $row;
} }
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
} }
return $rows; return $rows;
} }
@ -329,8 +325,6 @@ class Scheduler_commands extends ObjectYPT {
foreach ($fullData as $row) { foreach ($fullData as $row) {
$rows[] = $row; $rows[] = $row;
} }
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
} }
return $rows; return $rows;
} }
@ -355,8 +349,6 @@ class Scheduler_commands extends ObjectYPT {
foreach ($fullData as $row) { foreach ($fullData as $row) {
$rows[] = $row; $rows[] = $row;
} }
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
} }
return $rows; return $rows;
} }

View file

@ -6,9 +6,11 @@ require_once $global['systemRootPath'] . 'plugin/Plugin.abstract.php';
require_once $global['systemRootPath'] . 'plugin/Scheduler/Objects/Scheduler_commands.php'; require_once $global['systemRootPath'] . 'plugin/Scheduler/Objects/Scheduler_commands.php';
class Scheduler extends PluginAbstract { class Scheduler extends PluginAbstract
{
public function getDescription() { public function getDescription()
{
global $global; global $global;
$desc = "Scheduler Plugin"; $desc = "Scheduler Plugin";
if (!_isSchedulerPresentOnCrontab()) { if (!_isSchedulerPresentOnCrontab()) {
@ -17,23 +19,29 @@ class Scheduler extends PluginAbstract {
$desc .= "</strong>"; $desc .= "</strong>";
$desc .= "<br>Open a terminal and type <code>crontab -e</code> than add a crontab for every 1 minute<br><code>* * * * * php {$global['systemRootPath']}plugin/Scheduler/run.php</code>"; $desc .= "<br>Open a terminal and type <code>crontab -e</code> than add a crontab for every 1 minute<br><code>* * * * * php {$global['systemRootPath']}plugin/Scheduler/run.php</code>";
} }
$desc .= '<br>';
$desc .= getIncludeFileContent($global['systemRootPath'].'plugin/Scheduler/View/activeLabel.php');
//$desc .= $this->isReadyLabel(array('YPTWallet')); //$desc .= $this->isReadyLabel(array('YPTWallet'));
return $desc; return $desc;
} }
public function getName() { public function getName()
{
return "Scheduler"; return "Scheduler";
} }
public function getUUID() { public function getUUID()
{
return "Scheduler-5ee8405eaaa16"; return "Scheduler-5ee8405eaaa16";
} }
public function getPluginVersion() { public function getPluginVersion()
{
return "4.2"; return "4.2";
} }
public function updateScript() { public function updateScript()
{
global $global; global $global;
if (AVideoPlugin::compareVersion($this->getName(), "2.0") < 0) { if (AVideoPlugin::compareVersion($this->getName(), "2.0") < 0) {
$sqls = file_get_contents($global['systemRootPath'] . 'plugin/Scheduler/install/updateV2.0.sql'); $sqls = file_get_contents($global['systemRootPath'] . 'plugin/Scheduler/install/updateV2.0.sql');
@ -66,7 +74,8 @@ class Scheduler extends PluginAbstract {
return true; return true;
} }
public function getEmptyDataObject() { public function getEmptyDataObject()
{
$obj = new stdClass(); $obj = new stdClass();
/* /*
$obj->textSample = "text"; $obj->textSample = "text";
@ -86,15 +95,18 @@ class Scheduler extends PluginAbstract {
return $obj; return $obj;
} }
public function getPluginMenu() { public function getPluginMenu()
{
global $global; global $global;
$btn = '<button onclick="avideoModalIframeLarge(webSiteRootURL+\'plugin/Scheduler/View/editor.php\')" class="btn btn-primary btn-sm btn-xs btn-block"><i class="fa fa-edit"></i> Edit</button>'; $btn = '<button onclick="avideoModalIframeLarge(webSiteRootURL+\'plugin/Scheduler/View/editor.php\')" class="btn btn-primary btn-sm btn-xs btn-block"><i class="fa fa-edit"></i> Edit</button>';
$btn .= '<button onclick="avideoModalIframeLarge(webSiteRootURL+\'plugin/Scheduler/run.php\')" class="btn btn-primary btn-sm btn-xs btn-block"><i class="fas fa-terminal"></i> Run now</button>'; $btn .= '<button onclick="avideoModalIframeLarge(webSiteRootURL+\'plugin/Scheduler/run.php\')" class="btn btn-primary btn-sm btn-xs btn-block"><i class="fas fa-terminal"></i> Run now</button>';
return $btn; return $btn;
} }
static public function run($scheduler_commands_id) { static public function run($scheduler_commands_id)
{
global $_executeSchelude, $global; global $_executeSchelude, $global;
_error_log("Scheduler::run {$scheduler_commands_id}");
if (!isset($_executeSchelude)) { if (!isset($_executeSchelude)) {
$_executeSchelude = array(); $_executeSchelude = array();
} }
@ -102,7 +114,13 @@ class Scheduler extends PluginAbstract {
$videos_id = $e->getVideos_id(); $videos_id = $e->getVideos_id();
if (!empty($videos_id)) { // make it active if (!empty($videos_id)) { // make it active
self::releaseVideosNow($videos_id); $response = self::releaseVideosNow($videos_id);
if(!$response){
_error_log("Scheduler::run error on release video {$videos_id} ");
return false;
}else{
return $e->setExecuted(array('videos_id'=>$videos_id, 'response'=>$response));
}
} }
$callBackURL = $e->getCallbackURL(); $callBackURL = $e->getCallbackURL();
@ -128,11 +146,13 @@ class Scheduler extends PluginAbstract {
return false; return false;
} }
static function isActiveFromVideosId($videos_id){ static function isActiveFromVideosId($videos_id)
{
return Scheduler_commands::isActiveFromVideosId($videos_id);; return Scheduler_commands::isActiveFromVideosId($videos_id);;
} }
static public function addVideoToRelease($date_to_execute, $videos_id) { static public function addVideoToRelease($date_to_execute, $videos_id)
{
_error_log("Scheduler::addVideoToRelease [$date_to_execute] [$videos_id]"); _error_log("Scheduler::addVideoToRelease [$date_to_execute] [$videos_id]");
if (empty($date_to_execute)) { if (empty($date_to_execute)) {
_error_log("Scheduler::addVideoToRelease ERROR date_to_execute is empty"); _error_log("Scheduler::addVideoToRelease ERROR date_to_execute is empty");
@ -164,7 +184,8 @@ class Scheduler extends PluginAbstract {
return $e->save(); return $e->save();
} }
static public function add($date_to_execute, $callbackURL, $parameters = '', $type = '') { static public function add($date_to_execute, $callbackURL, $parameters = '', $type = '')
{
_error_log("Scheduler::add [$date_to_execute] [$callbackURL]"); _error_log("Scheduler::add [$date_to_execute] [$callbackURL]");
if (empty($date_to_execute)) { if (empty($date_to_execute)) {
_error_log("Scheduler::add ERROR date_to_execute is empty"); _error_log("Scheduler::add ERROR date_to_execute is empty");
@ -194,7 +215,8 @@ class Scheduler extends PluginAbstract {
return $e->save(); return $e->save();
} }
static public function addSendEmail($date_to_execute, $emailTo, $emailSubject, $emailEmailBody, $emailFrom = '', $emailFromName = '', $type = '') { static public function addSendEmail($date_to_execute, $emailTo, $emailSubject, $emailEmailBody, $emailFrom = '', $emailFromName = '', $type = '')
{
global $global; global $global;
$parameters = array( $parameters = array(
'emailSubject' => $emailSubject, 'emailSubject' => $emailSubject,
@ -214,7 +236,15 @@ class Scheduler extends PluginAbstract {
return $scheduler_commands_id; return $scheduler_commands_id;
} }
static public function getReminderOptions($destinationURL, $title, $date_start, $selectedEarlierOptions = array(), $date_end = '', $joinURL='', $description='',$earlierOptions = array( static public function getReminderOptions(
$destinationURL,
$title,
$date_start,
$selectedEarlierOptions = array(),
$date_end = '',
$joinURL = '',
$description = '',
$earlierOptions = array(
'10 minutes earlier' => 10, '10 minutes earlier' => 10,
'30 minutes earlier' => 30, '30 minutes earlier' => 30,
'1 hour earlier' => 60, '1 hour earlier' => 60,
@ -233,7 +263,8 @@ class Scheduler extends PluginAbstract {
'date_end' => $date_end, 'date_end' => $date_end,
'joinURL' => $joinURL, 'joinURL' => $joinURL,
'description' => $description, 'description' => $description,
'earlierOptions' => $earlierOptions); 'earlierOptions' => $earlierOptions
);
$filePath = "{$global['systemRootPath']}plugin/Scheduler/reminderOptions.php"; $filePath = "{$global['systemRootPath']}plugin/Scheduler/reminderOptions.php";
return getIncludeFileContent($filePath, $varsArray); return getIncludeFileContent($filePath, $varsArray);
} }
@ -253,7 +284,8 @@ class Scheduler extends PluginAbstract {
summary - string short summary of the event - usually used as the title. summary - string short summary of the event - usually used as the title.
url - string url to attach to the the event. Make sure to add the protocol (http:// or https://). url - string url to attach to the the event. Make sure to add the protocol (http:// or https://).
*/ */
static public function downloadICS($title, $date_start, $date_end = '', $reminderInMinutes='', $joinURL='', $description='') { static public function downloadICS($title, $date_start, $date_end = '', $reminderInMinutes = '', $joinURL = '', $description = '')
{
global $global, $config; global $global, $config;
//var_dump(date_default_timezone_get());exit; //var_dump(date_default_timezone_get());exit;
header('Content-Type: text/calendar; charset=utf-8'); header('Content-Type: text/calendar; charset=utf-8');
@ -310,19 +342,22 @@ class Scheduler extends PluginAbstract {
public static function getManagerVideosAddNew() { public static function getManagerVideosAddNew()
{
global $global; global $global;
$filename = $global['systemRootPath'] . 'plugin/Scheduler/getManagerVideosAddNew.js'; $filename = $global['systemRootPath'] . 'plugin/Scheduler/getManagerVideosAddNew.js';
return file_get_contents($filename); return file_get_contents($filename);
} }
public static function getManagerVideosEdit() { public static function getManagerVideosEdit()
{
global $global; global $global;
$filename = $global['systemRootPath'] . 'plugin/Scheduler/getManagerVideosEdit.js'; $filename = $global['systemRootPath'] . 'plugin/Scheduler/getManagerVideosEdit.js';
return file_get_contents($filename); return file_get_contents($filename);
} }
public static function getManagerVideosEditField($type='Advanced') { public static function getManagerVideosEditField($type = 'Advanced')
{
global $global; global $global;
if ($type == 'Advanced') { if ($type == 'Advanced') {
include $global['systemRootPath'] . 'plugin/Scheduler/managerVideosEdit.php'; include $global['systemRootPath'] . 'plugin/Scheduler/managerVideosEdit.php';
@ -330,11 +365,12 @@ class Scheduler extends PluginAbstract {
return ''; return '';
} }
public static function releaseVideosNow($videos_id) { public static function releaseVideosNow($videos_id)
{
if (empty($videos_id)) { if (empty($videos_id)) {
return false; return false;
} }
if (!Video::canEdit($videos_id) || isCommandLineInterface()) { if (!Video::canEdit($videos_id) && !isCommandLineInterface()) {
return false; return false;
} }
@ -350,15 +386,18 @@ class Scheduler extends PluginAbstract {
return true; return true;
} }
public static function saveVideosAddNew($post, $videos_id) { public static function saveVideosAddNew($post, $videos_id)
{
return self::addNewVideoToRelease($videos_id, @$post['releaseDate'], @$post['releaseDateTime']); return self::addNewVideoToRelease($videos_id, @$post['releaseDate'], @$post['releaseDateTime']);
} }
public function afterNewVideo($videos_id) { public function afterNewVideo($videos_id)
{
return self::addNewVideoToRelease($videos_id, @$_REQUEST['releaseDate'], @$_REQUEST['releaseDateTime']); return self::addNewVideoToRelease($videos_id, @$_REQUEST['releaseDate'], @$_REQUEST['releaseDateTime']);
} }
public static function addNewVideoToRelease($videos_id, $releaseDate, $releaseDateTime='') { public static function addNewVideoToRelease($videos_id, $releaseDate, $releaseDateTime = '')
{
if (!empty($releaseDate)) { if (!empty($releaseDate)) {
if ($releaseDate !== 'now') { if ($releaseDate !== 'now') {
if ($releaseDate == 'in-1-hour') { if ($releaseDate == 'in-1-hour') {
@ -383,7 +422,8 @@ class Scheduler extends PluginAbstract {
return false; return false;
} }
public static function setReleaseDateTime($videos_id, $releaseDateTime) { public static function setReleaseDateTime($videos_id, $releaseDateTime)
{
if (!Video::canEdit($videos_id)) { if (!Video::canEdit($videos_id)) {
return false; return false;
} }
@ -397,11 +437,48 @@ class Scheduler extends PluginAbstract {
return $video->save(); return $video->save();
} }
public static function getReleaseDateTime($videos_id) { public static function getReleaseDateTime($videos_id)
{
$video = new Video('', '', $videos_id); $video = new Video('', '', $videos_id);
$externalOptions = _json_decode($video->getExternalOptions()); $externalOptions = _json_decode($video->getExternalOptions());
return @$externalOptions->releaseDateTime; return @$externalOptions->releaseDateTime;
} }
public static function getLastVisitFile()
{
$lastVisitFile = getVideosDir() . 'cache/schedulerLastVisit.log';
return $lastVisitFile;
}
public static function setLastVisit()
{
$lastVisitFile = self::getLastVisitFile();
if(_file_put_contents($lastVisitFile, time())){
return $lastVisitFile;
}else{
return false;
}
}
public static function getLastVisit()
{
$lastVisitFile = self::getLastVisitFile();
if (!file_exists($lastVisitFile)) {
return 0;
}
return file_get_contents($lastVisitFile);
}
public static function isActive()
{
$lastVisitTime = self::getLastVisit();
if (empty($lastVisitTime)) {
return false;
}
$TwoMinutes = 120;
$result = $lastVisitTime + $TwoMinutes - time();
return $result > 0;
}
} }

View file

@ -0,0 +1,17 @@
<?php
if(!AVideoPlugin::isEnabledByName('Scheduler')){
return '';
}
if(Scheduler::isActive()){
?>
<span class="glowText">
Scheduler plugin cront tab found
</span>
<?php
}else{
?>
<span class="glowTextBlue">
Scheduler plugin cront tab NOT found
<?php
}
?>

View file

@ -33,10 +33,16 @@ foreach ($rows2 as $value) {
_log("getAllScheduledTORepeat run ". json_encode($value)); _log("getAllScheduledTORepeat run ". json_encode($value));
$id = Scheduler::run($value['id']); $id = Scheduler::run($value['id']);
if(empty($id)){ if(empty($id)){
_log("error [{$value['id']}] callbackURL={$value['callbackURL']}"); _log("error [{$value['id']}] callbackURL={$value['callbackURL']} ".json_encode($value));
} }
} }
if($lastVisitFile = Scheduler::setLastVisit()){
_error_log("Last visit set {$lastVisitFile}");
}else{
_error_log('ERROR: Last visit NOT set');
}
function _log($msg){ function _log($msg){
if(!isCommandLineInterface()){ if(!isCommandLineInterface()){

View file

@ -389,12 +389,6 @@ footer ul.list-inline li {
border-color: transparent !important; border-color: transparent !important;
} }
.no-outline:focus,
.no-outline:active,
.no-outline:hover {
/*color: #000;*/;
}
#showMore { #showMore {
padding: 20px; padding: 20px;
margin: 10px; margin: 10px;
@ -1165,6 +1159,10 @@ li.dropdown-submenu > ul > li > a {
animation: socketGlow 1s infinite alternate; animation: socketGlow 1s infinite alternate;
} }
.glowTextBlue {
animation: socketGlowBlue 1s infinite alternate;
}
.glowBox { .glowBox {
animation: glowBox 1s infinite alternate; animation: glowBox 1s infinite alternate;
} }