]> git.mxchange.org Git - friendica.git/blobdiff - bin/daemon.php
Merge pull request #5878 from nupplaphil/curl_response_refactoring
[friendica.git] / bin / daemon.php
index 65ae2a53b6596730e9f4b107e95c7dffdf001c04..f0f5826d928fb04c97e36e12f57020dd8cd88ec2 100755 (executable)
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
+use Friendica\Database\DBA;
+
+// Get options
+$shortopts = 'f';
+$longopts = ['foreground'];
+$options = getopt($shortopts, $longopts);
 
 // Ensure that daemon.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 = $_SERVER["PWD"] . "/" . $directory;
        }
-       $directory = realpath($directory."/..");
+       $directory = realpath($directory . "/..");
 
        chdir($directory);
 }
@@ -28,7 +34,7 @@ require_once "include/dba.php";
 
 $a = new App(dirname(__DIR__));
 
-if ($a->isInstallMode()) {
+if ($a->getMode()->isInstall()) {
        die("Friendica isn't properly installed yet.\n");
 }
 
@@ -54,7 +60,7 @@ if (in_array("status", $_SERVER["argv"])) {
        $mode = "status";
 }
 
-$foreground = in_array("--foreground", $_SERVER["argv"]);
+$foreground = array_key_exists('f', $options) || array_key_exists('foreground', $options);
 
 if (!isset($mode)) {
        die("Please use either 'start', 'stop' or 'status'.\n");
@@ -64,7 +70,11 @@ if (empty($_SERVER["argv"][0])) {
        die("Unexpected script behaviour. This message should never occur.\n");
 }
 
-$pid = @file_get_contents($pidfile);
+$pid = null;
+
+if (is_readable($pidfile)) {
+       $pid = intval(file_get_contents($pidfile));
+}
 
 if (empty($pid) && in_array($mode, ["stop", "status"])) {
        Config::set('system', 'worker_daemon_mode', false);
@@ -113,7 +123,7 @@ if (!$foreground) {
        // fclose(STDOUT); // file descriptors as we
        // fclose(STDERR); // are running as a daemon.
 
-       dba::disconnect();
+       DBA::disconnect();
 
        register_shutdown_function('shutdown');
 
@@ -154,7 +164,7 @@ while (true) {
        if ($do_cron) {
                // We force a reconnect of the database connection.
                // This is done to ensure that the connection don't get lost over time.
-               dba::reconnect();
+               DBA::reconnect();
 
                $last_cron = time();
        }