7.4 KiB
Maintenance Mode & Update Management
Overview
AtlasOS provides a maintenance mode feature that allows administrators to safely disable user operations during system updates or maintenance. When maintenance mode is enabled, all mutating operations (create, update, delete) are blocked except for users explicitly allowed.
Features
- Maintenance Mode: Disable user operations during maintenance
- Automatic Backup: Optionally create backup before entering maintenance
- Allowed Users: Specify users who can operate during maintenance
- Health Check Integration: Maintenance status included in health checks
- Audit Logging: All maintenance mode changes are logged
API Endpoints
Get Maintenance Status
GET /api/v1/maintenance
Returns the current maintenance mode status.
Response:
{
"enabled": false,
"enabled_at": "2024-12-20T10:30:00Z",
"enabled_by": "admin",
"reason": "System update",
"allowed_users": ["admin"],
"last_backup_id": "backup-1703123456"
}
Enable Maintenance Mode
POST /api/v1/maintenance
Enables maintenance mode. Requires administrator role.
Request Body:
{
"reason": "System update to v1.1.0",
"allowed_users": ["admin"],
"create_backup": true
}
Fields:
reason(string, required): Reason for entering maintenance modeallowed_users(array of strings, optional): User IDs allowed to operate during maintenancecreate_backup(boolean, optional): Create automatic backup before entering maintenance
Response:
{
"message": "maintenance mode enabled",
"status": {
"enabled": true,
"enabled_at": "2024-12-20T10:30:00Z",
"enabled_by": "admin",
"reason": "System update to v1.1.0",
"allowed_users": ["admin"],
"last_backup_id": "backup-1703123456"
},
"backup_id": "backup-1703123456"
}
Disable Maintenance Mode
POST /api/v1/maintenance/disable
Disables maintenance mode. Requires administrator role.
Response:
{
"message": "maintenance mode disabled"
}
Usage Examples
Enable Maintenance Mode with Backup
curl -X POST http://localhost:8080/api/v1/maintenance \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"reason": "System update to v1.1.0",
"allowed_users": ["admin"],
"create_backup": true
}'
Check Maintenance Status
curl http://localhost:8080/api/v1/maintenance \
-H "Authorization: Bearer $TOKEN"
Disable Maintenance Mode
curl -X POST http://localhost:8080/api/v1/maintenance/disable \
-H "Authorization: Bearer $TOKEN"
Behavior
When Maintenance Mode is Enabled
- Read Operations: All GET requests continue to work normally
- Mutating Operations: All POST, PUT, PATCH, DELETE requests are blocked
- Allowed Users: Users in the
allowed_userslist can still perform operations - Public Endpoints: Public endpoints (login, health checks) continue to work
- Error Response: Blocked operations return
503 Service Unavailablewith message:{ "code": "SERVICE_UNAVAILABLE", "message": "system is in maintenance mode", "details": "the system is currently in maintenance mode and user operations are disabled" }
Middleware Order
Maintenance mode middleware is applied after authentication but before routes:
- CORS
- Compression
- Security headers
- Request size limit
- Content-Type validation
- Rate limiting
- Caching
- Error recovery
- Request ID
- Logging
- Audit
- Maintenance mode ← Blocks operations
- Authentication
- Routes
Health Check Integration
The health check endpoint (/health) includes maintenance mode status:
{
"status": "maintenance",
"timestamp": "2024-12-20T10:30:00Z",
"checks": {
"zfs": "healthy",
"database": "healthy",
"smb": "healthy",
"nfs": "healthy",
"iscsi": "healthy",
"maintenance": "enabled"
}
}
When maintenance mode is enabled:
- Status may change from "healthy" to "maintenance"
checks.maintenancewill be "enabled"
Automatic Backup
When create_backup: true is specified:
- A backup is created automatically before entering maintenance
- The backup ID is stored in maintenance status
- The backup includes:
- All user accounts
- All SMB shares
- All NFS exports
- All iSCSI targets
- All snapshot policies
- System configuration
Best Practices
Before System Updates
- Create Backup: Always enable
create_backup: true - Notify Users: Inform users about maintenance window
- Allow Administrators: Include admin users in
allowed_users - Document Reason: Provide clear reason for maintenance
During Maintenance
- Monitor Status: Check
/api/v1/maintenanceperiodically - Verify Backup: Confirm backup was created successfully
- Perform Updates: Execute system updates or maintenance tasks
- Test Operations: Verify system functionality
After Maintenance
- Disable Maintenance: Use
/api/v1/maintenance/disable - Verify Services: Check all services are running
- Test Operations: Verify normal operations work
- Review Logs: Check audit logs for any issues
Security Considerations
- Administrator Only: Only administrators can enable/disable maintenance mode
- Audit Logging: All maintenance mode changes are logged
- Allowed Users: Only specified users can operate during maintenance
- Token Validation: Maintenance mode respects authentication
Error Handling
Maintenance Mode Already Enabled
{
"code": "INTERNAL_ERROR",
"message": "failed to enable maintenance mode",
"details": "maintenance mode is already enabled"
}
Maintenance Mode Not Enabled
{
"code": "INTERNAL_ERROR",
"message": "failed to disable maintenance mode",
"details": "maintenance mode is not enabled"
}
Backup Creation Failure
If backup creation fails, maintenance mode is not enabled:
{
"code": "INTERNAL_ERROR",
"message": "failed to create backup",
"details": "error details..."
}
Integration with Update Process
Recommended Update Workflow
-
Enable Maintenance Mode:
POST /api/v1/maintenance { "reason": "Updating to v1.1.0", "allowed_users": ["admin"], "create_backup": true } -
Verify Backup:
GET /api/v1/backups/{backup_id} -
Perform System Update:
- Stop services if needed
- Update binaries/configurations
- Restart services
-
Verify System Health:
GET /health -
Disable Maintenance Mode:
POST /api/v1/maintenance/disable -
Test Operations:
- Verify normal operations work
- Check service status
- Review logs
Limitations
- No Automatic Disable: Maintenance mode must be manually disabled
- No Scheduled Maintenance: Maintenance mode must be enabled manually
- No Maintenance History: Only current status is available
- No Notifications: No automatic notifications to users
Future Enhancements
- Scheduled Maintenance: Schedule maintenance windows
- Maintenance History: Track maintenance mode history
- User Notifications: Notify users when maintenance starts/ends
- Automatic Disable: Auto-disable after specified duration
- Maintenance Templates: Predefined maintenance scenarios
- Rollback Support: Automatic rollback on update failure