From d08e5f9c04c2b170a19f5ca3788c7f4dec343898 Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Sun, 3 Jul 2022 15:33:34 +0200 Subject: [PATCH] add documentation how to install server on ubuntu 20.04 and add server version stuff --- MareSynchronosServer/Installation-Linux.md | 84 +++++++++++++++++++ .../{LoggedInUserDto.cs => ConnectionDto.cs} | 3 +- .../.config/dotnet-tools.json | 12 +++ .../Hubs/ConnectionHub.cs | 9 +- .../MareSynchronosServer.csproj | 1 + .../MareSynchronosServer/Program.cs | 9 +- 6 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 MareSynchronosServer/Installation-Linux.md rename MareSynchronosServer/MareSynchronos.API/{LoggedInUserDto.cs => ConnectionDto.cs} (69%) create mode 100644 MareSynchronosServer/MareSynchronosServer/.config/dotnet-tools.json diff --git a/MareSynchronosServer/Installation-Linux.md b/MareSynchronosServer/Installation-Linux.md new file mode 100644 index 0000000..f6e4810 --- /dev/null +++ b/MareSynchronosServer/Installation-Linux.md @@ -0,0 +1,84 @@ +# Installing Mare Server on Ubuntu 20.04 Server LTS + +## Important +- **You _will_ need a valid Certificate for the server.** +- Set one up using LetsEncrypt or use the one provided by your hoster +- The server provided is only guaranteed to run under Ubuntu 20.04 Server LTS. For anything else, you are on your own. The server is provided as a standalone .NET application which does not require .NET Core to be installed. + +## Copy files over +- Connect via SCP and copy over all files to some directory +- The directory will need to be writeable by the user + +## Install MSSQL Server 2019 CU +- Import GPG keys + ```sh + sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - + ``` +- Add repository + ```sh + sudo add-apt-repository "$(curl https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)" + ``` +- Install SQL Server 2019 + ``` + sudo apt-get update + sudo apt-get install -y mssql-server + ``` +- Run configuration + ``` + sudo /opt/mssql/bin/mssql-conf setup + ``` +- Install "3) Express" +- Set a password +- Verify server is running + ``` + systemctl status mssql-server --no-pager + ``` +- Optional: set up a separate user for Mare Synchronos + - I'll let you figure that out yourself + - The user will need database creation rights + +## Configure Mare Server +- open provided appsettings.json +- edit `DefaultConnection` to `"Server=localhost;User=sa;Password=;Database=mare;MultipleActiveResultSets=true"` + - if you created a separate user for mare on the SQL Server, specify the username and password here +- edit `CacheDirectory` and set it to a path where the file cache is supposed to be located. i.e. `/home//servercache` + - you will also need to create that folder +- optional: set Port under edit `Url` and change the `+:5000` to `+:` + + - Set up `Certificate` + - Set `Path` to the certificate file path + - Set `Password` to the password of the certificate + - If the certificate file is split in private key and public, set `KeyPath` to the private key file + - Delete all unused keys from `Certificate` + +## Set up Mare Synchonos Server as a Service +- create new file `/etc/systemd/system/MareSynchronosServer.service` with following contents + ``` + [Unit] + Description=Mare Synchronos Service + + [Service] + WorkingDirectory= + ExecStart=/MareSynchronosServer + SysLogIdentifier=MareSynchronosServer + User= + Restart=always + RestartSec=5 + + [Install] + WantedBy=multi-user.target + ``` +- Reload SystemD daemon + ``` + sudo systemctl daemon-reload + ``` +- Enable the service with + ``` + sudo systemctl enable MareSynchronosServer + ``` +- Start the service with + ``` + sudo systemctl start MareSynchronosServer + ``` +- Log in ingame and add a custom server within the Mare Synchronos Plugin configuration under the address `wss://:` +- That should be it and your server ready to go and running \ No newline at end of file diff --git a/MareSynchronosServer/MareSynchronos.API/LoggedInUserDto.cs b/MareSynchronosServer/MareSynchronos.API/ConnectionDto.cs similarity index 69% rename from MareSynchronosServer/MareSynchronos.API/LoggedInUserDto.cs rename to MareSynchronosServer/MareSynchronos.API/ConnectionDto.cs index 11323f1..0c8b15c 100644 --- a/MareSynchronosServer/MareSynchronos.API/LoggedInUserDto.cs +++ b/MareSynchronosServer/MareSynchronos.API/ConnectionDto.cs @@ -1,7 +1,8 @@ namespace MareSynchronos.API { - public record LoggedInUserDto + public record ConnectionDto { + public int ServerVersion { get; set; } public bool IsAdmin { get; set; } public bool IsModerator { get; set; } public string UID { get; set; } diff --git a/MareSynchronosServer/MareSynchronosServer/.config/dotnet-tools.json b/MareSynchronosServer/MareSynchronosServer/.config/dotnet-tools.json new file mode 100644 index 0000000..c9b7f4f --- /dev/null +++ b/MareSynchronosServer/MareSynchronosServer/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "6.0.6", + "commands": [ + "dotnet-ef" + ] + } + } +} \ No newline at end of file diff --git a/MareSynchronosServer/MareSynchronosServer/Hubs/ConnectionHub.cs b/MareSynchronosServer/MareSynchronosServer/Hubs/ConnectionHub.cs index 35edb0d..b0c22dc 100644 --- a/MareSynchronosServer/MareSynchronosServer/Hubs/ConnectionHub.cs +++ b/MareSynchronosServer/MareSynchronosServer/Hubs/ConnectionHub.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Runtime.ConstrainedExecution; using System.Security.Claims; using System.Threading.Tasks; using MareSynchronos.API; @@ -10,11 +11,12 @@ namespace MareSynchronosServer.Hubs { public class ConnectionHub : BaseHub { + private const int ServerVersion = 1; public ConnectionHub(MareDbContext mareDbContext, ILogger logger) : base(mareDbContext, logger) { } - public async Task Heartbeat() + public async Task Heartbeat() { var userId = Context.User!.Claims.SingleOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value; @@ -23,15 +25,16 @@ namespace MareSynchronosServer.Hubs { Logger.LogInformation("Connection from " + userId); var user = (await DbContext.Users.SingleAsync(u => u.UID == userId)); - return new LoggedInUserDto + return new ConnectionDto { + ServerVersion = ServerVersion, UID = userId, IsModerator = user.IsModerator, IsAdmin = user.IsAdmin }; } - return new LoggedInUserDto(); + return new ConnectionDto(); } } } diff --git a/MareSynchronosServer/MareSynchronosServer/MareSynchronosServer.csproj b/MareSynchronosServer/MareSynchronosServer/MareSynchronosServer.csproj index 3c6d037..f58bb07 100644 --- a/MareSynchronosServer/MareSynchronosServer/MareSynchronosServer.csproj +++ b/MareSynchronosServer/MareSynchronosServer/MareSynchronosServer.csproj @@ -17,6 +17,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/MareSynchronosServer/MareSynchronosServer/Program.cs b/MareSynchronosServer/MareSynchronosServer/Program.cs index c27f10b..13a95e9 100644 --- a/MareSynchronosServer/MareSynchronosServer/Program.cs +++ b/MareSynchronosServer/MareSynchronosServer/Program.cs @@ -1,10 +1,9 @@ using System; -using System.IO; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; using System.Linq; -using System.Reflection; using MareSynchronosServer.Data; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -20,7 +19,10 @@ namespace MareSynchronosServer { var services = scope.ServiceProvider; var context = services.GetRequiredService(); - context.Database.EnsureCreated(); + context.Database.Migrate(); + context.SaveChanges(); + + // clean up residuals var users = context.Users.Where(u => u.CharacterIdentification != null); foreach (var user in users) { @@ -37,6 +39,7 @@ namespace MareSynchronosServer public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) + .UseSystemd() .UseConsoleLifetime() .ConfigureWebHostDefaults(webBuilder => {