mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
feat(Service Manager): add service registry custom dir and restore functionality (#22589)
This pull request introduces significant enhancements to the service management system by adding a service registry with features like automatic tracking, reboot persistence, and restoration of missing services. The goal of this PR is to allow the user to store the service configuration files into an arbitrary directory, in this way they can be easily tracked, versioned, and replicated across different environments It also includes a migration script to transition from the legacy service configuration format to the new registry-based system. Below is a summary of the most important changes: ### Service Registry and Management Enhancements: 1. **Service Registry Integration**: - Added a comprehensive service registry system to track all created services, enabling features like cross-reboot persistence and restoration of missing services (`apps/startup-scripts/src/service-manager.sh`). [[1]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9R41-R229) [[2]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9R273) - Introduced commands for managing the registry, such as `restore` for recreating missing services and `list` for viewing registered services. [[1]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9R273) [[2]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9R332-R334) [[3]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9R346-L172) 2. **PM2 Persistence**: - Enhanced PM2 integration to automatically configure startup persistence across reboots using `pm2 startup` and `pm2 save` after service creation. ### Migration and Compatibility: 3. **Migration Script**: - Added a `migrate-registry.sh` script to convert legacy service configurations into the new registry format. It ensures compatibility while preserving existing service information (`apps/startup-scripts/src/migrate-registry.sh`). ### Documentation Updates: 4. **Updated README**: - Expanded documentation in `README.md` to explain the new service registry features, including usage examples, custom configuration directories, and migration instructions. [[1]](diffhunk://#diff-0917b2888cc9b16539173f318b77773d08f7bf360579b68b9710a96ca2bcbb64L387-R468) [[2]](diffhunk://#diff-0917b2888cc9b16539173f318b77773d08f7bf360579b68b9710a96ca2bcbb64R613-R626) ### Configuration Improvements: 5. **Custom Configuration Directories**: - Added support for overriding the default configuration directory for service registry and files using the `AC_SERVICE_CONFIG_DIR` environment variable. [[1]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9L14-R15) [[2]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9R346-L172) These changes significantly improve the usability, reliability, and maintainability of the service management system, especially for setups requiring persistence and multi-project configurations.
This commit is contained in:
@@ -312,6 +312,9 @@ Services support two restart policies:
|
||||
|
||||
# Edit configuration
|
||||
./service-manager.sh edit world
|
||||
|
||||
# Restore missing services from registry
|
||||
./service-manager.sh restore
|
||||
```
|
||||
|
||||
## 🌍 Multiple Realms Setup
|
||||
@@ -384,22 +387,72 @@ cp examples/restarter-world.sh restarter-realm2.sh
|
||||
|
||||
## 🛠️ Service Management
|
||||
|
||||
### Service Registry and Persistence
|
||||
|
||||
The service manager includes a comprehensive registry system that tracks all created services and enables automatic restoration:
|
||||
|
||||
#### Service Registry Features
|
||||
|
||||
- **Automatic Tracking**: All services are automatically registered when created
|
||||
- **Cross-Reboot Persistence**: PM2 services are configured with startup persistence
|
||||
- **Service Restoration**: Missing services can be detected and restored from registry
|
||||
- **Migration Support**: Legacy service configurations can be migrated to the new format
|
||||
|
||||
#### Using the Registry
|
||||
|
||||
```bash
|
||||
# Check for missing services and restore them
|
||||
./service-manager.sh restore
|
||||
|
||||
# List all registered services (includes status)
|
||||
./service-manager.sh list
|
||||
|
||||
# Services are automatically added to registry on creation
|
||||
./service-manager.sh create auth authserver --bin-path /path/to/bin
|
||||
```
|
||||
|
||||
#### Custom Configuration Directories
|
||||
|
||||
You can customize where service configurations and PM2/systemd files are stored:
|
||||
|
||||
```bash
|
||||
# Set custom directories
|
||||
export AC_SERVICE_CONFIG_DIR="/path/to/your/project/services"
|
||||
|
||||
# Now all service operations will use these custom directories
|
||||
./service-manager.sh create auth authserver --bin-path /path/to/bin
|
||||
```
|
||||
|
||||
This is particularly useful for:
|
||||
- **Version Control**: Keep service configurations in your project repository
|
||||
- **Multiple Projects**: Separate service configurations per project
|
||||
- **Team Collaboration**: Share service setups across development teams
|
||||
|
||||
#### Migration from Legacy Format
|
||||
|
||||
If you have existing services in the old format, use the migration script:
|
||||
|
||||
```bash
|
||||
# Migrate existing registry to new format
|
||||
./migrate-registry.sh
|
||||
|
||||
# The script will:
|
||||
# - Detect old format automatically
|
||||
# - Create a backup of the old registry
|
||||
# - Convert to new format with proper tracking
|
||||
# - Preserve all existing service information
|
||||
```
|
||||
|
||||
### PM2 Services
|
||||
|
||||
When using PM2 as the service provider:
|
||||
|
||||
```bash
|
||||
# PM2-specific commands
|
||||
pm2 list # List all PM2 processes
|
||||
pm2 logs auth # View logs
|
||||
pm2 monit # Real-time monitoring
|
||||
pm2 restart auth # Restart service
|
||||
pm2 delete auth # Remove service
|
||||
* [PM2 CLI Documentation](https://pm2.io/docs/runtime/reference/pm2-cli/)
|
||||
|
||||
# Save PM2 configuration
|
||||
pm2 save
|
||||
pm2 startup # Auto-start on boot
|
||||
```
|
||||
**Automatic PM2 Persistence**: The service manager automatically configures PM2 for persistence across reboots by:
|
||||
- Running `pm2 startup` to set up the startup script
|
||||
- Running `pm2 save` after each service creation/modification
|
||||
- This ensures your services automatically start when the system reboots
|
||||
|
||||
NOTE: pm2 cannot run tmux/screen sessions, but you can always use the `attach` command to connect to the service console because pm2 supports interactive mode.
|
||||
|
||||
@@ -407,6 +460,12 @@ NOTE: pm2 cannot run tmux/screen sessions, but you can always use the `attach` c
|
||||
|
||||
The startup scripts recognize several environment variables for configuration and runtime behavior:
|
||||
|
||||
#### Configuration Directory Variables
|
||||
|
||||
- **`AC_SERVICE_CONFIG_DIR`**: Override the default configuration directory for services registry and configurations
|
||||
- Default: `${XDG_CONFIG_HOME:-$HOME/.config}/azerothcore/services`
|
||||
- Used for storing service registry and run-engine configurations
|
||||
|
||||
#### Service Detection Variables
|
||||
|
||||
- **`AC_LAUNCHED_BY_PM2`**: Set to `1` when launched by PM2 (automatically set by service-manager)
|
||||
@@ -551,4 +610,18 @@ npm install -g pm2
|
||||
sudo npm install -g pm2
|
||||
```
|
||||
|
||||
#### 7. Registry Out of Sync
|
||||
```bash
|
||||
# If the service registry shows services that don't actually exist
|
||||
```
|
||||
**Solution**: Use registry sync or restore
|
||||
```bash
|
||||
# Check and restore missing services (also cleans up orphaned entries)
|
||||
./service-manager.sh restore
|
||||
|
||||
# If you have a very old registry format, migrate it
|
||||
./migrate-registry.sh
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user