forked from itzg/docker-minecraft-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage.ps1
More file actions
102 lines (86 loc) · 3.55 KB
/
manage.ps1
File metadata and controls
102 lines (86 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Minecraft Server Management PowerShell Script
# Common server management commands
param(
[Parameter(Mandatory=$false)]
[ValidateSet("start", "stop", "restart", "status", "logs", "backup", "rcon", "update", "shell")]
[string]$Command = "help"
)
function Show-Help {
Write-Host "🎮 Minecraft Server Management" -ForegroundColor Green
Write-Host "==============================" -ForegroundColor Green
Write-Host ""
Write-Host "Available commands:" -ForegroundColor Yellow
Write-Host " start - Start the server"
Write-Host " stop - Stop the server"
Write-Host " restart - Restart the server"
Write-Host " status - Show server status"
Write-Host " logs - View server logs (press Ctrl+C to exit)"
Write-Host " backup - Create a backup"
Write-Host " rcon - Execute RCON command"
Write-Host " update - Update server images"
Write-Host " shell - Open server shell"
Write-Host ""
Write-Host "Examples:" -ForegroundColor Cyan
Write-Host " .\manage.ps1 -Command start"
Write-Host " .\manage.ps1 -Command logs"
Write-Host " .\manage.ps1 -Command rcon -Argument 'list'"
}
switch ($Command) {
"start" {
Write-Host "🚀 Starting Minecraft server..." -ForegroundColor Blue
docker-compose up -d
Write-Host "✅ Server started!" -ForegroundColor Green
}
"stop" {
Write-Host "⏹️ Stopping Minecraft server..." -ForegroundColor Blue
docker-compose down
Write-Host "✅ Server stopped!" -ForegroundColor Green
}
"restart" {
Write-Host "🔄 Restarting Minecraft server..." -ForegroundColor Blue
docker-compose restart
Write-Host "✅ Server restarted!" -ForegroundColor Green
}
"status" {
Write-Host "📊 Server status:" -ForegroundColor Blue
docker-compose ps
}
"logs" {
Write-Host "📋 Server logs (press Ctrl+C to exit):" -ForegroundColor Blue
docker-compose logs -f
}
"backup" {
Write-Host "💾 Creating backup..." -ForegroundColor Blue
if (-not (Test-Path "backups")) {
New-Item -ItemType Directory -Path "backups" -Force | Out-Null
}
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$backupName = "backup-$timestamp.tar.gz"
docker-compose exec minecraft tar -czf "/backups/$backupName" /data
Write-Host "✅ Backup created: backups\$backupName" -ForegroundColor Green
}
"update" {
Write-Host "🔄 Updating server images..." -ForegroundColor Blue
docker-compose pull
Write-Host "🚀 Recreating containers with new images..." -ForegroundColor Blue
docker-compose up -d
Write-Host "✅ Update complete!" -ForegroundColor Green
}
"shell" {
Write-Host "🐚 Opening server shell..." -ForegroundColor Blue
docker-compose exec minecraft bash
}
"rcon" {
param([string]$Argument)
if (-not $Argument) {
Write-Host "Usage: .\manage.ps1 -Command rcon -Argument 'command'" -ForegroundColor Yellow
Write-Host "Example: .\manage.ps1 -Command rcon -Argument 'list'" -ForegroundColor Cyan
} else {
Write-Host "🔧 Executing RCON command: $Argument" -ForegroundColor Blue
docker-compose exec minecraft rcon-cli $Argument
}
}
default {
Show-Help
}
}