Update DEV_MODE.md

This commit is contained in:
CanbiZ 2025-11-17 13:21:53 +01:00
parent a60226b1ef
commit 541816f3b6

View File

@ -22,14 +22,17 @@ bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/Proxmo
## Available Modes ## Available Modes
### 1. **motd** - Early SSH/MOTD Setup ### 1. **motd** - Early SSH/MOTD Setup
Sets up SSH access and MOTD **before** the main application installation. Sets up SSH access and MOTD **before** the main application installation.
**Use Case**: **Use Case**:
- Quick access to container for manual debugging - Quick access to container for manual debugging
- Continue installation manually if something goes wrong - Continue installation manually if something goes wrong
- Verify container networking before main install - Verify container networking before main install
**Behavior**: **Behavior**:
``` ```
✔ Container created ✔ Container created
✔ Network configured ✔ Network configured
@ -43,21 +46,24 @@ Sets up SSH access and MOTD **before** the main application installation.
--- ---
### 2. **keep** - Preserve Container on Failure ### 2. **keep** - Preserve Container on Failure
Never delete the container when installation fails. Skips cleanup prompt. Never delete the container when installation fails. Skips cleanup prompt.
**Use Case**: **Use Case**:
- Repeated tests of the same installation - Repeated tests of the same installation
- Debugging failed installations - Debugging failed installations
- Manual fix attempts - Manual fix attempts
**Behavior**: **Behavior**:
``` ```
✖ Installation failed in container 107 (exit code: 1) ✖ Installation failed in container 107 (exit code: 1)
✔ Container creation log: /tmp/create-lxc-107-abc12345.log ✔ Container creation log: /tmp/create-lxc-107-abc12345.log
✔ Installation log: /tmp/install-lxc-107-abc12345.log ✔ Installation log: /tmp/install-lxc-107-abc12345.log
🔧 [DEV] Keep mode active - container 107 preserved 🔧 [DEV] Keep mode active - container 107 preserved
root@proxmox:~# root@proxmox:~#
``` ```
**Container remains**: `pct enter 107` to access and debug **Container remains**: `pct enter 107` to access and debug
@ -67,14 +73,17 @@ root@proxmox:~#
--- ---
### 3. **trace** - Bash Command Tracing ### 3. **trace** - Bash Command Tracing
Enables `set -x` for complete command-line tracing. Shows every command before execution. Enables `set -x` for complete command-line tracing. Shows every command before execution.
**Use Case**: **Use Case**:
- Deep debugging of installation logic - Deep debugging of installation logic
- Understanding script flow - Understanding script flow
- Identifying where errors occur exactly - Identifying where errors occur exactly
**Behavior**: **Behavior**:
``` ```
+(/opt/wallabag/bin/console): /opt/wallabag/bin/console cache:warmup +(/opt/wallabag/bin/console): /opt/wallabag/bin/console cache:warmup
+(/opt/wallabag/bin/console): env APP_ENV=prod /opt/wallabag/bin/console cache:warmup +(/opt/wallabag/bin/console): env APP_ENV=prod /opt/wallabag/bin/console cache:warmup
@ -91,14 +100,17 @@ Enables `set -x` for complete command-line tracing. Shows every command before e
--- ---
### 4. **pause** - Step-by-Step Execution ### 4. **pause** - Step-by-Step Execution
Pauses after each major step (`msg_info`). Requires manual Enter press to continue. Pauses after each major step (`msg_info`). Requires manual Enter press to continue.
**Use Case**: **Use Case**:
- Inspect container state between steps - Inspect container state between steps
- Understand what each step does - Understand what each step does
- Identify which step causes problems - Identify which step causes problems
**Behavior**: **Behavior**:
``` ```
⏳ Setting up Container OS ⏳ Setting up Container OS
[PAUSE] Press Enter to continue... [PAUSE] Press Enter to continue...
@ -109,6 +121,7 @@ Pauses after each major step (`msg_info`). Requires manual Enter press to contin
``` ```
**Between pauses**: You can open another terminal and inspect the container **Between pauses**: You can open another terminal and inspect the container
```bash ```bash
# In another terminal while paused # In another terminal while paused
pct enter 107 pct enter 107
@ -121,14 +134,17 @@ root@container:~# ps aux # Check running processes
--- ---
### 5. **breakpoint** - Interactive Shell on Error ### 5. **breakpoint** - Interactive Shell on Error
Opens interactive shell inside the container when an error occurs instead of cleanup prompt. Opens interactive shell inside the container when an error occurs instead of cleanup prompt.
**Use Case**: **Use Case**:
- Live debugging in the actual container - Live debugging in the actual container
- Manual command testing - Manual command testing
- Inspect container state at point of failure - Inspect container state at point of failure
**Behavior**: **Behavior**:
``` ```
✖ Installation failed in container 107 (exit code: 1) ✖ Installation failed in container 107 (exit code: 1)
✔ Container creation log: /tmp/create-lxc-107-abc12345.log ✔ Container creation log: /tmp/create-lxc-107-abc12345.log
@ -136,7 +152,7 @@ Opens interactive shell inside the container when an error occurs instead of cle
🐛 [DEV] Breakpoint mode - opening shell in container 107 🐛 [DEV] Breakpoint mode - opening shell in container 107
Type 'exit' to return to host Type 'exit' to return to host
root@wallabag:~# root@wallabag:~#
# Now you can debug: # Now you can debug:
root@wallabag:~# tail -f /root/.install-abc12345.log root@wallabag:~# tail -f /root/.install-abc12345.log
@ -153,15 +169,18 @@ Container 107 still running. Remove now? (y/N): n
--- ---
### 6. **logs** - Persistent Logging ### 6. **logs** - Persistent Logging
Saves all logs to `/var/log/community-scripts/` with timestamps. Logs persist even on successful installation. Saves all logs to `/var/log/community-scripts/` with timestamps. Logs persist even on successful installation.
**Use Case**: **Use Case**:
- Post-mortem analysis - Post-mortem analysis
- Performance analysis - Performance analysis
- Automated testing with log collection - Automated testing with log collection
- CI/CD integration - CI/CD integration
**Behavior**: **Behavior**:
``` ```
Logs location: /var/log/community-scripts/ Logs location: /var/log/community-scripts/
@ -170,6 +189,7 @@ install-abc12345-20251117_143022.log (container-side installation)
``` ```
**Access logs**: **Access logs**:
```bash ```bash
# View creation log # View creation log
tail -f /var/log/community-scripts/create-lxc-*.log tail -f /var/log/community-scripts/create-lxc-*.log
@ -182,6 +202,7 @@ grep "msg_info\|msg_ok" /var/log/community-scripts/create-*.log
``` ```
**With trace mode**: Creates detailed trace of all commands **With trace mode**: Creates detailed trace of all commands
```bash ```bash
grep "^+" /var/log/community-scripts/install-*.log grep "^+" /var/log/community-scripts/install-*.log
``` ```
@ -191,15 +212,18 @@ grep "^+" /var/log/community-scripts/install-*.log
--- ---
### 7. **dryrun** - Simulation Mode ### 7. **dryrun** - Simulation Mode
Shows all commands that would be executed without actually running them. Shows all commands that would be executed without actually running them.
**Use Case**: **Use Case**:
- Test script logic without making changes - Test script logic without making changes
- Verify command syntax - Verify command syntax
- Understand what will happen - Understand what will happen
- Pre-flight checks - Pre-flight checks
**Behavior**: **Behavior**:
``` ```
[DRYRUN] apt-get update [DRYRUN] apt-get update
[DRYRUN] apt-get install -y curl [DRYRUN] apt-get install -y curl
@ -217,6 +241,7 @@ Shows all commands that would be executed without actually running them.
## Mode Combinations ## Mode Combinations
### Development Workflow ### Development Workflow
```bash ```bash
# First test: See what would happen # First test: See what would happen
export dev_mode="dryrun,logs" export dev_mode="dryrun,logs"
@ -232,6 +257,7 @@ bash -c "$(curl ...)"
``` ```
### CI/CD Integration ### CI/CD Integration
```bash ```bash
# Automated testing with full logging # Automated testing with full logging
export dev_mode="logs" export dev_mode="logs"
@ -243,6 +269,7 @@ tar czf installation-logs-$(date +%s).tar.gz /var/log/community-scripts/
``` ```
### Production-like Testing ### Production-like Testing
```bash ```bash
# Keep containers for manual verification # Keep containers for manual verification
export dev_mode="keep,logs" export dev_mode="keep,logs"
@ -256,6 +283,7 @@ pct enter 100
``` ```
### Live Debugging ### Live Debugging
```bash ```bash
# SSH in early, step through installation, debug on error # SSH in early, step through installation, debug on error
export dev_mode="motd,pause,breakpoint,keep" export dev_mode="motd,pause,breakpoint,keep"
@ -267,15 +295,18 @@ bash -c "$(curl ...)"
## Environment Variables Reference ## Environment Variables Reference
### Dev Mode Variables ### Dev Mode Variables
- `dev_mode` (string): Comma-separated list of modes - `dev_mode` (string): Comma-separated list of modes
- Format: `"motd,keep,trace"` - Format: `"motd,keep,trace"`
- Default: Empty (no dev modes) - Default: Empty (no dev modes)
### Output Control ### Output Control
- `var_verbose="yes"`: Show all command output (disables silent mode) - `var_verbose="yes"`: Show all command output (disables silent mode)
- Pairs well with: `trace`, `pause`, `logs` - Pairs well with: `trace`, `pause`, `logs`
### Examples with vars ### Examples with vars
```bash ```bash
# Maximum verbosity and debugging # Maximum verbosity and debugging
export var_verbose="yes" export var_verbose="yes"
@ -297,6 +328,7 @@ bash -c "$(curl ...)"
## Troubleshooting with Dev Mode ## Troubleshooting with Dev Mode
### "Installation failed at step X" ### "Installation failed at step X"
```bash ```bash
export dev_mode="pause,logs" export dev_mode="pause,logs"
# Step through until the failure point # Step through until the failure point
@ -305,6 +337,7 @@ pct enter 107
``` ```
### "Password/credentials not working" ### "Password/credentials not working"
```bash ```bash
export dev_mode="motd,keep,trace" export dev_mode="motd,keep,trace"
# With trace mode, see exact password handling (be careful with logs!) # With trace mode, see exact password handling (be careful with logs!)
@ -313,6 +346,7 @@ ssh root@container-ip
``` ```
### "Permission denied errors" ### "Permission denied errors"
```bash ```bash
export dev_mode="breakpoint,keep" export dev_mode="breakpoint,keep"
# Get shell at failure point # Get shell at failure point
@ -322,6 +356,7 @@ whoami
``` ```
### "Networking issues" ### "Networking issues"
```bash ```bash
export dev_mode="motd" export dev_mode="motd"
# SSH in with motd mode before main install # SSH in with motd mode before main install
@ -331,6 +366,7 @@ nslookup example.com
``` ```
### "Need to manually complete installation" ### "Need to manually complete installation"
```bash ```bash
export dev_mode="motd,keep" export dev_mode="motd,keep"
# Container accessible via SSH while installation runs # Container accessible via SSH while installation runs
@ -346,14 +382,17 @@ exit
## Log Files Locations ## Log Files Locations
### Default (without `logs` mode) ### Default (without `logs` mode)
- Host creation: `/tmp/create-lxc-<SESSION_ID>.log` - Host creation: `/tmp/create-lxc-<SESSION_ID>.log`
- Container install: Copied to `/tmp/install-lxc-<CTID>-<SESSION_ID>.log` on failure - Container install: Copied to `/tmp/install-lxc-<CTID>-<SESSION_ID>.log` on failure
### With `logs` mode ### With `logs` mode
- Host creation: `/var/log/community-scripts/create-lxc-<SESSION_ID>-<TIMESTAMP>.log` - Host creation: `/var/log/community-scripts/create-lxc-<SESSION_ID>-<TIMESTAMP>.log`
- Container install: `/var/log/community-scripts/install-<SESSION_ID>-<TIMESTAMP>.log` - Container install: `/var/log/community-scripts/install-<SESSION_ID>-<TIMESTAMP>.log`
### View logs ### View logs
```bash ```bash
# Tail in real-time # Tail in real-time
tail -f /var/log/community-scripts/*.log tail -f /var/log/community-scripts/*.log
@ -370,6 +409,7 @@ grep "ed563b19" /var/log/community-scripts/*.log
## Best Practices ## Best Practices
### ✅ DO ### ✅ DO
- Use `logs` mode for CI/CD and automated testing - Use `logs` mode for CI/CD and automated testing
- Use `motd` for early SSH access during long installations - Use `motd` for early SSH access during long installations
- Use `pause` when learning the installation flow - Use `pause` when learning the installation flow
@ -378,6 +418,7 @@ grep "ed563b19" /var/log/community-scripts/*.log
- Archive logs after successful tests - Archive logs after successful tests
### ❌ DON'T ### ❌ DON'T
- Use `trace` in production or with untrusted networks (exposes secrets) - Use `trace` in production or with untrusted networks (exposes secrets)
- Leave `keep` mode enabled for unattended scripts (containers accumulate) - Leave `keep` mode enabled for unattended scripts (containers accumulate)
- Use `dryrun` and expect actual changes - Use `dryrun` and expect actual changes
@ -389,6 +430,7 @@ grep "ed563b19" /var/log/community-scripts/*.log
## Examples ## Examples
### Example 1: Debug a Failed Installation ### Example 1: Debug a Failed Installation
```bash ```bash
# Initial test to see the failure # Initial test to see the failure
export dev_mode="keep,logs" export dev_mode="keep,logs"
@ -409,6 +451,7 @@ bash -c "$(curl ...)"
``` ```
### Example 2: Verify Installation Steps ### Example 2: Verify Installation Steps
```bash ```bash
export dev_mode="pause,logs" export dev_mode="pause,logs"
export var_verbose="yes" export var_verbose="yes"
@ -421,6 +464,7 @@ bash -c "$(curl ...)"
``` ```
### Example 3: CI/CD Pipeline Integration ### Example 3: CI/CD Pipeline Integration
```bash ```bash
#!/bin/bash #!/bin/bash
export dev_mode="logs" export dev_mode="logs"
@ -445,6 +489,7 @@ tar czf all-logs.tar.gz /var/log/community-scripts/
## Advanced Usage ## Advanced Usage
### Custom Log Analysis ### Custom Log Analysis
```bash ```bash
# Extract all errors # Extract all errors
grep "ERROR\|exit code [1-9]" /var/log/community-scripts/*.log grep "ERROR\|exit code [1-9]" /var/log/community-scripts/*.log
@ -457,6 +502,7 @@ grep "free\|available" /var/log/community-scripts/*.log
``` ```
### Integration with External Tools ### Integration with External Tools
```bash ```bash
# Send logs to Elasticsearch # Send logs to Elasticsearch
curl -X POST "localhost:9200/installation-logs/_doc" \ curl -X POST "localhost:9200/installation-logs/_doc" \
@ -474,6 +520,7 @@ gpg --encrypt installation-records-*.tar.gz
## Support & Issues ## Support & Issues
When reporting installation issues, always include: When reporting installation issues, always include:
```bash ```bash
# Collect all relevant information # Collect all relevant information
export dev_mode="logs" export dev_mode="logs"