Skip to content

Re-add maintenance mode. #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function environment()
*/
public function isDownForMaintenance()
{
return false;
return file_exists($this->storagePath().DIRECTORY_SEPARATOR.'framework'.DIRECTORY_SEPARATOR.'down');
}

/**
Expand Down
33 changes: 33 additions & 0 deletions src/Console/Commands/DownCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php namespace Laravel\Lumen\Console\Commands;

use Illuminate\Console\Command;

class DownCommand extends Command {

/**
* The console command name.
*
* @var string
*/
protected $name = 'down';

/**
* The console command description.
*
* @var string
*/
protected $description = "Put the application into maintenance mode";

/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
touch($this->laravel->storagePath().'/framework/down');

$this->comment('Application is now in maintenance mode.');
}

}
33 changes: 33 additions & 0 deletions src/Console/Commands/UpCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php namespace Laravel\Lumen\Console\Commands;

use Illuminate\Console\Command;

class UpCommand extends Command {

/**
* The console command name.
*
* @var string
*/
protected $name = 'up';

/**
* The console command description.
*
* @var string
*/
protected $description = "Bring the application out of maintenance mode";

/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
@unlink($this->laravel->storagePath().'/framework/down');

$this->info('Application is now live.');
}

}
107 changes: 107 additions & 0 deletions src/Http/Middleware/CheckForMaintenanceMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php namespace Laravel\Lumen\Http\Middleware;

use Closure;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory as View;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class CheckForMaintenanceMode
{
/**
* The application instance.
*
* @var \Illuminate\Contracts\Foundation\Application
*/
protected $app;

/**
* The view factory instance.
*
* @var \Illuminate\Contracts\View\Factory
*/
protected $view;

/**
* Create a new check for maintenance mode instance.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Contracts\View\Factory $view
*
* @return void
*/
public function __construct(Application $app, View $view)
{
$this->app = $app;
$this->view = $view;
}

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if ($this->app->isDownForMaintenance()) {
return new Response($this->maintenance(), 503);
}

return $next($request);
}

public function maintenance()
{
return "<html>
<head>
<title>Maintenance.</title>

<link href='//fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'>

<style>
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
color: #B0BEC5;
display: table;
font-weight: 100;
font-family: 'Lato';
}

.container {
text-align: center;
display: table-cell;
vertical-align: middle;
}

.content {
text-align: center;
display: inline-block;
}

.title {
font-size: 96px;
margin-bottom: 40px;
}

.quote {
font-size: 24px;
}
</style>
</head>
<body>
<div class=\"container\">
<div class=\"content\">
<div class=\"title\">Maintenance, back soon.</div>
</div>
</div>
</body>
</html>
";
}
}