acassan/supervisord-bundle
Laravel/PHP bundle for managing Supervisord: configure supervisor programs, control processes, and monitor status from your application. A lightweight wrapper to simplify integrating supervisord-based workers and services into your project.
Install the Bundle Add the package via Composer:
composer require acassan/supervisord-bundle
Enable the bundle in config/bundles.php:
return [
// ...
Acassan\SupervisordBundle\SupervisordBundle::class => ['all' => true],
];
Configuration Publish the default config:
php artisan vendor:publish --tag=supervisord-bundle-config
Edit config/supervisord.php to define:
supervisord_path: Path to your supervisord executable (e.g., /usr/bin/supervisord).config_path: Path to your supervisord config file (e.g., config/supervisor.conf).log_path: Directory for supervisord logs (e.g., var/log/supervisord).First Use Case: Start/Stop Supervisord Run supervisord via Artisan:
php artisan supervisord:start
php artisan supervisord:stop
php artisan supervisord:restart
Dynamic Process Management
Use the supervisord:add command to dynamically add processes to supervisord:
php artisan supervisord:add "my_worker:app" --command="php artisan queue:work" --user="www-data"
--command: The command to run.
--user: User to run the process as.
--autostart: Auto-start on supervisord launch.
--autorestart: Auto-restart on failure.Process Monitoring Check process statuses:
php artisan supervisord:status
Outputs a table of running/stopped processes with PIDs.
Configuration-Driven Deployment
Store supervisord configs in config/supervisor.conf (or a custom path) and reference them in your Laravel deployment scripts:
# In deploy.php (Deployer)
run('php artisan supervisord:update');
run('php artisan supervisord:restart');
Event-Driven Integration Listen for supervisord events (e.g., process failures) by extending the bundle or using Laravel’s event system. Example:
// In EventServiceProvider
protected $listen = [
'supervisord.process.failed' => [SupervisorFailureHandler::class, 'handle'],
];
supervisord:start in your entrypoint.sh:
CMD ["php", "artisan", "supervisord:start"]
# GitHub Actions
- name: Restart Supervisord
run: php artisan supervisord:restart
// app/Console/Commands/ScaleWorkers.php
public function handle() {
$this->call('supervisord:scale', [
'process' => 'my_worker',
'count' => 3,
]);
}
Permissions Issues
chown -R www-data:www-data var/log
Config File Overrides
config_path, ensure the file exists and is valid YAML/INI.supervisord -c /path/to/your/config.conf -d
Process Naming Conflicts
app_worker_1, app_worker_2) or prefix with a namespace.Signal Handling
supervisord:stop if processes are stuck. Use supervisord:kill as a fallback:
php artisan supervisord:kill
tail -f var/log/supervisord.log
--dry-run with commands to preview changes:
php artisan supervisord:add --dry-run "test_process"
supervisord -c config/supervisor.conf -i
Custom Process Templates
Override the default process template in config/supervisord.php:
'process_template' => '[program:{name}]
command={command}
autostart={autostart}
autorestart={autorestart}
user={user}
stderr_logfile=/var/log/supervisord/{name}-err.log
stdout_logfile=/var/log/supervisord/{name}-out.log
',
Event Listeners Extend the bundle to trigger Laravel events on supervisord actions. Example:
// In SupervisordBundle
public function addProcess($name, $command) {
// ... existing logic ...
event(new ProcessAdded($name, $command));
}
Database-Backed Config
Store supervisord processes in a database table (e.g., supervisord_processes) and sync them dynamically:
// In a custom command
$processes = DB::table('supervisord_processes')->get();
foreach ($processes as $process) {
$this->call('supervisord:add', [
'name' => $process->name,
'command' => $process->command,
'--user' => $process->user,
]);
}
Environment Awareness Use Laravel’s environment files to conditionally enable/disable supervisord:
// In config/supervisord.php
'enabled' => env('SUPERVISORD_ENABLED', false),
Then guard commands in AppServiceProvider:
if (!config('supervisord.enabled')) {
Artisan::disableCommands(['supervisord:*']);
}
How can I help you explore Laravel packages today?