mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-16 16:45:07 +00:00
ed0d36de25
Updating a server install cost nine artisan invocations plus a PHP-FPM
reload, written out in three places that had already drifted apart. One
of those steps is silently fatal to skip: with opcache.validate_timestamps
off — what production guides recommend and what our own image ships — the
database moves to the new version while every visitor keeps being served
the old code, and artisan reports the new version throughout.
`sudo ./update.sh` is now the whole procedure. It asks whether to check
GitHub, asks whether to download the release and verifies the checksum
published beside it, and asks whether there is a backup — offering to dump
the database when the answer is no. Then it takes the site down, replaces
the files, runs the update, reloads PHP-FPM, restarts the worker and
brings the site back. The application still has no self-updater: nothing
is fetched or applied unless somebody runs this and answers yes.
Underneath it is `php artisan projectsend:update`, which is everything an
update does that needs no root — and now the only definition of it. Both
container entrypoints call it instead of carrying their own copy of the
sequence, so the two paths cannot drift again.
Three findings worth keeping in the record, all from rehearsing rather
than reasoning:
- queue:restart has to come last. It writes its signal into the cache,
so clearing the cache afterwards deletes it and the worker runs old
code forever.
- optimize:clear is not safe to recommend. It runs cache:clear, which
on Redis is FLUSHDB — harmless on the default two-database layout,
but on a single-database Redis it takes the sessions and the queue
with it. The compiled caches are cleared individually instead.
- update.sh overwrites itself mid-run, because the zip contains it and
bash reads its own script lazily by byte offset. It re-execs from a
temporary copy before touching anything.
And when the reload is skipped anyway, the application now says so:
projectsend:update records the version it applied, and any staff page
compares that with what the running process actually compiled. The same
check catches the mirror image — new files in place, update never run.
Rehearsed end to end against real installs: a container upgrade (69 to 73
migrations, key and data intact, healthy), a scripted update on a real
nginx + php-fpm install with OPcache pinned (web process moved 2.1.0 to
2.1.1), the skipped-reload case (banner appears naming both versions, and
clears on reload), the refusals (downgrade, non-release zip, truncated
zip, URL passed to --zip, non-root), a database taken down mid-update
(site comes back out of maintenance mode by itself), and a real download
of the published 2.0.0 zip with its checksum verified.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
82 lines
2.6 KiB
PHP
82 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Platform\Updates\Console;
|
|
|
|
use App\Modules\Platform\Installation\Installation;
|
|
use App\Modules\Platform\Installation\InstallationKind;
|
|
use App\Modules\Platform\Updates\UpdateInstallation;
|
|
use Illuminate\Console\Command;
|
|
|
|
/**
|
|
* Bring this installation in line with the code that is on disk.
|
|
*
|
|
* No options, deliberately: the container entrypoints, update.sh and an
|
|
* administrator typing it all invoke the identical string, which is what
|
|
* makes "one definition of an update" true rather than aspirational.
|
|
* UpdateInstallation holds the sequence and the reasoning.
|
|
*/
|
|
class UpdateCommand extends Command
|
|
{
|
|
protected $signature = 'projectsend:update';
|
|
|
|
protected $description = 'Bring the database, roles and caches in line with the installed code (idempotent; run on every boot)';
|
|
|
|
public function handle(UpdateInstallation $update, Installation $installation): int
|
|
{
|
|
$result = $update->run($this->output);
|
|
|
|
if (! $result['ok']) {
|
|
foreach ($result['warnings'] as $warning) {
|
|
$this->error($warning);
|
|
}
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$this->info('System roles are in place.');
|
|
|
|
if ($result['cleared'] !== []) {
|
|
$this->info('Cleared the compiled configuration, events, routes and views.');
|
|
}
|
|
|
|
if ($result['rewarmed'] !== []) {
|
|
$this->info('Rebuilt the route, event and view caches — they were in place before.');
|
|
}
|
|
|
|
$this->info('Asked the background workers to restart.');
|
|
|
|
foreach ($result['warnings'] as $warning) {
|
|
$this->warn($warning);
|
|
}
|
|
|
|
$this->newLine();
|
|
$this->info($this->summary($result['from'], $result['to']));
|
|
|
|
// A container is replaced rather than reloaded, and its operator
|
|
// has no systemd to reload anything with — printing this there
|
|
// would send them looking for a service that does not exist.
|
|
if ($installation->kind() === InstallationKind::Manual) {
|
|
$this->newLine();
|
|
$this->warn('The web server is still running the code it compiled before this ran.');
|
|
$this->warn('Reload PHP-FPM now, or it will keep serving it: sudo systemctl reload php8.4-fpm');
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
private function summary(string $from, string $to): string
|
|
{
|
|
if ($from === '') {
|
|
return "Applied {$to}.";
|
|
}
|
|
|
|
if ($from === $to) {
|
|
return "Re-applied {$to}.";
|
|
}
|
|
|
|
return "Updated from {$from} to {$to}.";
|
|
}
|
|
}
|