76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Models\Supervisor;
|
|
|
|
class SupervisorMaker
|
|
{
|
|
public static $base = '';
|
|
|
|
public static $path = '';
|
|
|
|
public static function run()
|
|
{
|
|
self::$base = base_path().DIRECTORY_SEPARATOR.'supervisor'.DIRECTORY_SEPARATOR;
|
|
|
|
$sup = Supervisor::with('option')
|
|
->with('sport')
|
|
->with('provider')
|
|
->with('client')
|
|
->with('bookmaker')
|
|
->get()->all();
|
|
|
|
foreach ($sup as $row) {
|
|
|
|
$process = $row->command;
|
|
if ($row->option) {
|
|
$process .= '_'.strtolower(preg_replace('"\W"', '', $row->option->name));
|
|
}
|
|
if ($row->provider) {
|
|
$process .= '_'.strtolower(preg_replace('"\W"', '', $row->provider->name));
|
|
}
|
|
if ($row->sport) {
|
|
$process .= '_'.strtolower(preg_replace('"\W"', '', $row->sport->name));
|
|
}
|
|
if ($row->client) {
|
|
$process .= '_'.strtolower(preg_replace('"\W"', '', $row->client->name));
|
|
}
|
|
if ($row->bookmaker) {
|
|
$process .= '_'.strtolower(preg_replace('"\W"', '', $row->bookmaker->name));
|
|
}
|
|
|
|
if (! is_dir(self::$base.$row->command)) {
|
|
mkdir(self::$base.$row->command, 0777, true);
|
|
}
|
|
|
|
self::$path = self::$base.$row->command.DIRECTORY_SEPARATOR;
|
|
|
|
self::create_single($process, $row->is_active, $row->is_cron, $row->command, $row->id);
|
|
}
|
|
|
|
if (config('env.app_env') == 'production') {
|
|
$exec = base_path().'/super_update.sh';
|
|
exec($exec, $out, $rcode);
|
|
}
|
|
}
|
|
|
|
public static function create_single($process, $is_active, $is_cron, $command, $id)
|
|
{
|
|
$file = self::$path.$process.'.ini';
|
|
$content = '[program:'.$process.']'.PHP_EOL;
|
|
$content .= 'command=/usr/bin/php '.base_path().'/artisan '.$command.' '.$id.PHP_EOL;
|
|
$content .= 'autostart=true'.PHP_EOL;
|
|
$content .= 'autorestart=true'.PHP_EOL;
|
|
|
|
if ($is_active && ! $is_cron) {
|
|
file_put_contents($file, $content);
|
|
chmod($file, 0777);
|
|
} else {
|
|
if (is_file($file)) {
|
|
unlink($file);
|
|
}
|
|
}
|
|
}
|
|
}
|