2026-04-23 21:28:51 +03:00
# 🛠 CLI Tools & Database Updates
2026-03-15 00:02:19 +03:00
2026-04-23 21:28:51 +03:00
Reference for XC_VM command-line interface, system tools, and the database update process after version upgrades. Covers daily operations, emergency access, and creating new DB update steps.
2026-03-15 00:02:19 +03:00
---
## 📚 Navigation
2026-04-17 19:56:58 +03:00
- [🖥 Console Entry Point ](#console-entry-point )
- [📋 Full Command Registry ](#full-command-registry )
- [🆕 Registering a New Command ](#registering-a-new-command )
- [🔧 Tools Command ](#tools-command )
2026-04-23 21:28:51 +03:00
- [🗃 Database Updates After Version Upgrade ](#database-updates-after-version-upgrade )
- [📝 Creating a New DB Update Step ](#creating-a-new-db-update-step )
2026-04-17 19:56:58 +03:00
- [⚙️ Common CLI Operations ](#common-cli-operations )
2026-03-15 00:02:19 +03:00
---
2026-04-17 19:56:58 +03:00
## Console Entry Point
2026-03-15 00:02:19 +03:00
All CLI commands are executed through `console.php` :
```bash
2026-04-07 20:49:44 +03:00
/home/xc_vm/console.php <command> [ args...]
2026-03-15 00:02:19 +03:00
```
The console supports three types of commands:
| Type | Count | Description |
2026-04-17 19:56:58 +03:00
| --- | --- | --- |
2026-03-15 00:02:19 +03:00
| **Commands** | 26 | One-time operations (update, status, tools, etc.) |
| **CronJobs** | 25 | Scheduled tasks (auto-invoked by crontab) |
| **Daemons** | 8 | Long-running background processes (Commands using `DaemonTrait` ) |
> **Note:** Daemons are regular Commands that use `DaemonTrait`. There is no separate `Daemons/` directory.
To see all available commands:
```bash
2026-04-07 20:49:44 +03:00
/home/xc_vm/console.php list
2026-03-15 00:02:19 +03:00
```
---
2026-04-17 19:56:58 +03:00
## Full Command Registry
2026-03-15 00:02:19 +03:00
### Utility Commands
| Command | Class | Description | User |
2026-04-17 19:56:58 +03:00
| --- | --- | --- | --- |
2026-04-23 21:28:51 +03:00
| `status` | `StatusCommand` | System status, DB updates, configuration check | root |
2026-03-15 00:02:19 +03:00
| `update` | `UpdateCommand` | System update (update / post-update) | xc_vm |
| `service` | `ServiceCommand` | Manage XC_VM service: start, stop, restart, reload | root |
2026-04-17 19:56:58 +03:00
| `tools` | `ToolsCommand` | Maintenance utilities (see Tools Command section) | root/xc_vm |
2026-03-15 00:02:19 +03:00
| `certbot` | `CertbotCommand` | Generate SSL certificate via certbot | root |
| `binaries` | `BinariesCommand` | Update binaries and GeoLite DB from GitHub | xc_vm |
| `startup` | `StartupCommand` | System initialization: daemons.sh, crontab, cache | root |
| `monitor` | `MonitorCommand` | Monitor stream by ID (start/restart/track) | xc_vm |
| `thumbnail` | `ThumbnailCommand` | Generate thumbnail frames for a stream | xc_vm |
| `plex_item` | `PlexItemCommand` | Process single Plex item (movie/series) | xc_vm |
| `watch_item` | `WatchItemCommand` | Process single Watch item (TMDB search/update) | xc_vm |
2026-04-23 21:28:51 +03:00
| `migrate` | `MigrateCommand` | Transfer data from `xc_vm_migrate` database | xc_vm |
2026-03-15 00:02:19 +03:00
| `balancer` | `BalancerCommand` | Install/configure load balancer via SSH | root |
> Commands marked **optional** are conditionally registered via `file_exists()` guard: `cache_handler`, `balancer`, `migrate`.
### Daemon Commands (persistent processes)
These commands use `DaemonTrait` and run continuously via `while(true)` loops:
| Command | Class | Description |
2026-04-17 19:56:58 +03:00
| --- | --- | --- |
2026-03-15 00:02:19 +03:00
| `signals` | `SignalsCommand` | Process kill/cache signals from DB and Redis |
| `watchdog` | `WatchdogCommand` | System monitoring: CPU, connections, server updates |
| `queue` | `QueueCommand` | Process background queue tasks |
| `scanner` | `ScannerCommand` | Scan for new streams/devices |
| `cache_handler` | `CacheHandlerCommand` | Handle cache operations (optional) |
### Stream Processing Commands
| Command | Class | Description |
2026-04-17 19:56:58 +03:00
| --- | --- | --- |
2026-03-15 00:02:19 +03:00
| `proxy` | `ProxyCommand` | MPEG-TS stream proxying via sockets |
| `archive` | `ArchiveCommand` | TV Archive — record stream into segments |
| `created` | `CreatedCommand` | Created Channel — compose channel from sources |
| `delay` | `DelayCommand` | Delay HLS stream playback |
| `loopback` | `LoopbackCommand` | Receive MPEG-TS from another server |
| `llod` | `LlodCommand` | Low-Latency On-Demand stream processor |
| `record` | `RecordCommand` | Record stream to MP4 |
| `ondemand` | `OndemandCommand` | Kill streams with no active viewers |
### Cron Jobs (25 total)
All cron job names are prefixed with `cron:` . They use `CronTrait` and are invoked by the system crontab.
| Command | Class | Description |
2026-04-17 19:56:58 +03:00
| --- | --- | --- |
2026-03-15 00:02:19 +03:00
| `cron:activity` | `ActivityCronJob` | Import user activity logs into DB |
| `cron:backups` | `BackupsCronJob` | Manage backups (optional) |
| `cron:cache` | `CacheCronJob` | Cache management |
| `cron:cache_engine` | `CacheEngineCronJob` | Generate cache for lines, streams, series, groups (optional) |
| `cron:certbot` | `CertbotCronJob` | SSL certificate renewal |
| `cron:cleanup` | `CleanupCronJob` | Cleanup temporary files and logs |
| `cron:epg` | `EpgCronJob` | EPG download and processing (optional) |
| `cron:errors` | `ErrorsCronJob` | Process error logs |
| `cron:lines_logs` | `LinesLogsCronJob` | Import client request logs into DB |
| `cron:plex` | `PlexCronJob` | Process Plex updates |
| `cron:providers` | `ProvidersCronJob` | Update providers (optional) |
| `cron:root_mysql` | `RootMysqlCronJob` | Database maintenance (root, optional) |
| `cron:root_signals` | `RootSignalsCronJob` | Process signals, iptables, nginx, service management (root) |
| `cron:series` | `SeriesCronJob` | Update series data (optional) |
| `cron:servers` | `ServersCronJob` | Monitor server, launch daemons, update statistics |
| `cron:stats` | `StatsCronJob` | Calculate and store statistics |
| `cron:streams` | `StreamsCronJob` | Verify and update stream status |
| `cron:streams_logs` | `StreamsLogsCronJob` | Import stream logs |
| `cron:tmdb` | `TmdbCronJob` | Fetch TMDB metadata (optional) |
| `cron:tmdb_popular` | `TmdbPopularCronJob` | Fetch popular TMDB content (optional) |
| `cron:tmp` | `TmpCronJob` | Cleanup temporary files |
| `cron:update` | `UpdateCronJob` | Check and apply updates (optional) |
| `cron:users` | `UsersCronJob` | Manage user connections, Redis sync, divergence |
| `cron:vod` | `VodCronJob` | Process VOD content |
| `cron:watch` | `WatchCronJob` | Process Watch library updates |
> Optional cron jobs (conditionally registered): `cron:backups`, `cron:cache_engine`, `cron:epg`, `cron:providers`, `cron:root_mysql`, `cron:series`, `cron:tmdb`, `cron:tmdb_popular`, `cron:update`.
---
2026-04-17 19:56:58 +03:00
## Registering a New Command
2026-03-15 00:02:19 +03:00
All CLI commands implement `CommandInterface` and are explicitly registered in `console.php` .
### CommandInterface
```php
interface CommandInterface {
public function getName () : string ; // Unique command name (used in CLI)
public function getDescription () : string ; // One-line help text (shown in `list`)
public function execute ( array $rArgs ) : int ; // Entry point, returns exit code
}
```
### Step 1. Create the Class
Create a new file in `src/cli/Commands/` (or `src/cli/CronJobs/` for cron jobs):
```php
<? php
class MyNewCommand implements CommandInterface {
public function getName () : string {
return 'my_command' ;
}
public function getDescription () : string {
return 'Short description of what it does' ;
}
public function execute ( array $rArgs ) : int {
// Your logic here
echo "Done. \n " ;
return 0 ; // 0 = success, 1 = error
}
}
```
For **daemon** commands, also use `DaemonTrait` :
```php
class MyDaemonCommand implements CommandInterface {
use DaemonTrait ;
// ...
}
```
For **cron jobs** , use `CronTrait` :
```php
class MyCronJob implements CommandInterface {
use CronTrait ;
public function getName () : string {
return 'cron:my_job' ; // Cron names are prefixed with cron:
}
// ...
}
```
### Step 2. Register in console.php
Add to `console.php` :
```php
// Always loaded
$rRegistry -> register ( new MyNewCommand ());
// Or conditionally (for optional features)
if ( file_exists ( CLI_PATH . 'Commands/MyNewCommand.php' )) {
$rRegistry -> register ( new MyNewCommand ());
}
```
### Step 3. Add to Makefile (if LB-excluded)
If the command should NOT be included in Load Balancer builds, add its path to `LB_FILES_TO_REMOVE` in the `Makefile` .
### Step 4. Test
```bash
# Verify it appears in the list
2026-04-07 20:49:44 +03:00
/home/xc_vm/console.php list
2026-03-15 00:02:19 +03:00
# Run it
2026-04-07 20:49:44 +03:00
/home/xc_vm/console.php my_command
2026-03-15 00:02:19 +03:00
```
---
2026-04-17 19:56:58 +03:00
## Tools Command
2026-03-15 00:02:19 +03:00
The `tools` command provides system maintenance utilities.
```bash
2026-04-07 20:49:44 +03:00
/home/xc_vm/console.php tools <subcommand>
2026-03-15 00:02:19 +03:00
```
### Subcommands (run as `root`)
| Subcommand | Description |
2026-04-17 19:56:58 +03:00
| --- | --- |
2026-03-15 00:02:19 +03:00
| `rescue` | Create a temporary rescue access code for emergency panel access. Prints the URL. **Delete this code after use!** |
| `access` | Regenerate all nginx access code configs and reload nginx. Prints URLs for all admin panel codes. |
| `ports` | Regenerate nginx port configs (HTTP, HTTPS, RTMP) from the database and reload nginx. |
2026-04-23 21:28:51 +03:00
| `migration` | Clear the staging database (`xc_vm_migrate` ) and optionally restore a `.sql` backup into it. |
2026-03-15 00:02:19 +03:00
| `user` | Create a rescue admin user with random credentials. Prints username and password. **Delete this user after use!** |
| `mysql` | Reauthorise MySQL privileges for all load balancer servers. |
| `database` | Restore a blank XC_VM database from `database.sql` . **Erases ALL data!** Requires `--confirm` flag. |
| `flush` | Flush all blocked IPs — clears iptables rules, removes block files, and truncates the `blocked_ips` table. |
### Subcommands (run as `xc_vm`)
| Subcommand | Description |
2026-04-17 19:56:58 +03:00
| --- | --- |
2026-03-15 00:02:19 +03:00
| `images` | Download missing stream/movie/series images from TMDB. Scans DB for image URLs and downloads missing files. |
| `duplicates` | Find and remove duplicate VOD streams. Groups by identical source, keeps first, deletes rest. **Destructive!** |
| `bouquets` | Clean stale references from bouquets. Removes IDs that no longer exist in the database. |
### Examples
```bash
# Emergency panel access (root)
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php tools rescue
2026-03-15 00:02:19 +03:00
# Regenerate access codes (root) — required after nginx template changes
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php tools access
2026-03-15 00:02:19 +03:00
# Regenerate port configuration (root)
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php tools ports
2026-03-15 00:02:19 +03:00
2026-04-23 21:28:51 +03:00
# Clear staging database (root)
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php tools migration
2026-03-15 00:02:19 +03:00
2026-04-23 21:28:51 +03:00
# Clear staging database and restore a backup (root)
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php tools migration /path/to/backup.sql
2026-03-15 00:02:19 +03:00
# Create rescue admin user (root)
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php tools user
2026-03-15 00:02:19 +03:00
# Reauthorise MySQL privileges on all servers (root)
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php tools mysql
2026-03-15 00:02:19 +03:00
# Restore blank database (root) — DESTRUCTIVE!
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php tools database --confirm
2026-03-15 00:02:19 +03:00
# Flush all blocked IPs (root)
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php tools flush
2026-03-15 00:02:19 +03:00
# Download missing images (xc_vm)
2026-04-07 20:49:44 +03:00
su - xc_vm -c '/home/xc_vm/console.php tools images'
2026-03-15 00:02:19 +03:00
# Remove duplicate VOD entries (xc_vm)
2026-04-07 20:49:44 +03:00
su - xc_vm -c '/home/xc_vm/console.php tools duplicates'
2026-03-15 00:02:19 +03:00
# Clean orphaned bouquet references (xc_vm)
2026-04-07 20:49:44 +03:00
su - xc_vm -c '/home/xc_vm/console.php tools bouquets'
2026-03-15 00:02:19 +03:00
```
2026-04-17 19:56:58 +03:00
- ⚠️ **Warning:** `duplicates` permanently deletes streams and all associated data (logs, stats, episodes, recordings). Always back up before running.
- ⚠️ **Warning:** `database --confirm` erases the entire database and replaces it with a blank schema. This is irreversible.
- 💡 **Tip:** After running `rescue` , always delete the code through the admin panel or by running `tools access` once you have regained access.
- 💡 **Tip:** After running `user` , change the password immediately and delete the rescue user when done.
2026-03-15 00:02:19 +03:00
---
2026-04-23 21:28:51 +03:00
## Database Updates After Version Upgrade
2026-03-15 00:02:19 +03:00
2026-04-23 21:28:51 +03:00
XC_VM uses a file-based DB update system to manage schema changes between versions. DB updates are executed automatically during updates and system status checks.
2026-03-15 00:02:19 +03:00
### How It Works
2026-04-23 21:28:51 +03:00
- SQL files for DB updates are stored in `/home/xc_vm/migrations/` .
2026-03-15 00:02:19 +03:00
2026-04-17 19:56:58 +03:00
- Each file is named with a sequential number prefix, for example:
2026-03-15 00:02:19 +03:00
2026-04-17 19:56:58 +03:00
```text
001_drop_watch_folders_plex_token.sql
002_panel_logs_add_file_env.sql
003_drop_settings_segment_type.sql
```
2026-03-15 00:02:19 +03:00
2026-04-23 21:28:51 +03:00
- Applied DB update steps are tracked in the `migrations` database table. Each step runs **exactly once** - if a step has already been applied, it is skipped.
2026-04-17 19:56:58 +03:00
2026-04-23 21:28:51 +03:00
- DB updates are executed automatically by:
2026-04-17 19:56:58 +03:00
- `console.php update post-update` - after a panel update
- `console.php status` - during system status check (MAIN server only)
2026-03-15 00:02:19 +03:00
2026-04-23 21:28:51 +03:00
### DB Update Execution Flow
2026-03-15 00:02:19 +03:00
```text
2026-04-23 21:28:51 +03:00
[ MigrationRunner::run() — DB update execution ]
2026-03-15 00:02:19 +03:00
│
▼
[ CREATE TABLE IF NOT EXISTS `migrations` ]
│
▼
[ Read all *.sql files from migrations/ ]
│
▼
[ For each file not in `migrations` table: ]
├── Execute SQL statements
├── Record in `migrations` table
└── Output [OK] or [WARN]
```
---
2026-04-23 21:28:51 +03:00
## Creating a New DB Update Step
2026-03-15 00:02:19 +03:00
2026-04-23 21:28:51 +03:00
When you need to modify the database schema (add columns, create tables, insert data, etc.), create a new SQL file for a DB update step.
2026-03-15 00:02:19 +03:00
### Step 1. Choose a File Name
Use the next sequential number and a descriptive name:
2026-04-17 19:56:58 +03:00
```text
2026-03-15 00:02:19 +03:00
NNN_short_description.sql
```
**Format rules:**
2026-04-17 19:56:58 +03:00
2026-03-15 00:02:19 +03:00
- Number prefix: 3 digits, zero-padded (e.g., `006` , `007` )
- Separator: underscore `_`
2026-04-23 21:28:51 +03:00
- Name: lowercase, underscores, describing what the update step does
2026-03-15 00:02:19 +03:00
- Extension: `.sql`
**Examples:**
2026-04-17 19:56:58 +03:00
```text
2026-03-15 00:02:19 +03:00
006_add_user_timezone.sql
007_create_audit_log_table.sql
008_insert_default_codec_settings.sql
```
### Step 2. Write the SQL
Place raw SQL statements in the file. Multiple statements are separated by `;` .
2026-04-23 21:28:51 +03:00
**Rules for SQL DB update steps:**
2026-03-15 00:02:19 +03:00
2026-04-23 21:28:51 +03:00
- **Use `IF EXISTS` / `IF NOT EXISTS` ** to make DB update steps idempotent:
2026-03-15 00:02:19 +03:00
```sql
-- Adding a column (safe)
ALTER TABLE ` settings ` ADD COLUMN IF NOT EXISTS ` timezone ` VARCHAR ( 64 ) DEFAULT 'UTC' ;
-- Dropping a column (safe)
ALTER TABLE ` settings ` DROP COLUMN IF EXISTS ` old_column ` ;
-- Creating a table (safe)
CREATE TABLE IF NOT EXISTS ` audit_log ` (
` id ` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY ,
` action ` VARCHAR ( 255 ) NOT NULL ,
` created_at ` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE = InnoDB DEFAULT CHARSET = utf8 ;
```
2026-04-17 19:56:58 +03:00
- **Use conditional `INSERT` ** to avoid duplicates:
2026-03-15 00:02:19 +03:00
```sql
INSERT INTO ` streams_arguments ` ( argument_key , argument_name , argument_cmd )
SELECT 'my_key' , 'My Argument' , '-my_flag %s'
FROM DUAL
WHERE NOT EXISTS ( SELECT 1 FROM ` streams_arguments ` WHERE argument_key = 'my_key' );
```
2026-04-23 21:28:51 +03:00
- **Do not mix DDL and DML** that depend on each other in the same file. If you need to add a column and then populate it, use two DB update step files.
2026-03-15 00:02:19 +03:00
2026-04-17 19:56:58 +03:00
- **Comments** are supported with `--` prefix (they are skipped during execution).
2026-03-15 00:02:19 +03:00
### Step 3. Place the File
2026-04-23 21:28:51 +03:00
Copy the SQL file for the DB update step to:
2026-03-15 00:02:19 +03:00
2026-04-17 19:56:58 +03:00
```text
2026-03-15 00:02:19 +03:00
/home/xc_vm/migrations/
```
> 💡 In the source repository, this is `src/migrations/`.
2026-04-23 21:28:51 +03:00
### Step 4. Validate DB Update
2026-03-15 00:02:19 +03:00
2026-04-23 21:28:51 +03:00
Run the status command to apply pending DB update steps:
2026-03-15 00:02:19 +03:00
```bash
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php status first-run
2026-03-15 00:02:19 +03:00
```
Expected output:
2026-04-17 19:56:58 +03:00
```text
2026-03-15 00:02:19 +03:00
Migrations
------------------------------
[OK] 006_add_user_timezone.sql
```
2026-04-23 21:28:51 +03:00
If a statement fails, the step will still be recorded but show `[WARN]` — review the SQL and fix any issues.
2026-03-15 00:02:19 +03:00
---
2026-04-17 19:56:58 +03:00
## Common CLI Operations
2026-03-15 00:02:19 +03:00
### Status Check
```bash
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php status
2026-03-15 00:02:19 +03:00
```
2026-04-23 21:28:51 +03:00
Checks if XC_VM is running, connects to the database, runs pending DB update steps, fixes permissions, and validates nginx configuration. Required after installation or recovery.
2026-03-15 00:02:19 +03:00
With `first-run` argument, skips the running check — used for initial setup:
```bash
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php status first-run
2026-03-15 00:02:19 +03:00
```
### Service Management
```bash
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php service start| stop| restart| reload
2026-03-15 00:02:19 +03:00
```
### Manual Update
```bash
2026-04-07 20:49:44 +03:00
sudo -u xc_vm /home/xc_vm/console.php update update
2026-03-15 00:02:19 +03:00
```
Downloads and applies the latest update from GitHub. Usually triggered automatically through the web panel.
### Stream Diagnostics
```bash
2026-04-07 20:49:44 +03:00
sudo -u xc_vm /home/xc_vm/console.php monitor <stream_id>
2026-03-15 00:02:19 +03:00
```
Starts a stream manually and displays any errors. Useful for diagnosing stream startup failures.
### SSL Certificate
```bash
2026-04-07 20:49:44 +03:00
sudo /home/xc_vm/console.php certbot
2026-03-15 00:02:19 +03:00
```
2026-04-23 21:28:51 +03:00
### Database Update with Data from Other Systems
2026-03-15 00:02:19 +03:00
```bash
2026-04-07 20:49:44 +03:00
/home/xc_vm/console.php migrate
2026-03-15 00:02:19 +03:00
```
2026-04-23 21:28:51 +03:00
Transfers data from the staging database `xc_vm_migrate` . See the [Database Update Guide ](en-us/info/migration_guide.md ) for details.
2026-03-15 00:02:19 +03:00
---