Compare commits

...

20 commits

Author SHA1 Message Date
Bozhidar
030d73cf77 Update ProcessHostingSubscriptionBackup.php 2024-05-07 17:40:36 +03:00
Bozhidar
e4c172218a Update HostingSubscriptionBackup.php 2024-05-07 17:07:09 +03:00
Bozhidar
6e18fb4513 Update ProcessHostingSubscriptionBackup.php 2024-05-07 16:50:11 +03:00
Bozhidar
b77f0ad0ff update 2024-05-07 16:40:06 +03:00
Bozhidar
4320aa029c update 2024-05-07 15:42:17 +03:00
Bozhidar
f81cf44978 update 2024-05-07 15:05:39 +03:00
Bozhidar
cc820a7671 update 2024-05-07 14:48:20 +03:00
Bozhidar
6dc1bad756 update 2024-05-07 14:27:50 +03:00
Bozhidar
c15173af24 update 2024-05-07 14:24:41 +03:00
Bozhidar
3c475ddab0 Update DockerTest.php.stop 2024-05-07 13:49:32 +03:00
Bozhidar
482620edfc Update app-unit-test.yml 2024-05-07 13:46:33 +03:00
Bozhidar
d6f2fd8189 Update app-unit-test.yml 2024-05-07 13:45:53 +03:00
Bozhidar
2113dc97fe Update DomainIsCreatedListener.php 2024-05-07 13:42:47 +03:00
Bozhidar
a363e3cdff Update Backup.php 2024-05-07 12:19:49 +03:00
Bozhidar
93af7e058e Update .drone.yml 2024-05-07 11:49:35 +03:00
Bozhidar
13d8da81d2 Update .drone.yml 2024-05-07 11:48:50 +03:00
Bozhidar
8745b85c34 Update .drone.yml 2024-05-07 11:33:46 +03:00
Bozhidar
3648f319ed Update .drone.yml 2024-05-07 11:23:51 +03:00
Bozhidar
b11c19d8c5 Update .drone.yml 2024-05-07 11:17:58 +03:00
Bozhidar
3a6dac0c15 update 2024-05-07 11:13:25 +03:00
15 changed files with 242 additions and 12384 deletions

28
.drone-extend.yml Normal file
View file

@ -0,0 +1,28 @@
---
kind: pipeline
name: CentOS
steps:
- name: run unit tests
image: centos:latest
commands:
- sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
- sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
- yum update -y
- dnf -y install sudo wget
- sudo wget -q -O - http://www.atomicorp.com/installers/atomic | sh
- mkdir /phyre-panel
- cp installers/centos-stream-9/install-partial/install_base.sh /phyre-panel/install_base.sh
- chmod +x /phyre-panel/install_base.sh
- /phyre-panel/install_base.sh
---
kind: pipeline
name: Debian 12
steps:
- name: run unit tests
image: debian:12
environment:
DEBIAN_FRONTEND: noninteractive
commands:
- apt-get update

View file

@ -1,32 +1,68 @@
--- ---
kind: pipeline kind: pipeline
name: CentOS name: Ubuntu 22.04 - CODE COVERAGE
steps: steps:
- name: run unit tests - name: run unit tests
image: centos:latest image: ubuntu:22.04
commands:
- sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
- sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
- yum update -y
- dnf -y install sudo wget
- sudo wget -q -O - http://www.atomicorp.com/installers/atomic | sh
- mkdir /phyre-panel
- cp installers/centos-stream-9/install-partial/install_base.sh /phyre-panel/install_base.sh
- chmod +x /phyre-panel/install_base.sh
- /phyre-panel/install_base.sh
---
kind: pipeline
name: Debian 12
steps:
- name: run unit tests
image: debian:12
environment: environment:
DEBIAN_FRONTEND: noninteractive DEBIAN_FRONTEND: noninteractive
commands: commands:
- apt-get update - apt-get update
- apt-get install -y libicu-dev sudo cron apt-utils -yqq daemonize dbus-user-session fontconfig rsync
- daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
- ls -la
- mkdir /phyre-panel
- cp installers/ubuntu-22.04/install-partial/install_base.sh /phyre-panel/install_base.sh
- chmod +x /phyre-panel/install_base.sh
- /phyre-panel/install_base.sh
- cp installers/ubuntu-22.04/install-partial/install_web.sh /phyre-panel/install_web.sh
- chmod +x /phyre-panel/install_web.sh
- cp -r web /usr/local/phyre/web/
- cd /usr/local/phyre/web/
- ls -la
- wget https://getcomposer.org/download/latest-stable/composer.phar
- COMPOSER_ALLOW_SUPERUSER=1 phyre-php composer.phar install
- /phyre-panel/install_web.sh
- apt-get install autoconf build-essential -y
- mkdir -p /usr/local/phyre/php-xdebug
- cd /usr/local/phyre/php-xdebug
- wget http://xdebug.org/files/xdebug-3.3.2.tgz
- tar -xvzf xdebug-3.3.2.tgz
- cd xdebug-3.3.2
- /usr/local/phyre/php/bin/phpize
- ./configure --enable-xdebug --with-php-config=/usr/local/phyre/php/bin/php-config
- make
- mkdir -p /usr/local/phyre/php/zend-xdebug
- cp modules/xdebug.so /usr/local/phyre/php/zend-xdebug/xdebug.so
- chmod 777 /usr/local/phyre/php/zend-xdebug/xdebug.so
- cp /usr/local/phyre/web/tests/xdebug-php-ini.txt /usr/local/phyre/php/bin/php.ini
- chmod 777 /usr/local/phyre/php/bin/php.ini
- phyre-php -v
- cd /usr/local/phyre/web/
- chmod -R 777 vendor
- apt install composer -y
- composer test:coverage
- name: codecov
image: robertstettner/drone-codecov
environment:
CODECOV_TOKEN:
from_secret: CODECOV_TOKEN
settings:
token: $CODECOV_TOKEN
files: /usr/local/phyre/web/clover.xml
--- ---
kind: pipeline kind: pipeline
name: Ubuntu 22.04 name: Ubuntu 22.04
@ -34,7 +70,7 @@ steps:
- name: run unit tests - name: run unit tests
image: ubuntu:22.04 image: ubuntu:22.04
environment: environment:
DEBIAN_FRONTEND: noninteractive DEBIAN_FRONTEND: noninteractive
commands: commands:
- apt-get update - apt-get update
- apt-get install -y libicu-dev sudo cron apt-utils -yqq daemonize dbus-user-session fontconfig rsync - apt-get install -y libicu-dev sudo cron apt-utils -yqq daemonize dbus-user-session fontconfig rsync
@ -53,8 +89,3 @@ steps:
- COMPOSER_ALLOW_SUPERUSER=1 phyre-php composer.phar install - COMPOSER_ALLOW_SUPERUSER=1 phyre-php composer.phar install
- /phyre-panel/install_web.sh - /phyre-panel/install_web.sh
- phyre-php artisan test - phyre-php artisan test
# - name: codecov
# image: robertstettner/drone-codecov
# settings:
# token: ${CODECOV_TOKEN}
# files: /usr/local/phyre/web/clover.xml

View file

@ -11,7 +11,7 @@ jobs:
#os: [ubuntu-24.04, ubuntu-22.04, ubuntu-20.04] #os: [ubuntu-24.04, ubuntu-22.04, ubuntu-20.04]
os: [ubuntu-22.04] os: [ubuntu-22.04]
runs-on: hetzner-${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- name: Checkout Repository - name: Checkout Repository
@ -43,7 +43,7 @@ jobs:
sudo COMPOSER_ALLOW_SUPERUSER=1 phyre-php composer.phar install sudo COMPOSER_ALLOW_SUPERUSER=1 phyre-php composer.phar install
sudo /phyre-panel/install_web.sh sudo /phyre-panel/install_web.sh
sudo phyre-php artisan test sudo phyre-php artisan test --filter HostingSubscriptionsTest
compile-phyre-web-panel: compile-phyre-web-panel:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04

View file

@ -43,6 +43,7 @@ class DomainIsCreatedListener
if (! in_array('letsencrypt', $findHostingPlan->additional_services)) { if (! in_array('letsencrypt', $findHostingPlan->additional_services)) {
return; return;
} }
return;
$generalSettings = Settings::general(); $generalSettings = Settings::general();

View file

@ -2,6 +2,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Jobs\ProcessHostingSubscriptionBackup;
use App\Models\Backup; use App\Models\Backup;
use App\Models\HostingSubscription; use App\Models\HostingSubscription;
use App\Models\HostingSubscriptionBackup; use App\Models\HostingSubscriptionBackup;
@ -45,11 +46,7 @@ class CreateDailyFullHostingSubscriptionsBackup extends Command
->where('created_at', '>=', Carbon::now()->subHours(24)) ->where('created_at', '>=', Carbon::now()->subHours(24))
->first(); ->first();
if (! $findBackup) { if (! $findBackup) {
$backup = new HostingSubscriptionBackup(); ProcessHostingSubscriptionBackup::dispatch($hostingSubscription->id);
$backup->hosting_subscription_id = $hostingSubscription->id;
$backup->backup_type = 'full';
$backup->save();
} else { } else {
$this->error('Backup already exists for ' . $hostingSubscription->domain); $this->error('Backup already exists for ' . $hostingSubscription->domain);
$this->error('Created before: ' . $findBackup->created_at->diffForHumans()); $this->error('Created before: ' . $findBackup->created_at->diffForHumans());

View file

@ -1,65 +0,0 @@
<?php
namespace App\Console\Commands;
use App\Models\Backup;
use App\Models\HostingSubscription;
use App\Models\HostingSubscriptionBackup;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class RunHostingSubscriptionsBackupChecks extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'phyre:run-hosting-subscriptions-backup-checks';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle()
{
// Delete backups older than 7 days
$findBackupsForDeleting = HostingSubscriptionBackup::where('created_at', '<', now()->subDays(7))->get();
foreach ($findBackupsForDeleting as $backup) {
$backup->delete();
}
// Check for pending backups
$getPendingBackups = HostingSubscriptionBackup::where('status', 'pending')
->get();
if ($getPendingBackups->count() > 0) {
if ($getPendingBackups->count() > 1) {
$this->info('Multiple backups are pending...');
} else {
foreach ($getPendingBackups as $pendingBackup) {
$pendingBackup->startBackup();
$this->info('Backup started.. ');
}
}
}
// Check for processing backups
$getRunningBackups = HostingSubscriptionBackup::where('status', 'processing')->get();
if ($getRunningBackups->count() > 0) {
foreach ($getRunningBackups as $runningBackup) {
$runningBackup->checkBackup();
$this->info('Checking backup status...');
}
}
}
}

View file

@ -31,6 +31,22 @@ class RunRepair extends Command
public function handle() public function handle()
{ {
// Overwrite supervisor config file
file_put_contents('/etc/supervisor/conf.d/phyre.conf', file_get_contents(base_path('app/Supervisor/configs/phyre-worker.conf')));
// Restart supervisor
shell_exec('service supervisor restart');
// Check supervisor config file
$checkSupervisorStatus = shell_exec('service supervisor status');
if (strpos($checkSupervisorStatus, 'active (running)') !== false) {
$this->info('Supervisor is running');
} else {
$this->info('Supervisor is not running');
$this->info('Restarting supervisor');
shell_exec('service supervisor restart');
}
$checkApacheStatus = shell_exec('service apache2 status'); $checkApacheStatus = shell_exec('service apache2 status');
} }
} }

View file

@ -0,0 +1,70 @@
<?php
namespace App\Jobs;
use App\Filament\Enums\BackupStatus;
use App\Models\HostingSubscription;
use App\Models\HostingSubscriptionBackup;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ProcessHostingSubscriptionBackup implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $id;
/**
* Create a new job instance.
*/
public function __construct($id)
{
$this->id = $id;
}
/**
* Execute the job.
*/
public function handle(): void
{
echo "Backup hosting subscription backup with ID: {$this->id}\n";
$backupDone = false;
$findHostingSubscriptionBackup = HostingSubscriptionBackup::where('id', $this->id)->first();
if ($findHostingSubscriptionBackup) {
if ($findHostingSubscriptionBackup->status == BackupStatus::Pending) {
$findHostingSubscriptionBackup->startBackup();
}
for ($i = 0; $i < 200; $i++) {
echo "Check: ".$i." | Checking backup status...\n";
$findHostingSubscriptionBackup->checkBackup();
if ($findHostingSubscriptionBackup->status == BackupStatus::Completed) {
echo "Backup completed\n";
$backupDone = true;
break;
}
if ($findHostingSubscriptionBackup->status == BackupStatus::Failed) {
echo "Backup failed\n";
break;
}
sleep(4);
}
if (! $backupDone) {
echo "Backup failed\n";
$findHostingSubscriptionBackup->status = BackupStatus::Failed;
$findHostingSubscriptionBackup->save();
}
}
}
}

View file

@ -10,6 +10,8 @@ use Dotenv\Dotenv;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Jackiedo\DotenvEditor\Facades\DotenvEditor; use Jackiedo\DotenvEditor\Facades\DotenvEditor;
@ -220,9 +222,23 @@ class Backup extends Model
$shellFileContent .= 'mysqldump --defaults-extra-file='.$mysqlAuthConf.' "'.env('DB_DATABASE').'" > '.$databaseBackupPath . PHP_EOL; $shellFileContent .= 'mysqldump --defaults-extra-file='.$mysqlAuthConf.' "'.env('DB_DATABASE').'" > '.$databaseBackupPath . PHP_EOL;
// Export Phyre Panel Database
$database = [];
$tables = Schema::getTables();
if (count($tables) > 0) {
foreach ($tables as $table) {
$tableData = [];
$tableData['table'] = $table;
$tableData['columns'] = Schema::getColumnListing($table['name']);
$tableData['data'] = DB::table($table['name'])->get()->toArray();
$database[$table['name']] = $tableData;
}
}
// Export Phyre Panel ENV // Export Phyre Panel ENV
$getEnv = Dotenv::createArrayBacked(base_path())->load(); $getEnv = Dotenv::createArrayBacked(base_path())->load();
$backupStructure = [ $backupStructure = [
'database'=>$database,
'env'=>$getEnv, 'env'=>$getEnv,
]; ];
file_put_contents($backupTempPath.'/backup.json', json_encode($backupStructure, JSON_PRETTY_PRINT)); file_put_contents($backupTempPath.'/backup.json', json_encode($backupStructure, JSON_PRETTY_PRINT));

View file

@ -5,6 +5,7 @@ namespace App\Models;
use App\BackupStorage; use App\BackupStorage;
use App\Filament\Enums\BackupStatus; use App\Filament\Enums\BackupStatus;
use App\Helpers; use App\Helpers;
use App\Jobs\ProcessHostingSubscriptionBackup;
use App\ShellApi; use App\ShellApi;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Casts\Attribute;
@ -55,29 +56,18 @@ class HostingSubscriptionBackup extends Model
}); });
static::created(function ($model) { static::created(function ($model) {
$model->startBackup(); ProcessHostingSubscriptionBackup::dispatch($model->id);
}); });
static::deleting(function ($model) { static::deleting(function ($model) {
// if (is_file($model->filepath)) { if (is_file($model->file_path)) {
// shell_exec('rm -rf ' . $model->filepath); shell_exec('rm -rf ' . $model->file_path);
// } }
}); });
} }
public function checkCronJob() public function checkCronJob()
{ {
$cronJobCommand = 'phyre-php /usr/local/phyre/web/artisan phyre:run-hosting-subscriptions-backup-checks';
$findCronJob = CronJob::where('command', $cronJobCommand)->first();
if (! $findCronJob) {
$cronJob = new CronJob();
$cronJob->schedule = '*/5 * * * *';
$cronJob->command = $cronJobCommand;
$cronJob->user = 'root';
$cronJob->save();
}
$cronJobCommand = 'phyre-php /usr/local/phyre/web/artisan phyre:create-daily-full-hosting-subscriptions-backup'; $cronJobCommand = 'phyre-php /usr/local/phyre/web/artisan phyre:create-daily-full-hosting-subscriptions-backup';
$findCronJob = CronJob::where('command', $cronJobCommand)->first(); $findCronJob = CronJob::where('command', $cronJobCommand)->first();
if (! $findCronJob) { if (! $findCronJob) {

View file

@ -0,0 +1,12 @@
[program:phyre-worker]
process_name=%(program_name)s_%(process_num)02d
command=phyre-php /usr/local/phyre/web/artisan queue:work --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/usr/local/phyre/web/storage/logs/worker.log
stopwaitsecs=3600

12270
web/composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,7 +13,7 @@ return [
| |
*/ */
'default' => env('QUEUE_CONNECTION', 'sync'), 'default' => 'database',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('jobs');
}
};