laravel / ideas

Issues board used for Laravel internals discussions.
939 stars 28 forks source link

isdown Command #1326

Open szepeviktor opened 6 years ago

szepeviktor commented 6 years ago

When Laravel is down it would be nice to figure out its current state.

Could you add an isdown command?

        $downFile = storage_path('framework/down');
        if (!file_exists($downFile)) {
            $this->info('Application is up.');
            return;
        }

        $data = json_decode(file_get_contents($downFile), true);

        $status = sprintf("Time: %s\nRetry: %d\nMessage: '%s'",
            date('c', $data['time']),
            $data['retry'] ?: 0,
            $data['message']
        );
        $this->line($status);

https://github.com/laravel/framework/issues/25721

michaeldyrynda commented 6 years ago

What's the use case for this?

You can visit the app in the browser and see pretty clearly that the app is down. If you're using a monitoring service, it should be able to detect the 503 being returned when the application is in maintenance mode.

szepeviktor commented 6 years ago

Thank you.

You can visit the app in the browser

I am a stay-at-the-terminal type.

And in script it is necessary to check for maintenance mode.

michaeldyrynda commented 6 years ago

You can check $this->app->isDownForMaintenance() in your commands.

szepeviktor commented 6 years ago

Thanks.

$ ./artisan isdown

   ErrorException  : Undefined property: App\Console\Commands\IsDownForMaintenance::$app

  at app/Console/Commands/IsDownForMaintenance.php:40
    36|      * @return mixed
    37|      */
    38|     public function handle()
    39|     {
  > 40|         if (!$this->app->isDownForMaintenance()) {
    41|             $this->info('Application is up.');
    42|             return;
    43|         }
    44|

  Exception trace:

  1   Raven_Breadcrumbs_ErrorHandler::handleError("Undefined property: App\Console\Commands\IsDownForMaintenance::$app", "app/Console/Commands/IsDownForMaintenance.php", [])
      app/Console/Commands/IsDownForMaintenance.php:40

  2   App\Console\Commands\IsDownForMaintenance::handle()
      /home/viktor/src/gallerytool/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29
AegirLeet commented 6 years ago

It's $this->laravel, not $this->app.

In a script, you could also simply check if storage/framework/down exists. If that file exists, the application is currently down.

szepeviktor commented 6 years ago

Thank you. That is OK.