xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
Commit 03e1ba61bdcac0514977b79c0b38449db29aa7a5

Now, any script can update the structure and apply the fixes
Author: Catalin(ux) M. BOIE
Author date (UTC): 2016-10-03 16:05
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2016-10-03 16:05
Parent(s): 5dee24337e21e740cba1080e9bfc376b2e8f2036
Signing key:
Tree: 521708b2b9e5ccf75d48ad0e24126135fb71f7c6
File Lines added Lines deleted
inc/cache.inc.php 0 1
inc/struct.inc.php 40 0
root/index.php 2 21
scripts/builder.php 1 8
scripts/cron.php 1 22
scripts/events.php 1 4
scripts/remote.php 1 4
File inc/cache.inc.php changed (mode: 100644) (index 33c3944..04f1310)
3 3 // memcache alike daemon // memcache alike daemon
4 4 // //
5 5 require_once($INC . "/util.inc.php"); require_once($INC . "/util.inc.php");
6 require_once($INC . "/sql.inc.php");
7 6 require_once($INC . "/prof.inc.php"); require_once($INC . "/prof.inc.php");
8 7
9 8 // Client side can disable the cache for various reasons (unit testing etc.) // Client side can disable the cache for various reasons (unit testing etc.)
File inc/struct.inc.php changed (mode: 100644) (index 78a09f1..bf940b6)
... ... function rg_sql_struct_slaves_update($db)
878 878 return $ret; return $ret;
879 879 } }
880 880
881 /*
882 * Helper that will setup the structure and the fixes if needed
883 */
884 function rg_struct_ok($db)
885 {
886 $ret = FALSE;
887 while (1) {
888 $restart_cache = FALSE;
889
890 if (rg_sql_struct_update_needed($db) == 1) {
891 $r = rg_sql_struct_update($db, 0);
892 if ($r !== TRUE)
893 break;
894 $restart_cache = TRUE;
895 }
896
897 if (rg_fixes_needed($db) == 1) {
898 $r = rg_fixes_update($db);
899 if ($r !== TRUE)
900 break;
901 $restart_cache = TRUE;
902 }
903
904 if ($restart_cache)
905 rg_cache_restart();
906
907 $install_id = rg_state_get($db, 'install_id');
908 if ($install_id === FALSE)
909 break;
910 if (empty($install_id))
911 rg_state_set($db, 'install_id',
912 sha512(microtime(TRUE)));
913
914 $ret = TRUE;
915 break;
916 }
917
918 return $ret;
919 }
920
881 921 ?> ?>
File root/index.php changed (mode: 100644) (index 76863ed..75628b8)
... ... rg_log_ml('_SERVER: ' . print_r($_SERVER, TRUE));
98 98 $rg['ct'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : ''; $rg['ct'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '';
99 99
100 100
101 $good = 0;
102 $tries = 10;
103 while ($tries > 0) {
104 $r = rg_sql_struct_update_needed($db);
105 if ($r === 0) {
106 $r = rg_fixes_needed($db);
107 if ($r === 0) {
108 $good = 1;
109 break;
110 } else {
111 rg_log("Fixes needed (r=$r)");
112 }
113 } else {
114 rg_log("db struct update needed (r=$r)");
115 }
116
117 rg_log("Schema/fixes is not up-to-date! Sleep 1 second...");
118 $tries--;
119 sleep(1);
120 }
121 if ($good == 0) {
101 $r = rg_struct_ok($db);
102 if ($r === FALSE) {
122 103 echo "Internal error; please try again later."; echo "Internal error; please try again later.";
123 104 exit(0); exit(0);
124 105 } }
File scripts/builder.php changed (mode: 100644) (index 801f27a..7714591)
... ... if ($db === FALSE) {
325 325 exit(1); exit(1);
326 326 } }
327 327
328 if (rg_sql_struct_update_needed($db) !== 0) {
329 rg_log('Update needed. Exit.');
328 if (rg_struct_ok($db) === FALSE)
330 329 exit(0); exit(0);
331 }
332
333 if (rg_fixes_needed($db) !== 0) {
334 rg_log('Fixes needed. Exit.');
335 exit(0);
336 }
337 330
338 331 // Prepare socket // Prepare socket
339 332 $socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
File scripts/cron.php changed (mode: 100644) (index 93281e6..07df3f2)
... ... if ($db === FALSE) {
42 42 exit(1); exit(1);
43 43 } }
44 44
45 $restart_cache = FALSE;
46 if (rg_sql_struct_update_needed($db) == 1) {
47 $r = rg_sql_struct_update($db, 0);
48 if ($r !== TRUE)
49 exit(1);
50 $restart_cache = TRUE;
51 }
52
53 if (rg_fixes_needed($db) == 1) {
54 $r = rg_fixes_update($db);
55 if ($r !== TRUE)
56 exit(1);
57 $restart_cache = TRUE;
58 }
59
60 if ($restart_cache)
61 rg_cache_restart();
62
63 $install_id = rg_state_get($db, "install_id");
64 if ($install_id === FALSE)
45 if (rg_struct_ok($db) === FALSE)
65 46 exit(1); exit(1);
66 if (empty($install_id))
67 rg_state_set($db, "install_id", sha512(microtime(TRUE)));
68 47
69 48 $first_install = rg_state_get($db, 'first_install'); $first_install = rg_state_get($db, 'first_install');
70 49 if ($first_install === FALSE) if ($first_install === FALSE)
File scripts/events.php changed (mode: 100644) (index 939f33b..00241a4)
... ... if ($db === FALSE) {
68 68 exit(1); exit(1);
69 69 } }
70 70
71 if (rg_sql_struct_update_needed($db) !== 0)
72 exit(0);
73
74 if (rg_fixes_needed($db) !== 0)
71 if (rg_struct_ok($db) === FALSE)
75 72 exit(0); exit(0);
76 73
77 74 // Remove the socket, else we will get error // Remove the socket, else we will get error
File scripts/remote.php changed (mode: 100644) (index 5ac629c..1d64022)
... ... $db = rg_sql_open($rg_sql);
66 66 if ($db === FALSE) if ($db === FALSE)
67 67 fatal("Internal error (db)!"); fatal("Internal error (db)!");
68 68
69 if (rg_sql_struct_update_needed($db) !== 0)
70 fatal("We are in a short maintenance window. Try again later.");
71
72 if (rg_fixes_needed($db) !== 0)
69 if (rg_struct_ok($db) === FALSE)
73 70 fatal("We are in a short maintenance window. Try again later."); fatal("We are in a short maintenance window. Try again later.");
74 71
75 72 if (isset($_SERVER['SSH_CONNECTION'])) { if (isset($_SERVER['SSH_CONNECTION'])) {
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://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master