Skip to content

Commit

Permalink
fix: 获取服务器信息时导致崩溃
Browse files Browse the repository at this point in the history
fix: 某些情况下在控制台输入导致崩溃
ci: 添加docker
  • Loading branch information
Zaitonn committed Jan 2, 2025
1 parent ac4256a commit a63219f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 8 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
on:
push:
paths:
- 'Dockerfile'
- '**/*.cs'
- '**/*.csproj'

workflow_dispatch:

jobs:
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Github Registry
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/serein.cli
tags: |
type=edge
type=sha,event=branch
type=ref,event=tag
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: "Dockerfile"
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64, linux/arm64, linux/arm
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

WORKDIR /src
COPY . .

ARG TARGETARCH
RUN dotnet publish src/Serein.Cli -a $TARGETARCH -c Release -o /app/bin

WORKDIR /app/bin
ENV DOTNET_EnableWriteXorExecute=0

RUN echo "#!/bin/sh \r\n/app/bin/Serein.Cli" > /app/bin/serein-entrypoint.sh
RUN chmod +x /app/bin/serein-entrypoint.sh

ENTRYPOINT [ "/app/bin/serein-entrypoint.sh" ]
17 changes: 14 additions & 3 deletions src/Serein.Cli/Services/Interaction/InputLoopService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,22 @@ out var server
Console.CancelKeyPress -= IgnoreCtrlC;
flag = false;
}
var response = prompt.ReadLineAsync().Await();

if (response.IsSuccess)
try
{
ProcessInput(response.Text);
var response = prompt.ReadLineAsync().Await();

if (response.IsSuccess)
{
ProcessInput(response.Text);
}
}
catch (Exception e)
{
_logger.LogError(
e,
"读取输入时发生错误。若此错误持续出现,请尝试关闭彩色输出"
);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Serein.Core/Services/Servers/ServerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ ReactionTrigger reactionManager
_commandHistory = [];
_cache = [];
_updateTimer = new(2000) { AutoReset = true };
_updateTimer.Elapsed += (_, _) => UpdateInfo();
_updateTimer.Elapsed += (_, _) => Task.Run(UpdateInfo);
_info = new();
PluginManager = new(this);

ServerStatusChanged += (_, _) => UpdateInfo();
ServerStatusChanged += (_, _) => Task.Run(UpdateInfo);
}

protected abstract void StartProcess();
Expand Down Expand Up @@ -441,7 +441,7 @@ private void WaitAndRestart()
);
}

private async Task UpdateInfo()
private void UpdateInfo()
{
if (!Status && _process is null)
{
Expand All @@ -454,7 +454,7 @@ private async Task UpdateInfo()
_info.CpuUsage = 0;
return;
}
else if (_process is null)
else if (_process is null || _process.HasExited)
{
return;
}
Expand All @@ -469,7 +469,7 @@ private async Task UpdateInfo()

if (Configuration.PortIPv4 >= 0)
{
await Task.Run(() => _info.Stat = new("127.0.0.1", (ushort)Configuration.PortIPv4));
_info.Stat = new("127.0.0.1", (ushort)Configuration.PortIPv4);
}
}
}

0 comments on commit a63219f

Please sign in to comment.