/scripts/cron.php (07df3f2d16d5a6c7ed13c1f91041d0af958de83b) (5371 bytes) (mode 100644) (type blob)
<?php
// This is called by cron
error_reporting(E_ALL);
ini_set("track_errors", "On");
set_time_limit(0);
require_once("/etc/rocketgit/config.php");
$INC = dirname(__FILE__) . "/../inc";
require_once($INC . "/init.inc.php");
require_once($INC . "/log.inc.php");
require_once($INC . "/sql.inc.php");
require_once($INC . "/struct.inc.php");
require_once($INC . "/repo.inc.php");
require_once($INC . "/keys.inc.php");
require_once($INC . "/fixes.inc.php");
require_once($INC . "/mr.inc.php");
require_once($INC . "/admin.inc.php");
require_once($INC . "/ver.php");
$now = time();
rg_log_set_file($rg_log_dir . "/cron.log");
rg_log_set_sid("000000"); // to spread the logs
if (rg_load() > 5)
exit(0);
// locking
rg_lock_or_exit("cron.lock");
rg_log("Start (ver=$rocketgit_version)...");
if (gmdate("Hi") == "0305")
rg_clean_logs('/var/log/rocketgit');
rg_sql_app("rg-cron");
$db = rg_sql_open($rg_sql);
if ($db === FALSE) {
rg_log("Cannot connect to database (" . rg_sql_error() . ")!");
// TODO: inform admin - already by e-mail?
exit(1);
}
if (rg_struct_ok($db) === FALSE)
exit(1);
$first_install = rg_state_get($db, 'first_install');
if ($first_install === FALSE)
exit(1);
if (empty($first_install)) {
rg_log("Admin did not created the user, so no need to run this code.");
exit(0);
}
if (gmdate("Hi") == "0105") {
while (1) {
rg_log("Compute repository sizes if dirty...");
// delete 'dirty' files
$sql = "SELECT uid, repo_id, master, disk_used_mb FROM repos";
$res = rg_sql_query($db, $sql);
if ($res === FALSE) {
// TODO: rg_internal_error? it must notify me in case of problems
rg_log("Cannot run query (" . rg_sql_error() . ")!");
break;
}
while (($row = rg_sql_fetch_array($res))) {
rg_log("Processing repo " . $row['repo_id'] . "...");
$repo_path = rg_repo_path_by_id($row['uid'], $row['repo_id']);
$all_files = $row['master'] == 0 ? TRUE : FALSE;
$disk_used = rg_repo_size($repo_path, $all_files);
if ($disk_used === FALSE) {
rg_log("Cannot compute the repo size: " . rg_repo_error());
continue;
}
$disk_used_mb = sprintf("%u", $disk_used / 1024 / 1024);
if ($disk_used_mb != $row['disk_used_mb']) {
$sql = "UPDATE repos SET disk_used_mb = $disk_used_mb"
. " WHERE repo_id = " . $row['repo_id'];
$res2 = rg_sql_query($db, $sql);
if ($res2 === FALSE) {
rg_log("Cannot run query!");
break;
}
rg_sql_free_result($res2);
}
}
rg_sql_free_result($res);
break;
}
while (1) {
rg_log("Compute repository sizes per user...");
$sql = "SELECT SUM(disk_used_mb) AS disk_used_mb, uid"
. " FROM repos"
. " GROUP BY uid";
$res = rg_sql_query($db, $sql);
if ($res === FALSE) {
rg_log("Cannot run query (" . rg_sql_error() . ")!");
break;
}
while (($row = rg_sql_fetch_array($res))) {
$sql = "UPDATE users"
. " SET disk_used_mb = " . $row['disk_used_mb']
. " WHERE uid = " . $row['uid']
. " AND disk_used_mb != " . $row['disk_used_mb'];
$res2 = rg_sql_query($db, $sql);
if ($res2 !== FALSE)
rg_sql_free_result($res2);
}
rg_sql_free_result($res);
break;
}
}
if (gmdate("Hi") == "0300") {
rg_log_enter("Clean old forget_pass entries...");
$sql = "DELETE FROM forgot_pass WHERE expire < $now";
$res = rg_sql_query($db, $sql);
if ($res !== FALSE)
rg_sql_free_result($res);
rg_log_exit();
}
if (gmdate("i") == "30") {
rg_log_enter("Clean old tokens...");
$sql = "DELETE FROM tokens WHERE expire < $now";
$res = rg_sql_query($db, $sql);
if ($res !== FALSE)
rg_sql_free_result($res);
rg_log_exit();
}
if (gmdate("i") == "01") {
rg_log_enter("Clean old sess entries...");
$sql = "DELETE FROM sess WHERE expire < $now";
$res = rg_sql_query($db, $sql);
if ($res !== FALSE)
rg_sql_free_result($res);
rg_log_exit();
}
if (gmdate("Hi") == "0605") {
rg_log_enter("Clean old login_tokens_ip entries...");
$sql = "DELETE FROM login_tokens_ip WHERE expire < $now";
$res = rg_sql_query($db, $sql);
if ($res !== FALSE)
rg_sql_free_result($res);
rg_log_exit();
}
if (gmdate("dHi") == "010610") {
rg_log_enter("Clean old empty slave tables...");
$ts = time() - 3 * 31 * 24 * 3600;
$limit = gmdate('Y_m', $ts);
rg_log('limit=' . $limit);
foreach ($rg_sql_struct_slaves as $table) {
rg_log('Slave: ' . $table);
$sql = 'SELECT relname FROM pg_class'
. ' WHERE relname LIKE \'' . $table . '_%\''
. ' AND relkind = \'r\''
. ' AND relname < \'' . $table . '_' . $limit . '\''
. ' ORDER BY relname';
$res = rg_sql_query($db, $sql);
if ($res === FALSE) {
rg_log('Cannot load slave tables: ' . rg_sql_error());
break;
}
while (($row = rg_sql_fetch_array($res))) {
$sql = 'SELECT 1 FROM ' . $row['relname'] . ' LIMIT 1';
$res2 = rg_sql_query($db, $sql);
if ($res2 === FALSE) {
rg_log('Cannot select from table ['
. $row['relname'] . ']: '
. rg_sql_error());
break;
}
$rows = rg_sql_num_rows($res2);
rg_sql_free_result($res2);
if ($rows == 1)
continue;
$sql = 'DROP TABLE ' . $row['relname'];
$res2 = rg_sql_query($db, $sql);
rg_sql_free_result($res2);
}
rg_sql_free_result($res);
}
rg_log_exit();
}
rg_log_cron();
rg_sql_struct_slaves_update($db);
if (gmdate("Hi") == "0100")
rg_admin_report1($db, $rg);
// TODO: move it as an event after the push
rg_mr_queue_process($db);
rg_log("Done!");
?>
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
9 |
f3c7a7c5da68804a1bdf391127ba34aed33c3cca |
.exclude |
100644 |
blob |
102 |
eaeb7d777062c60a55cdd4b5734902cdf6e1790c |
.gitignore |
100644 |
blob |
289 |
fabbff669e768c05d6cfab4d9aeb651bf623e174 |
AUTHORS |
100644 |
blob |
1132 |
dd65951315f3de6d52d52a82fca59889d1d95187 |
Certs.txt |
100644 |
blob |
1339 |
6ef73b238cddfb5bd83fe344a186e48f12e9da2c |
Compare.txt |
100644 |
blob |
549 |
41c3bdbba8ec2523fe24b84bdd46777fc13e8345 |
History.txt |
100644 |
blob |
34520 |
dba13ed2ddf783ee8118c6a581dbf75305f816a3 |
LICENSE |
100644 |
blob |
2695 |
994656805a9db0ea31cf9be1e5776182efbefecc |
Makefile.in |
100644 |
blob |
4788 |
eb8fa578df718b058ebbde968998718c669984cd |
README |
100644 |
blob |
100510 |
90d67c74d02ceaa47fad1166b5299d98a333ee08 |
TODO |
100644 |
blob |
1294 |
f22911eb777f0695fcf81ad686eac133eb11fcc4 |
TODO-plans |
100644 |
blob |
203 |
a2863c67c3da44126b61a15a6f09738c25e0fbe0 |
TODO.perf |
100644 |
blob |
373 |
ca2fd2e49069f5d13d557928e0bf53135782530f |
TODO.vm |
040000 |
tree |
- |
21928e906ad2907a55c2e81c2a8b0502b586b8a0 |
artwork |
100755 |
blob |
30 |
92c4bc48245c00408cd7e1fd89bc1a03058f4ce4 |
configure |
040000 |
tree |
- |
788c57f7b8b4a17ab4e6903b044addae9617da09 |
debian |
040000 |
tree |
- |
681465a8d96259004db092e8aab5111ad18900f1 |
docker |
040000 |
tree |
- |
f67d3605efbd6422a8acdd953578991139266391 |
docs |
100755 |
blob |
16711 |
924262b2f8dbf3bbe02358e7f404175732e970d1 |
duilder |
100644 |
blob |
536 |
0c5848fb0f59bf8aa904bb2c024c7ecc53b047fa |
duilder.conf |
040000 |
tree |
- |
b0cc8cc0386eddf4373339a7860e46e8f74e0202 |
hooks |
040000 |
tree |
- |
3d0ce82f618b8a7ea674b0bbbb375da6f45bd1fd |
inc |
100644 |
blob |
3881 |
074e596bfc98db0f5ea8368ba9839659629bb814 |
rocketgit.spec.in |
040000 |
tree |
- |
1f24175a898046ed93afdf11e6379ab0baf61843 |
root |
040000 |
tree |
- |
6c1ba1c908f4fcc7eed4edf31292b5299f442072 |
samples |
040000 |
tree |
- |
a400a14155cebfc40cf6323af694b5135ec57b6e |
scripts |
040000 |
tree |
- |
025ca18e527ac6671c34adb53cd74cd242ce68a2 |
selinux |
100755 |
blob |
256 |
462ccd108c431f54e380cdac2329129875a318b5 |
spell_check.sh |
040000 |
tree |
- |
cb54e074b3ca35943edfcda9dd9cfcd281bcd9e7 |
techdocs |
040000 |
tree |
- |
5e4e7da913966f00733b01a18e7e4972a44e91b1 |
tests |
040000 |
tree |
- |
d39824f9d9ba0f8b2f00f4a101f5cd5aeebc2f83 |
tools |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/rocketgit
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/rocketgit
Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/rocketgit
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main