Skip to content

Commit 3ed2832

Browse files
committed
some work for cron update etc
Signed-off-by: DaRK AnGeL <[email protected]>
1 parent 5b6b484 commit 3ed2832

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if ($var['shareCacheEnabled']!='yes') {
88
} elseif ($var['shareUser']=='-') {
99
echo "<p class='notice'>User shares not enabled!</p>";
1010
}
11+
$vars = @parse_ini_file("/var/local/emhttp/var.ini");
1112
$plugin = 'ca.mover.tuning';
1213
$config_file = '/boot/config/plugins/' . $plugin . '/' . $plugin . '.cfg';
1314
$config_default_file = '/usr/local/emhttp/plugins/' . $plugin . '/default.cfg';
@@ -49,9 +50,10 @@ $.fn.toggleAttr = function(attr) {
4950

5051
function updateCron() {
5152
var cron = $("#cronSchedule").val();
53+
var tune_cron = $("#tune_cronSchedule").val();
5254
var cronEnabled = $("#forceCron").val();
5355
var ismoverDisabled = $("#moverDisabled").val();
54-
$.post("/plugins/ca.mover.tuning/updateCron.php",{cronEnabled:cronEnabled,cron:cron,ismoverDisabled:ismoverDisabled});
56+
$.post("/plugins/ca.mover.tuning/updateCron.php",{cronEnabled:cronEnabled,cron:cron,tune_cron:tune_cron,ismoverDisabled:ismoverDisabled});
5557
}
5658

5759
function moveNow() {
@@ -147,6 +149,16 @@ _(Disable Mover running on a schedule)_:
147149
:end
148150

149151
<div markdown="1" id="moverTuningSettings">
152+
<?php if (version_compare($vars['version'], '7.2.1', '>=')): ?>
153+
_(Mover Tuning schedule)_:
154+
: <input type='text' id='tune_cronSchedule' name='cron' size='1' class='tune_mycron' placeholder='0 */4 * * *' value='<?=htmlspecialchars($cfg['moverTuneCron'])?>'>
155+
156+
<blockquote class="inline_help">
157+
<p>Runs the <strong><code>age_mover</code></strong> schedule from the Mover Tuning plugin using your custom cron entry (includes all plugin filters).</p>
158+
<p> Cron Schedule entry example <strong>0 */4 * * *</strong>.&nbsp; To run at <em>every</em><strong> 4 hours</strong>.&nbsp; <a href="https://crontab.guru/" target="_blank" rel="noopener noreferrer"><i class="fa fa-clock-o"></i> What Is Cron</a></p>
159+
</blockquote>
160+
<?php endif; ?>
161+
150162
_(Test Mode (dry run))_:
151163
: <select name='testmode' size='1' id='testmode' onchange="toggleTestModeWarning(this.value)">
152164
<?=mk_option($cfg['testmode'],"no",_('No'))?>

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/default.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ sparsnessv="1"
4848
filetypesv=""
4949
omoverthresh=""
5050
cron=""
51+
moverTuneCron=""
5152
forceParity="no"

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
require_once("/usr/local/emhttp/plugins/dynamix/include/Wrappers.php");
44

55
$cfg = parse_plugin_cfg("ca.mover.tuning");
6+
$vars = @parse_ini_file("/var/local/emhttp/var.ini");
67

78
// Get config value of forced cron
89
$cfg_cronEnabled = $cfg['force'];
910
// Get cron time of forced cron (normalized)
1011
$cfg_cron = trim($cfg['cron'] ?? '');
1112
// Get config value of mover disabled
1213
$cfg_moverDisabled = $cfg['moverDisabled'];
14+
// Get Mover Tuning cron time (normalized)
15+
$cfg_moverTuneCron = trim($cfg['moverTuneCron'] ?? $vars['shareMoverSchedule'] ?? '');
1316

1417
function logger($string)
1518
{
@@ -20,9 +23,26 @@ function logger($string)
2023
}
2124
}
2225

26+
function make_tune_cron()
27+
{
28+
global $vars;
29+
if (!empty($var['shareMoverSchedule'])) {
30+
// Disable Unraid mover
31+
$vars['shareMoverSchedule'] = "";
32+
}
33+
34+
$cronTuneFile = "# Generated schedule for Mover Tuning move\n" . trim($_POST['tune_cron']) . " /usr/local/emhttp/plugins/ca.mover.tuning/age_mover start |& logger -t move\n\n";
35+
file_put_contents("/boot/config/plugins/ca.mover.tuning/mover.tune.cron", $cronTuneFile);
36+
}
37+
2338
function make_cron()
2439
{
25-
$cronFile = "# Generated schedule for forced move\n" . trim($_POST['cron']) . " /usr/local/sbin/mover.old start |& logger -t move\n\n";
40+
global $vars;
41+
if (version_compare($vars['version'], '7.2.1', '<')) {
42+
$cronFile = "# Generated schedule for forced move\n" . trim($_POST['cron']) . " /usr/local/sbin/mover.old start |& logger -t move\n\n";
43+
} else {
44+
$cronFile = "# Generated schedule for forced move\n" . trim($_POST['cron']) . " /usr/local/sbin/mover start |& logger -t move\n\n";
45+
}
2646
file_put_contents("/boot/config/plugins/ca.mover.tuning/mover.cron", $cronFile);
2747
}
2848

@@ -63,5 +83,17 @@ function make_cron()
6383
}
6484
}
6585

86+
// Handle Mover Tuning custom cron schedule
87+
if ($cfg_moverTuneCron != $_POST['tune_cron']) {
88+
89+
if (trim($_POST['tune_cron']) != "") {
90+
make_tune_cron();
91+
logger("Mover Tuning cron schedule updated successfully.");
92+
} else {
93+
@unlink("/boot/config/plugins/ca.mover.tuning/mover.tune.cron");
94+
logger("Mover Tuning cron schedule removed.");
95+
}
96+
}
97+
6698
exec("update_cron");
6799
?>

0 commit comments

Comments
 (0)