wip: generates supervisord config at runtime
This commit is contained in:
23
compose.yml
23
compose.yml
@@ -33,12 +33,11 @@ services:
|
|||||||
|
|
||||||
|
|
||||||
worker:
|
worker:
|
||||||
# build:
|
build:
|
||||||
# dockerfile: docker/Dockerfile.base.worker
|
dockerfile: docker/Dockerfile.worker
|
||||||
# context: .
|
context: .
|
||||||
# args:
|
args:
|
||||||
# FRANKENPHP_TAG: php8.4-alpine
|
APP_VERSION: latest
|
||||||
image: torsearch-alpine
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- $PWD:/app
|
- $PWD:/app
|
||||||
@@ -46,22 +45,22 @@ services:
|
|||||||
tty: true
|
tty: true
|
||||||
environment:
|
environment:
|
||||||
TZ: America/Chicago
|
TZ: America/Chicago
|
||||||
# command: php /app/bin/console messenger:consume async --time-limit=3600 -vv
|
command: --download 2 --async
|
||||||
|
|
||||||
|
|
||||||
scheduler:
|
scheduler:
|
||||||
build:
|
build:
|
||||||
dockerfile: docker/Dockerfile.base.worker
|
dockerfile: docker/Dockerfile.worker
|
||||||
context: .
|
context: .
|
||||||
args:
|
args:
|
||||||
FRANKENPHP_TAG: php8.4-alpine
|
APP_VERSION: latest
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- $PWD:/app
|
- $PWD:/app
|
||||||
|
- $PWD/var/download:/var/download
|
||||||
|
tty: true
|
||||||
environment:
|
environment:
|
||||||
TZ: America/Chicago
|
TZ: America/Chicago
|
||||||
command: php /app/bin/console messenger:consume scheduler_monitor -vv
|
WORKER_MONITOR: 2
|
||||||
tty: true
|
|
||||||
|
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ RUN apk add --no-cache \
|
|||||||
RUN ln -s /usr/bin/php84 /usr/bin/php
|
RUN ln -s /usr/bin/php84 /usr/bin/php
|
||||||
|
|
||||||
COPY docker/worker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
COPY docker/worker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||||
|
COPY docker/ app/docker
|
||||||
|
|
||||||
# We start supervisord and supervisord starts
|
# We start supervisord and supervisord starts
|
||||||
# respective service in the configuration file.
|
# respective service in the configuration file.
|
||||||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
ENTRYPOINT ["/app/bin/console", "init:worker"]
|
||||||
|
|||||||
10
docker/worker/async.conf
Normal file
10
docker/worker/async.conf
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[program:torsearch-worker]
|
||||||
|
command=/app/bin/console messenger:consume async -vv --time-limit 3600
|
||||||
|
numprocs=1
|
||||||
|
stdout_logfile=/dev/stdout
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/dev/stderr
|
||||||
|
stderr_logfile_maxbytes=0
|
||||||
|
autorestart=true
|
||||||
|
startretries=3
|
||||||
|
process_name=%(program_name)s_%(process_num)02d
|
||||||
10
docker/worker/download.conf
Normal file
10
docker/worker/download.conf
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[program:torsearch-downloader]
|
||||||
|
command=/app/bin/console messenger:consume download -vv --time-limit 3600
|
||||||
|
numprocs=1
|
||||||
|
stdout_logfile=/dev/stdout
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/dev/stderr
|
||||||
|
stderr_logfile_maxbytes=0
|
||||||
|
autorestart=true
|
||||||
|
startretries=3
|
||||||
|
process_name=%(program_name)s_%(process_num)02d
|
||||||
10
docker/worker/monitor.conf
Normal file
10
docker/worker/monitor.conf
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[program:torsearch-scheduler]
|
||||||
|
command=/app/bin/console messenger:consume scheduler_monitor monitor -vv --time-limit 21600
|
||||||
|
numprocs=1
|
||||||
|
stdout_logfile=/dev/stdout
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/dev/stderr
|
||||||
|
stderr_logfile_maxbytes=0
|
||||||
|
autorestart=true
|
||||||
|
startretries=3
|
||||||
|
process_name=%(program_name)s_%(process_num)02d
|
||||||
90
src/Base/Framework/Command/InitWorker.php
Normal file
90
src/Base/Framework/Command/InitWorker.php
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Base\Framework\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
|
class InitWorker extends Command
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private Environment $twig,
|
||||||
|
) {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName('init:worker')
|
||||||
|
->addOption('async', null, InputOption::VALUE_OPTIONAL, 'Run the async worker.',false)
|
||||||
|
->addOption('download', null, InputOption::VALUE_OPTIONAL, 'Run the download worker.', false)
|
||||||
|
->addOption('monitor', null, InputOption::VALUE_OPTIONAL, 'Run the monitor worker.', false)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$configFile = $this->twig->render("config/supervisord.conf.twig", []);
|
||||||
|
|
||||||
|
if ($this->optionExists($input, $output, 'async')) {
|
||||||
|
$configFile .= $this->twig->render("config/async.conf.twig", [
|
||||||
|
'replicas' => $this->getOptionValue('async', $input),
|
||||||
|
]) . "\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->optionExists($input, $output, 'download')) {
|
||||||
|
$configFile .= $this->twig->render("config/download.conf.twig", [
|
||||||
|
'replicas' => $this->getOptionValue('download', $input),
|
||||||
|
]). "\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->optionExists($input, $output, 'monitor')) {
|
||||||
|
$configFile .= $this->twig->render("config/monitor.conf.twig", [
|
||||||
|
'replicas' => $this->getOptionValue('monitor', $input),
|
||||||
|
]). "\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("" !== $configFile) {
|
||||||
|
$output->writeln("[init:worker] Writing /etc/supervisor/conf.d/supervisord.conf");
|
||||||
|
file_put_contents("/etc/supervisor/conf.d/supervisord.conf", $configFile);
|
||||||
|
|
||||||
|
$output->writeln("[init:worker] Starting supervisord");
|
||||||
|
shell_exec("/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf");
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
$output->writeln("[init:worker] No workers selected. Exiting.");
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function optionExists(InputInterface $input, OutputInterface $output, string $option): bool
|
||||||
|
{
|
||||||
|
if ($input->getOption($option) !== false) {
|
||||||
|
$value = $input->getOption($option) ?? 1;
|
||||||
|
$output->writeln("[init:worker] transport: $option // $value // input var");;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$optionKey = 'WORKER_' . strtoupper($option);
|
||||||
|
if (array_key_exists($optionKey, $_SERVER) && $_SERVER[$optionKey] !== null && $_SERVER[$optionKey] !== '') {
|
||||||
|
$output->writeln("[init:worker] transport: $option // $_SERVER[$optionKey] // env var");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getOptionValue(string $option, InputInterface $input): int
|
||||||
|
{
|
||||||
|
if ($input->getOption($option) !== false) {
|
||||||
|
return $input->getOption($option) ?? 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$optionKey = 'WORKER_' . strtoupper($option);
|
||||||
|
return $_SERVER[$optionKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
10
templates/config/async.conf.twig
Normal file
10
templates/config/async.conf.twig
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[program:torsearch-worker]
|
||||||
|
command=/app/bin/console messenger:consume async -vv --time-limit 3600
|
||||||
|
numprocs={{ replicas|default(1) }}
|
||||||
|
stdout_logfile=/dev/stdout
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/dev/stderr
|
||||||
|
stderr_logfile_maxbytes=0
|
||||||
|
autorestart=true
|
||||||
|
startretries=3
|
||||||
|
process_name=%(program_name)s_%(process_num)02d
|
||||||
10
templates/config/download.conf.twig
Normal file
10
templates/config/download.conf.twig
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[program:torsearch-downloader]
|
||||||
|
command=/app/bin/console messenger:consume download -vv --time-limit 3600
|
||||||
|
numprocs={{ replicas|default(1) }}
|
||||||
|
stdout_logfile=/dev/stdout
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/dev/stderr
|
||||||
|
stderr_logfile_maxbytes=0
|
||||||
|
autorestart=true
|
||||||
|
startretries=3
|
||||||
|
process_name=%(program_name)s_%(process_num)02d
|
||||||
10
templates/config/monitor.conf.twig
Normal file
10
templates/config/monitor.conf.twig
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[program:torsearch-scheduler]
|
||||||
|
command=/app/bin/console messenger:consume scheduler_monitor monitor -vv --time-limit 21600
|
||||||
|
numprocs={{ replicas|default(1) }}
|
||||||
|
stdout_logfile=/dev/stdout
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/dev/stderr
|
||||||
|
stderr_logfile_maxbytes=0
|
||||||
|
autorestart=true
|
||||||
|
startretries=3
|
||||||
|
process_name=%(program_name)s_%(process_num)02d
|
||||||
5
templates/config/supervisord.conf.twig
Normal file
5
templates/config/supervisord.conf.twig
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[supervisord]
|
||||||
|
nodaemon=true
|
||||||
|
logfile=/dev/null
|
||||||
|
logfile_maxbytes=0
|
||||||
|
pidfile=/run/supervisord.pid
|
||||||
Reference in New Issue
Block a user