]> git.mxchange.org Git - friendica.git/commitdiff
We now are having a "scripts" folder
authorMichael <heluecht@pirati.ca>
Sun, 19 Nov 2017 21:21:54 +0000 (21:21 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 19 Nov 2017 21:21:54 +0000 (21:21 +0000)
boot.php
include/dbstructure.php
include/poller.php [deleted file]
scripts/daemon.php [new file with mode: 0644]
scripts/dbstructure.php [new file with mode: 0644]
scripts/worker.php [new file with mode: 0644]
src/Core/Worker.php
util/daemon.php [deleted file]

index 402273bddf761187143a3b47260a1d56c815ab22..0364bd4e72660fe8d71b1c341eebcdba0362a7d1 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -1064,18 +1064,6 @@ function get_max_import_size()
        return ((x($a->config, 'max_import_size')) ? $a->config['max_import_size'] : 0 );
 }
 
-/**
- * @brief compatibilty wrapper for Worker::add function
- *
- * @param (integer|array) priority or parameter array, strings are deprecated and are ignored
- *
- * @return boolean "false" if proc_run couldn't be executed
- */
-function proc_run()
-{
-       $proc_args = func_get_args();
-       call_user_func_array('Friendica\Core\Worker::add', $proc_args);
-}
 
 function current_theme()
 {
index 1df82b1beda5b5e50e3648c77d1572187dc10f37..dde3dc6f18be5c66fa15efc1546c22794fb7dd35 100644 (file)
@@ -1757,73 +1757,3 @@ function db_definition() {
 
        return($database);
 }
-
-
-/*
- * run from command line
- */
-function dbstructure_run(&$argv, &$argc) {
-       global $a;
-
-       if (empty($a)) {
-               $a = new App(dirname(__DIR__));
-       }
-
-       @include ".htconfig.php";
-       require_once "include/dba.php";
-       dba::connect($db_host, $db_user, $db_pass, $db_data);
-       unset($db_host, $db_user, $db_pass, $db_data);
-
-       if ($argc == 2) {
-               switch ($argv[1]) {
-                       case "dryrun":
-                               update_structure(true, false);
-                               return;
-                       case "update":
-                               update_structure(true, true);
-
-                               $build = Config::get('system','build');
-                               if (!x($build)) {
-                                       Config::set('system', 'build', DB_UPDATE_VERSION);
-                                       $build = DB_UPDATE_VERSION;
-                               }
-
-                               $stored = intval($build);
-                               $current = intval(DB_UPDATE_VERSION);
-
-                               // run any left update_nnnn functions in update.php
-                               for ($x = $stored; $x < $current; $x ++) {
-                                       $r = run_update_function($x);
-                                       if (!$r) {
-                                               break;
-                                       }
-                               }
-
-                               Config::set('system','build',DB_UPDATE_VERSION);
-                               return;
-                       case "dumpsql":
-                               print_structure(db_definition());
-                               return;
-                       case "toinnodb":
-                               convert_to_innodb();
-                               return;
-               }
-       }
-
-
-       // print help
-       echo $argv[0]." <command>\n";
-       echo "\n";
-       echo "Commands:\n";
-       echo "dryrun            show database update schema queries without running them\n";
-       echo "update            update database schema\n";
-       echo "dumpsql           dump database schema\n";
-       echo "toinnodb  convert all tables from MyISAM to InnoDB\n";
-       return;
-
-}
-
-if (array_search(__FILE__,get_included_files())===0) {
-       dbstructure_run($_SERVER["argv"],$_SERVER["argc"]);
-       killme();
-}
diff --git a/include/poller.php b/include/poller.php
deleted file mode 100644 (file)
index 6fcf4c7..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-use Friendica\App;
-use Friendica\Core\Worker;
-use Friendica\Core\Config;
-
-// Ensure that poller.php is executed from the base path of the installation
-if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
-       $directory = dirname($_SERVER["argv"][0]);
-
-       if (substr($directory, 0, 1) != "/") {
-               $directory = $_SERVER["PWD"]."/".$directory;
-       }
-       $directory = realpath($directory."/..");
-
-       chdir($directory);
-}
-
-require_once "boot.php";
-require_once "include/dba.php";
-
-$a = new App(dirname(__DIR__));
-
-require_once ".htconfig.php";
-dba::connect($db_host, $db_user, $db_pass, $db_data);
-unset($db_host, $db_user, $db_pass, $db_data);
-
-Config::load();
-
-// Check the database structure and possibly fixes it
-check_db(true);
-
-// Quit when in maintenance
-if (Config::get('system', 'maintenance', true)) {
-       return;
-}
-
-$a->set_baseurl(Config::get('system', 'url'));
-
-load_hooks();
-
-$run_cron = (($_SERVER["argc"] <= 1) || ($_SERVER["argv"][1] != "no_cron"));
-Worker::processQueue($run_cron);
-
-Worker::unclaimProcess();
-
-$a->end_process();
-
-killme();
-
diff --git a/scripts/daemon.php b/scripts/daemon.php
new file mode 100644 (file)
index 0000000..4accef3
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+/**
+ * @file util/daemon.php
+ * @brief Run the poller from a daemon.
+ *
+ * This script was taken from http://php.net/manual/en/function.pcntl-fork.php
+ */
+function shutdown() {
+       posix_kill(posix_getpid(), SIGHUP);
+}
+
+if (in_array("start", $_SERVER["argv"])) {
+       $mode = "start";
+}
+
+if (in_array("stop", $_SERVER["argv"])) {
+       $mode = "stop";
+}
+
+if (in_array("status", $_SERVER["argv"])) {
+       $mode = "status";
+}
+
+if (!isset($mode)) {
+       die("Please use either 'start', 'stop' or 'status'.\n");
+}
+
+@include(".htconfig.php");
+
+if (!isset($pidfile)) {
+       die('Please specify a pid file in the variable $pidfile in the .htconfig.php. For example:'."\n".
+               '$pidfile = "/path/to/daemon.pid";'."\n");
+}
+
+if (in_array($mode, array("stop", "status"))) {
+       $pid = @file_get_contents($pidfile);
+
+       if (!$pid) {
+               die("Pidfile wasn't found. Is the daemon running?\n");
+       }
+}
+
+if ($mode == "status") {
+       if (posix_kill($pid, 0)) {
+               die("Daemon process $pid is running.\n");
+       }
+
+       unlink($pidfile);
+
+       die("Daemon process $pid isn't running.\n");
+}
+
+if ($mode == "stop") {
+       posix_kill($pid, SIGTERM);
+
+       unlink($pidfile);
+
+       die("Worker daemon process $pid was killed.\n");
+}
+
+echo "Starting worker daemon.\n";
+
+if (isset($a->config['php_path'])) {
+       $php = $a->config['php_path'];
+} else {
+       $php = "php";
+}
+
+// Switch over to daemon mode.
+if ($pid = pcntl_fork())
+       return;     // Parent
+
+fclose(STDIN);  // Close all of the standard
+fclose(STDOUT); // file descriptors as we
+fclose(STDERR); // are running as a daemon.
+
+register_shutdown_function('shutdown');
+
+if (posix_setsid() < 0)
+       return;
+
+if ($pid = pcntl_fork())
+       return;     // Parent
+
+$pid = getmypid();
+file_put_contents($pidfile, $pid);
+
+// Now running as a daemon.
+while (true) {
+       // Just to be sure that this script really runs endlessly
+       set_time_limit(0);
+
+       // Call the poller
+       $cmdline = $php.' include/poller.php';
+
+       exec($cmdline);
+
+       // Now sleep for 5 minutes
+       sleep(300);
+}
diff --git a/scripts/dbstructure.php b/scripts/dbstructure.php
new file mode 100644 (file)
index 0000000..cf14c92
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+/**
+ * @file scripts/dbstructure.php
+ * @brief Does database updates from the command line
+ */
+
+require_once 'include/dbstructure.php';
+
+use Friendica\App;
+
+$a = new App(dirname(__DIR__));
+
+@include ".htconfig.php";
+require_once "include/dba.php";
+dba::connect($db_host, $db_user, $db_pass, $db_data);
+unset($db_host, $db_user, $db_pass, $db_data);
+
+if ($_SERVER["argc"] == 2) {
+       switch ($_SERVER["argv"][1]) {
+               case "dryrun":
+                       update_structure(true, false);
+                       return;
+               case "update":
+                       update_structure(true, true);
+
+                       $build = Config::get('system','build');
+                       if (!x($build)) {
+                               Config::set('system', 'build', DB_UPDATE_VERSION);
+                               $build = DB_UPDATE_VERSION;
+                       }
+
+                       $stored = intval($build);
+                       $current = intval(DB_UPDATE_VERSION);
+
+                       // run any left update_nnnn functions in update.php
+                       for ($x = $stored; $x < $current; $x ++) {
+                               $r = run_update_function($x);
+                               if (!$r) {
+                                       break;
+                               }
+                       }
+
+                       Config::set('system','build',DB_UPDATE_VERSION);
+                       return;
+               case "dumpsql":
+                       print_structure(db_definition());
+                       return;
+               case "toinnodb":
+                       convert_to_innodb();
+                       return;
+       }
+}
+
+// print help
+echo $_SERVER["argv"][0]." <command>\n";
+echo "\n";
+echo "Commands:\n";
+echo "dryrun           show database update schema queries without running them\n";
+echo "update           update database schema\n";
+echo "dumpsql          dump database schema\n";
+echo "toinnodb convert all tables from MyISAM to InnoDB\n";
+killme();
+
diff --git a/scripts/worker.php b/scripts/worker.php
new file mode 100644 (file)
index 0000000..6fcf4c7
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+use Friendica\App;
+use Friendica\Core\Worker;
+use Friendica\Core\Config;
+
+// Ensure that poller.php is executed from the base path of the installation
+if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
+       $directory = dirname($_SERVER["argv"][0]);
+
+       if (substr($directory, 0, 1) != "/") {
+               $directory = $_SERVER["PWD"]."/".$directory;
+       }
+       $directory = realpath($directory."/..");
+
+       chdir($directory);
+}
+
+require_once "boot.php";
+require_once "include/dba.php";
+
+$a = new App(dirname(__DIR__));
+
+require_once ".htconfig.php";
+dba::connect($db_host, $db_user, $db_pass, $db_data);
+unset($db_host, $db_user, $db_pass, $db_data);
+
+Config::load();
+
+// Check the database structure and possibly fixes it
+check_db(true);
+
+// Quit when in maintenance
+if (Config::get('system', 'maintenance', true)) {
+       return;
+}
+
+$a->set_baseurl(Config::get('system', 'url'));
+
+load_hooks();
+
+$run_cron = (($_SERVER["argc"] <= 1) || ($_SERVER["argv"][1] != "no_cron"));
+Worker::processQueue($run_cron);
+
+Worker::unclaimProcess();
+
+$a->end_process();
+
+killme();
+
index 9e69d4173a807db96131eebe276465b5a9961ddd..e949ff2da81d0c1bb1415a6d808a8f0f0e96086b 100644 (file)
@@ -912,7 +912,7 @@ class Worker {
        }
 
        public static function spawnWorker() {
-               $args = array("include/poller.php", "no_cron");
+               $args = array("scripts/worker.php", "no_cron");
                get_app()->proc_run($args);
        }
 
diff --git a/util/daemon.php b/util/daemon.php
deleted file mode 100644 (file)
index 4accef3..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-/**
- * @file util/daemon.php
- * @brief Run the poller from a daemon.
- *
- * This script was taken from http://php.net/manual/en/function.pcntl-fork.php
- */
-function shutdown() {
-       posix_kill(posix_getpid(), SIGHUP);
-}
-
-if (in_array("start", $_SERVER["argv"])) {
-       $mode = "start";
-}
-
-if (in_array("stop", $_SERVER["argv"])) {
-       $mode = "stop";
-}
-
-if (in_array("status", $_SERVER["argv"])) {
-       $mode = "status";
-}
-
-if (!isset($mode)) {
-       die("Please use either 'start', 'stop' or 'status'.\n");
-}
-
-@include(".htconfig.php");
-
-if (!isset($pidfile)) {
-       die('Please specify a pid file in the variable $pidfile in the .htconfig.php. For example:'."\n".
-               '$pidfile = "/path/to/daemon.pid";'."\n");
-}
-
-if (in_array($mode, array("stop", "status"))) {
-       $pid = @file_get_contents($pidfile);
-
-       if (!$pid) {
-               die("Pidfile wasn't found. Is the daemon running?\n");
-       }
-}
-
-if ($mode == "status") {
-       if (posix_kill($pid, 0)) {
-               die("Daemon process $pid is running.\n");
-       }
-
-       unlink($pidfile);
-
-       die("Daemon process $pid isn't running.\n");
-}
-
-if ($mode == "stop") {
-       posix_kill($pid, SIGTERM);
-
-       unlink($pidfile);
-
-       die("Worker daemon process $pid was killed.\n");
-}
-
-echo "Starting worker daemon.\n";
-
-if (isset($a->config['php_path'])) {
-       $php = $a->config['php_path'];
-} else {
-       $php = "php";
-}
-
-// Switch over to daemon mode.
-if ($pid = pcntl_fork())
-       return;     // Parent
-
-fclose(STDIN);  // Close all of the standard
-fclose(STDOUT); // file descriptors as we
-fclose(STDERR); // are running as a daemon.
-
-register_shutdown_function('shutdown');
-
-if (posix_setsid() < 0)
-       return;
-
-if ($pid = pcntl_fork())
-       return;     // Parent
-
-$pid = getmypid();
-file_put_contents($pidfile, $pid);
-
-// Now running as a daemon.
-while (true) {
-       // Just to be sure that this script really runs endlessly
-       set_time_limit(0);
-
-       // Call the poller
-       $cmdline = $php.' include/poller.php';
-
-       exec($cmdline);
-
-       // Now sleep for 5 minutes
-       sleep(300);
-}