Commit 9602eb01 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

FPM waits for all children to finish before exit now

parent 67655e9b
......@@ -3,6 +3,8 @@
set -e
_trap() {
echo "Waiting for child processes to finish"
php artisan fpm:graceful-stop
echo "Stopping FPM"
kill -s SIGQUIT $FPM_PID
}
......
......@@ -3,6 +3,8 @@
set -e
_trap() {
echo "Waiting for child processes to finish"
php artisan fpm:graceful-stop
echo "Stopping FPM"
kill -s SIGQUIT $FPM_PID
}
......
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class FPMGracefulStop extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fpm:graceful-stop';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This command will wait until there are no active fpm processes anymore and then return.';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
do {
$active_fpm_processes = $this->getActiveProcessCount();
usleep(500 * 1000); // Check every half second
} while ($active_fpm_processes === null || $active_fpm_processes > 1);
$this->info("Only one FPM process left. Ready to stop fpm...");
return 0;
}
/**
* Returns the number of active fpm processes
*
* @return int|null Number of active fpm processes; Causes one active process by itself; Null if an error occured
*/
private function getActiveProcessCount()
{
$url = route("fpm-status");
$auth = \base64_encode(config("metager.metager.admin.user") . ":" . config("metager.metager.admin.password"));
$context = \stream_context_create([
"http" => [
"header" => "Authorization: Basic $auth",
],
]);
$fpm_info = \file_get_contents($url, false, $context);
if ($fpm_info !== false) {
$fpm_info = \json_decode($fpm_info);
} else {
return null;
}
if (!\is_object($fpm_info) || !\property_exists($fpm_info, "active-processes")) {
return null;
}
return $fpm_info->{"active-processes"};
}
}
......@@ -205,4 +205,10 @@ class AdminInterface extends Controller
->with('title', 'Wer sucht was? - MetaGer')
->with('q', $q);
}
public function getFPMStatus()
{
$status = \fpm_get_status();
return response()->json($status);
}
}
......@@ -5,6 +5,10 @@ return [
"browserverification_whitelist" => [
"w3m\/",
],
"admin" => [
"user" => env("ADMIN_USER", "admin"),
"password" => env("ADMIN_PASSWORD", "admin"),
],
"affiliate_preference" => "adgoal",
"botprotection" => [
"enabled" => env("BOT_PROTECTION", false),
......
......@@ -18,9 +18,9 @@ class UsersSeeder extends Seeder
DB::table('users')->truncate();
DB::table('users')->insert(
[
'email' => 'admin',
'name' => 'admin',
'password' => Hash::make('admin'),
'email' => config("metager.metager.admin.user"),
'name' => config("metager.metager.admin.user"),
'password' => Hash::make(config("metager.metager.admin.password")),
]
);
}
......
......@@ -238,6 +238,7 @@ Route::get('plugin', function (Request $request) {
});
Route::group(['middleware' => ['auth.basic'], 'prefix' => 'admin'], function () {
Route::get('fpm-status', [AdminInterface::class, "getFPMStatus"])->name("fpm-status");
Route::get('count', 'AdminInterface@count');
Route::get('count/count-data-total', [AdminInterface::class, 'getCountDataTotal']);
Route::get('count/count-data-until', [AdminInterface::class, 'getCountDataUntil']);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment