Skip to content

Commit 8418cc3

Browse files
committed
force jails to update every 2 weeks
1 parent cabf603 commit 8418cc3

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

server/lib/classes/cron.d/600-jailkit_maintenance.inc.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,6 @@ class cronjob_jailkit_maintenance extends cronjob {
3434
protected $_schedule = '*/5 * * * *';
3535
protected $_run_at_new = true;
3636

37-
//private $_tools = null;
38-
39-
/* this function is optional if it contains no custom code */
40-
public function onPrepare() {
41-
global $app;
42-
43-
parent::onPrepare();
44-
}
45-
46-
/* this function is optional if it contains no custom code */
47-
public function onBeforeRun() {
48-
global $app;
49-
50-
return parent::onBeforeRun();
51-
}
52-
5337
public function onRunJob() {
5438
global $app, $conf;
5539

@@ -66,6 +50,18 @@ public function onRunJob() {
6650
$options = array('allow_hardlink');
6751
}
6852

53+
// force all jails to update every 2 weeks
54+
if (! is_file('/usr/local/ispconfig/server/temp/jailkit_force_update.ts')) {
55+
if(!@is_dir('/usr/local/ispconfig/server/temp')) {
56+
$app->system->mkdirpath('/usr/local/ispconfig/server/temp');
57+
}
58+
$app->system->touch('/usr/local/ispconfig/server/temp/jailkit_force_update.ts');
59+
} elseif ( time() - filemtime('/usr/local/ispconfig/server/temp/jailkit_force_update.ts') > 60 * 60 * 24 * 14 ) {
60+
$update_hash = 'force_update'.time();
61+
$app->db->query("UPDATE web_domain SET last_jailkit_hash = ? WHERE type = 'vhost' AND server_id = ?", $update_hash, $conf['server_id']);
62+
$app->system->touch('/usr/local/ispconfig/server/temp/jailkit_force_update.ts');
63+
}
64+
6965
// limit the number of jails we update at one time according to time of day
7066
$num_jails_to_update = (date('H') < 6) ? 25 : 3;
7167

@@ -111,12 +107,12 @@ public function onRunJob() {
111107
sort($last_updated, SORT_STRING);
112108
$update_hash = hash('md5', implode(' ', $last_updated));
113109

114-
if (is_file( $rec['document_root']."/bin/bash" )) {
110+
if (substr($rec['last_jailkit_hash'], 0, strlen('force_update')) === 'force_update') {
111+
$options[] = 'force';
112+
} elseif (is_file( $rec['document_root']."/bin/bash" )) {
115113
# test that /bin/bash functions in the jail
116-
print "chroot --userspec ".$rec['system_user'].":".$rec['system_group']." ".$rec['document_root']." /bin/bash -c true 2>/dev/null\n";
117114
$app->system->exec_safe("chroot --userspec ?:? ? /bin/bash -c true 2>/dev/null", $rec['system_user'], $rec['system_group'], $rec['document_root']);
118115
if ($app->system->last_exec_retcode()) { # return 0 means success
119-
print "/bin/bash test failed, forcing update\n";
120116
$options[] = 'force';
121117
# bogus hash will not match, triggering an update
122118
$update_hash = 'force_update'.time();
@@ -147,10 +143,5 @@ public function onRunJob() {
147143
parent::onRunJob();
148144
}
149145

150-
/* this function is optional if it contains no custom code */
151-
public function onAfterRun() {
152-
parent::onAfterRun();
153-
}
154-
155146
}
156147

0 commit comments

Comments
 (0)