]> git.mxchange.org Git - friendica.git/blobdiff - bin/daemon.php
Merge pull request #5838 from tobiasd/20181006-lng
[friendica.git] / bin / daemon.php
index 475bafc09de0f03c8c5ae12e4b821ee4f53644e5..e2bad90df59775e74ad4cd96164a84d6df41d13c 100755 (executable)
@@ -12,14 +12,19 @@ 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);
 }
@@ -29,7 +34,7 @@ require_once "include/dba.php";
 
 $a = new App(dirname(__DIR__));
 
-if ($a->isInstallMode()) {
+if (App\Mode::isInstall()) {
        die("Friendica isn't properly installed yet.\n");
 }
 
@@ -55,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");
@@ -65,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);