Compare commits
No commits in common. "master" and "podman" have entirely different histories.
45
README.md
45
README.md
@ -1,40 +1,15 @@
|
||||
# GibCasa GameServerSupervisor
|
||||
|
||||
## Prerequisites
|
||||
# Setup
|
||||
|
||||
Python 3.10 or above
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone the repository:
|
||||
```bash
|
||||
git clone https://git.com.de/GibCasa/GameServerSupervisor
|
||||
```
|
||||
2. Create a virtual environment in Python:
|
||||
```bash
|
||||
python -m venv venv
|
||||
```
|
||||
3. Activate the virtual environment:
|
||||
```bash
|
||||
source venv/bin/activate
|
||||
```
|
||||
4. Install dependencies:
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
5. Run migrations:
|
||||
```bash
|
||||
python manage.py migrate
|
||||
```
|
||||
6. Create admin user:
|
||||
```bash
|
||||
python manage.py createsuperuser
|
||||
```
|
||||
7. Run server:
|
||||
```bash
|
||||
python manage.py runserver
|
||||
```
|
||||
* visit http://localhost:8000 for /public and
|
||||
http://localhost:8000/admin/ to login via the superuser credentials
|
||||
* clone the repo
|
||||
* create venv `python3 -m venv venv`
|
||||
* activate `source venv/bin/activate`
|
||||
* `pip install -r requirements.txt`
|
||||
* will need docker running
|
||||
|
||||
* `python manage.py migrate`
|
||||
* Create admin user: `python manage.py createsuperuser`
|
||||
* `python manage.py runserver`
|
||||
* visit http://localhost:8000 for /public and
|
||||
http://localhost:8000/admin/ to login via the superuser credentials
|
@ -16,9 +16,9 @@ def launch_container(modeladmin, request, queryset):
|
||||
container_name = f"{server.game.name}_{server.ip_address}_{server.port}"
|
||||
try:
|
||||
# Ensure the command is passed as a list of strings
|
||||
command = server.get_podman_run_command().split() if server.run_command else []
|
||||
command = server.get_docker_run_command().split() if server.docker_run_command else []
|
||||
container = client.containers.run(
|
||||
server.image,
|
||||
server.docker_image,
|
||||
detach=True,
|
||||
name=container_name,
|
||||
command=command,
|
||||
@ -48,7 +48,7 @@ def remove_container(modeladmin, request, queryset):
|
||||
|
||||
@admin.register(Server)
|
||||
class ServerAdmin(admin.ModelAdmin):
|
||||
list_display = ('game', 'name', 'ip_address', 'port', 'status', 'image', 'run_command', 'command_args')
|
||||
list_display = ('game', 'name', 'ip_address', 'port', 'status', 'docker_image', 'docker_run_command', 'command_args')
|
||||
search_fields = ('game__name', 'ip_address', 'port')
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
@ -62,6 +62,6 @@ class ServerAdmin(admin.ModelAdmin):
|
||||
return queryset
|
||||
|
||||
list_filter = ('status', 'game')
|
||||
search_fields = ('ip_address', 'game__name', 'image')
|
||||
search_fields = ('ip_address', 'game__name', 'docker_image')
|
||||
ordering = ('game', 'ip_address')
|
||||
actions = [launch_container, stop_container, remove_container]
|
||||
|
@ -1,23 +0,0 @@
|
||||
# Generated by Django 5.1.5 on 2025-02-09 17:03
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("webpanel", "0005_server_command_args_server_docker_run_command"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name="server",
|
||||
old_name="docker_image",
|
||||
new_name="image",
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name="server",
|
||||
old_name="docker_run_command",
|
||||
new_name="run_command",
|
||||
),
|
||||
]
|
@ -18,8 +18,8 @@ class Server(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
ip_address = models.GenericIPAddressField(null=True)
|
||||
port = models.PositiveIntegerField(null=True)
|
||||
image = models.CharField(max_length=200, null=True)
|
||||
run_command = models.CharField(max_length=500, blank=True, null=True)
|
||||
docker_image = models.CharField(max_length=200, null=True)
|
||||
docker_run_command = models.CharField(max_length=500, blank=True, null=True)
|
||||
command_args = models.TextField(blank=True, null=True)
|
||||
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='offline')
|
||||
|
||||
@ -27,7 +27,7 @@ class Server(models.Model):
|
||||
return f"{self.game.name} Server at {self.ip_address}:{self.port}"
|
||||
|
||||
def sync_status(self):
|
||||
"""Check the real-time status of the container and update the field."""
|
||||
"""Check the real-time status of the Docker container and update the field."""
|
||||
client = podman.PodmanClient(base_url="unix:///run/user/1000/podman/podman.sock")
|
||||
container_name = f"{self.game.name}_{self.ip_address}_{self.port}"
|
||||
try:
|
||||
@ -42,11 +42,11 @@ class Server(models.Model):
|
||||
self.status = "offline" # Fallback in case of unexpected errors
|
||||
self.save()
|
||||
|
||||
def get_podman_run_command(self):
|
||||
def get_docker_run_command(self):
|
||||
"""Returns the Podman run command, falling back to default image if not set."""
|
||||
if self.run_command:
|
||||
if self.docker_run_command:
|
||||
# Return command as a string to be split later
|
||||
return self.run_command
|
||||
return self.docker_run_command
|
||||
else:
|
||||
# Default command with image and arguments
|
||||
base_command = f"{self.image}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user