From 6378fbcf60375e7950e1cbd0c8a359c4d3c7bfa1 Mon Sep 17 00:00:00 2001 From: akirilov <***REMOVED***> Date: Mon, 15 Sep 2025 16:03:19 +0200 Subject: [PATCH 01/16] Added autostart script for systemd --- UIMod/onboard_bundled/scripts/autostart.sh | 31 +++++++++++++++++++++- src/config/config.go | 2 +- src/setup/autostartscripts.go | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/UIMod/onboard_bundled/scripts/autostart.sh b/UIMod/onboard_bundled/scripts/autostart.sh index b3d220b4..9c8cac7f 100644 --- a/UIMod/onboard_bundled/scripts/autostart.sh +++ b/UIMod/onboard_bundled/scripts/autostart.sh @@ -1,3 +1,32 @@ #!/bin/bash -# not yet implemented \ No newline at end of file +if [[ $(id -u) = 0 ]]; then + echo "For security reasons, it is not recommended to run this service as a root user." + exit 1 +fi + +BASEDIR=$(dirname $(readlink -f "$0")) +BINARY=$(find $BASEDIR/* -maxdepth 0 -name "StationeersServerControlv*") + +sudo cat < /etc/systemd/system/ssui.service +[Unit] +Description=Stationeers Server UI +After=network.target + +[Service] +Type=simple +Restart=on-failure +RestartSec=5s +User=$(whoami) +WorkingDirectory=$BASEDIR +ExecStart=$BINARY + +[Install] +WantedBy=multi-user.target +EOF + +sudo systemctl daemon-reload +sudo systemctl enable ssui.service +sudo systemctl start ssui.service + +echo "Success! Service installed in \`/etc/systemd/system/ssui.service\`" \ No newline at end of file diff --git a/src/config/config.go b/src/config/config.go index f1b304e7..1221ec63 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -11,7 +11,7 @@ import ( var ( // All configuration variables can be found in vars.go - Version = "5.6.4" + Version = "5.6.5" Branch = "release" ) diff --git a/src/setup/autostartscripts.go b/src/setup/autostartscripts.go index 4fe653d4..3194f354 100644 --- a/src/setup/autostartscripts.go +++ b/src/setup/autostartscripts.go @@ -40,7 +40,7 @@ func SetupAutostartScripts() { if err != nil { return } - err = os.WriteFile("autostart.service", data, 0755) + err = os.WriteFile("autostart.sh", data, 0755) if err != nil { return } From 7d65ae24aae4a4e4d329e7ccb8710301c93255e1 Mon Sep 17 00:00:00 2001 From: akirilov Date: Mon, 15 Sep 2025 23:20:32 +0900 Subject: [PATCH 02/16] Update UIMod/onboard_bundled/scripts/autostart.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- UIMod/onboard_bundled/scripts/autostart.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UIMod/onboard_bundled/scripts/autostart.sh b/UIMod/onboard_bundled/scripts/autostart.sh index 9c8cac7f..a3c2c534 100644 --- a/UIMod/onboard_bundled/scripts/autostart.sh +++ b/UIMod/onboard_bundled/scripts/autostart.sh @@ -6,7 +6,7 @@ if [[ $(id -u) = 0 ]]; then fi BASEDIR=$(dirname $(readlink -f "$0")) -BINARY=$(find $BASEDIR/* -maxdepth 0 -name "StationeersServerControlv*") +BINARY=$(find $BASEDIR/* -maxdepth 0 -name "StationeersServerControlv*" -print -quit) sudo cat < /etc/systemd/system/ssui.service [Unit] From 6512c24e01ef5223fdea2f5b12e1ca4a10c25e0e Mon Sep 17 00:00:00 2001 From: akirilov <***REMOVED***> Date: Mon, 15 Sep 2025 16:23:56 +0200 Subject: [PATCH 03/16] Implemented code review feedback --- UIMod/onboard_bundled/scripts/autostart.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/UIMod/onboard_bundled/scripts/autostart.sh b/UIMod/onboard_bundled/scripts/autostart.sh index a3c2c534..cf4ea489 100644 --- a/UIMod/onboard_bundled/scripts/autostart.sh +++ b/UIMod/onboard_bundled/scripts/autostart.sh @@ -6,7 +6,15 @@ if [[ $(id -u) = 0 ]]; then fi BASEDIR=$(dirname $(readlink -f "$0")) -BINARY=$(find $BASEDIR/* -maxdepth 0 -name "StationeersServerControlv*" -print -quit) +if [[ -z "$BASEDIR" || ! -d "$BASEDIR" ]]; then + echo "Error: Could not determine base directory." + exit 1 +fi +BINARY=$(find $BASEDIR/* -maxdepth 0 -name "StationeersServerControlv*" -quit) +if [[ -z "$BINARY" || ! -x "$BINARY" ]]; then + echo "Error: Could not find executable StationeersServerControl binary in $BASEDIR." + exit 1 +fi sudo cat < /etc/systemd/system/ssui.service [Unit] @@ -29,4 +37,4 @@ sudo systemctl daemon-reload sudo systemctl enable ssui.service sudo systemctl start ssui.service -echo "Success! Service installed in \`/etc/systemd/system/ssui.service\`" \ No newline at end of file +echo "Success! Service installed in '/etc/systemd/system/ssui.service'" \ No newline at end of file From 4b8cfbbbd25bd36af29f942bfe721d22698ae98a Mon Sep 17 00:00:00 2001 From: akirilov <***REMOVED***> Date: Mon, 15 Sep 2025 17:22:28 +0200 Subject: [PATCH 04/16] Updated the autorun.sh script to be more resilient --- UIMod/onboard_bundled/scripts/autostart.sh | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/UIMod/onboard_bundled/scripts/autostart.sh b/UIMod/onboard_bundled/scripts/autostart.sh index cf4ea489..3701715c 100644 --- a/UIMod/onboard_bundled/scripts/autostart.sh +++ b/UIMod/onboard_bundled/scripts/autostart.sh @@ -1,22 +1,35 @@ #!/bin/bash +# Check if running as root to prevent installing a service as root if [[ $(id -u) = 0 ]]; then echo "For security reasons, it is not recommended to run this service as a root user." exit 1 fi -BASEDIR=$(dirname $(readlink -f "$0")) +# Determine the full path of this script +SCRIPT_PATH=$(readlink -f "$0") + +# Determine the base directory and locate the StationeersServerControl binary +BASEDIR=$(dirname "$SCRIPT_PATH") if [[ -z "$BASEDIR" || ! -d "$BASEDIR" ]]; then echo "Error: Could not determine base directory." exit 1 fi -BINARY=$(find $BASEDIR/* -maxdepth 0 -name "StationeersServerControlv*" -quit) -if [[ -z "$BINARY" || ! -x "$BINARY" ]]; then + +# Find the last modified SSUI binary if multiple exist +SSUI_BINARY=$(ls -t $BASEDIR/StationeersServerControlv* 2>/dev/null | head -n 1 | cut -c 1-) +if [[ -z "$SSUI_BINARY" || ! -x "$SSUI_BINARY" ]]; then echo "Error: Could not find executable StationeersServerControl binary in $BASEDIR." exit 1 fi -sudo cat < /etc/systemd/system/ssui.service +# If the systemd service file already exists, just exec the SSUI binary +if [[ -f /etc/systemd/system/ssui.service ]]; then + exec "$SSUI_BINARY" +fi + +# Create the systemd service file pointing to this script +sudo tee /etc/systemd/system/ssui.service > /dev/null < Date: Mon, 15 Sep 2025 17:34:57 +0200 Subject: [PATCH 05/16] Minor fixes to squash into the PR --- UIMod/onboard_bundled/scripts/autostart.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/UIMod/onboard_bundled/scripts/autostart.sh b/UIMod/onboard_bundled/scripts/autostart.sh index 3701715c..81a24db2 100644 --- a/UIMod/onboard_bundled/scripts/autostart.sh +++ b/UIMod/onboard_bundled/scripts/autostart.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # Check if running as root to prevent installing a service as root if [[ $(id -u) = 0 ]]; then @@ -17,7 +18,7 @@ if [[ -z "$BASEDIR" || ! -d "$BASEDIR" ]]; then fi # Find the last modified SSUI binary if multiple exist -SSUI_BINARY=$(ls -t $BASEDIR/StationeersServerControlv* 2>/dev/null | head -n 1 | cut -c 1-) +SSUI_BINARY=$(ls -t $BASEDIR/StationeersServerControlv* 2>/dev/null | head -n 1) if [[ -z "$SSUI_BINARY" || ! -x "$SSUI_BINARY" ]]; then echo "Error: Could not find executable StationeersServerControl binary in $BASEDIR." exit 1 @@ -25,6 +26,7 @@ fi # If the systemd service file already exists, just exec the SSUI binary if [[ -f /etc/systemd/system/ssui.service ]]; then + echo "Service already installed. Starting SSUI..." exec "$SSUI_BINARY" fi @@ -36,7 +38,7 @@ After=network.target [Service] Type=simple -Restart=on-failure +Restart=always RestartSec=5s User=$(whoami) WorkingDirectory=$BASEDIR From 86df256de92e5c962ead1217dc4ca0a8a4f6670a Mon Sep 17 00:00:00 2001 From: akirilov <***REMOVED***> Date: Mon, 15 Sep 2025 17:38:26 +0200 Subject: [PATCH 06/16] Add a check for systemd and change Restart policy to always. --- UIMod/onboard_bundled/scripts/autostart.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/UIMod/onboard_bundled/scripts/autostart.sh b/UIMod/onboard_bundled/scripts/autostart.sh index 81a24db2..daa4a696 100644 --- a/UIMod/onboard_bundled/scripts/autostart.sh +++ b/UIMod/onboard_bundled/scripts/autostart.sh @@ -7,6 +7,12 @@ if [[ $(id -u) = 0 ]]; then exit 1 fi +# Check if systemd is available +if ! command -v systemctl &> /dev/null; then + echo "Error: systemd is not available on this system." + exit 1 +fi + # Determine the full path of this script SCRIPT_PATH=$(readlink -f "$0") @@ -18,7 +24,7 @@ if [[ -z "$BASEDIR" || ! -d "$BASEDIR" ]]; then fi # Find the last modified SSUI binary if multiple exist -SSUI_BINARY=$(ls -t $BASEDIR/StationeersServerControlv* 2>/dev/null | head -n 1) +SSUI_BINARY=$(ls -t "$BASEDIR"/StationeersServerControlv* 2>/dev/null | head -n 1) if [[ -z "$SSUI_BINARY" || ! -x "$SSUI_BINARY" ]]; then echo "Error: Could not find executable StationeersServerControl binary in $BASEDIR." exit 1 From c8afea714955f5d6c69393d07d6b9c563ef40995 Mon Sep 17 00:00:00 2001 From: akirilov Date: Wed, 17 Sep 2025 11:57:20 +0900 Subject: [PATCH 07/16] Apply suggestions from code review Co-authored-by: JLangisch --- UIMod/onboard_bundled/scripts/autostart.sh | 38 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/UIMod/onboard_bundled/scripts/autostart.sh b/UIMod/onboard_bundled/scripts/autostart.sh index daa4a696..63e8fad5 100644 --- a/UIMod/onboard_bundled/scripts/autostart.sh +++ b/UIMod/onboard_bundled/scripts/autostart.sh @@ -1,6 +1,9 @@ #!/bin/bash set -e - +# This script serves two purposes: +# 1. Installation: Creates and configures a systemd service (ssui.service) to run the StationeersServerControl (StationeersServerUI) application. +# 2. Runtime: When executed and Service already installed, finds and runs the latest StationeersServerControl binary (matching StationeersServerControlv*). +# The systemd service uses ExecStart=$SCRIPT_PATH to run this script, which then dynamically selects the latest binary version of SSUI to run. # Check if running as root to prevent installing a service as root if [[ $(id -u) = 0 ]]; then echo "For security reasons, it is not recommended to run this service as a root user." @@ -24,20 +27,20 @@ if [[ -z "$BASEDIR" || ! -d "$BASEDIR" ]]; then fi # Find the last modified SSUI binary if multiple exist -SSUI_BINARY=$(ls -t "$BASEDIR"/StationeersServerControlv* 2>/dev/null | head -n 1) +SSUI_BINARY=$(find "$BASEDIR" -maxdepth 1 -name 'StationeersServerControlv*' -type f -executable -print0 | xargs -0 ls -t | head -n 1) if [[ -z "$SSUI_BINARY" || ! -x "$SSUI_BINARY" ]]; then echo "Error: Could not find executable StationeersServerControl binary in $BASEDIR." exit 1 fi # If the systemd service file already exists, just exec the SSUI binary -if [[ -f /etc/systemd/system/ssui.service ]]; then +if [[ -f /etc/systemd/system/ssui.service && "$1" != "--install" ]]; then echo "Service already installed. Starting SSUI..." exec "$SSUI_BINARY" fi # Create the systemd service file pointing to this script -sudo tee /etc/systemd/system/ssui.service > /dev/null < /dev/null < Date: Wed, 17 Sep 2025 10:37:11 +0200 Subject: [PATCH 08/16] Minor fixes including symlinking the binary to /usr/local/bin --- UIMod/onboard_bundled/scripts/autostart.sh | 38 +++++++++++++--------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/UIMod/onboard_bundled/scripts/autostart.sh b/UIMod/onboard_bundled/scripts/autostart.sh index 63e8fad5..71785604 100644 --- a/UIMod/onboard_bundled/scripts/autostart.sh +++ b/UIMod/onboard_bundled/scripts/autostart.sh @@ -1,10 +1,12 @@ -#!/bin/bash +#!/usr/bin/env bash set -e + # This script serves two purposes: # 1. Installation: Creates and configures a systemd service (ssui.service) to run the StationeersServerControl (StationeersServerUI) application. # 2. Runtime: When executed and Service already installed, finds and runs the latest StationeersServerControl binary (matching StationeersServerControlv*). # The systemd service uses ExecStart=$SCRIPT_PATH to run this script, which then dynamically selects the latest binary version of SSUI to run. # Check if running as root to prevent installing a service as root + if [[ $(id -u) = 0 ]]; then echo "For security reasons, it is not recommended to run this service as a root user." exit 1 @@ -33,10 +35,20 @@ if [[ -z "$SSUI_BINARY" || ! -x "$SSUI_BINARY" ]]; then exit 1 fi -# If the systemd service file already exists, just exec the SSUI binary -if [[ -f /etc/systemd/system/ssui.service && "$1" != "--install" ]]; then - echo "Service already installed. Starting SSUI..." - exec "$SSUI_BINARY" +# Create a link to the latest binary in /usr/local/bin for easier access +sudo ln -sf "$SSUI_BINARY" /usr/local/bin/StationeersServerControl +if ! sudo chmod 0755 /usr/local/bin/StationeersServerControl; then + echo "Error: Failed to create symlink or set executable permission." + exit 1 +fi + +# If the service is already running, stop it before updating +if systemctl is-active --quiet ssui.service; then + echo "Stopping ssui.service for the update..." + if ! sudo systemctl stop ssui.service; then + echo "Error: Failed to stop ssui.service." + exit 1 + fi fi # Create the systemd service file pointing to this script @@ -51,7 +63,7 @@ Restart=always RestartSec=5s User=$(whoami) WorkingDirectory=$BASEDIR -ExecStart=$SCRIPT_PATH +ExecStart=/usr/local/bin/StationeersServerControl [Install] WantedBy=multi-user.target @@ -61,9 +73,8 @@ then exit 1 fi - # Set service file permissions -sudo chmod 0600 /etc/systemd/system/ssui.service +sudo chmod 0644 /etc/systemd/system/ssui.service if ! sudo systemctl daemon-reload; then echo "Error: Failed to reload systemd daemon." exit 1 @@ -72,14 +83,9 @@ if ! sudo systemctl enable ssui.service; then echo "Error: Failed to enable ssui.service." exit 1 fi -if systemctl is-active --quiet ssui.service; then - echo "Service ssui.service is already running." -else - if ! sudo systemctl start ssui.service; then - echo "Error: Failed to start ssui.service." - exit 1 - fi +if ! sudo systemctl start ssui.service; then + echo "Error: Failed to start ssui.service." + exit 1 fi - echo "Success! Service installed in '/etc/systemd/system/ssui.service'" \ No newline at end of file From 3a1861ccfeae6add992d8d37a623f692e9730eb8 Mon Sep 17 00:00:00 2001 From: akirilov <***REMOVED***> Date: Thu, 18 Sep 2025 07:16:47 +0200 Subject: [PATCH 09/16] Added working directory setup for Linux to handle symlink issues. --- server.go | 1 + src/core/loader/loader.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/server.go b/server.go index 7c5c6677..a5811bcf 100644 --- a/server.go +++ b/server.go @@ -38,6 +38,7 @@ func main() { var wg sync.WaitGroup logger.ConfigureConsole() logger.Install.Info("Starting setup...") + loader.SetupWorkingDir() loader.ReloadConfig() // Load the config file before starting the setup process loader.LoadCmdArgs() setup.Install(&wg) diff --git a/src/core/loader/loader.go b/src/core/loader/loader.go index 72830a12..ce211ef4 100644 --- a/src/core/loader/loader.go +++ b/src/core/loader/loader.go @@ -3,6 +3,9 @@ package loader import ( "embed" + "os" + "path/filepath" + "runtime" "sync" "github.com/JacksonTheMaster/StationeersServerUI/v5/src/config" @@ -16,6 +19,36 @@ import ( "github.com/JacksonTheMaster/StationeersServerUI/v5/src/steamcmd" ) +func SetupWorkingDir() error { + if runtime.GOOS == "windows" { + // For now Windows doesn't have symlinking issues so we'll just let is use the current working directory + return nil + } + if runtime.GOOS == "linux" { + // Get the current executable path from /proc/self/exe + exePath, err := os.Readlink("/proc/self/exe") + if err != nil { + return err + } + // Get the directory path of the executable + dirPath := filepath.Dir(exePath) + // Change the working directory to the executable's directory + cwd, err := os.Getwd() + if err != nil { + return err + } + if cwd != dirPath { + logger.Core.Info("Changing working directory to " + dirPath) + err = os.Chdir(dirPath) + if err != nil { + return err + } + } + return nil + } + return nil +} + // only call this once at startup func InitBackend(wg *sync.WaitGroup) { wg.Add(1) From aa2438efcd7e864cf19a9de39cfe154e6ade9e03 Mon Sep 17 00:00:00 2001 From: JacksonTheMaster <81807824+JacksonTheMaster@users.noreply.github.com> Date: Thu, 18 Sep 2025 13:24:18 +0200 Subject: [PATCH 10/16] Revert "Added working directory setup for Linux to handle symlink issues." This reverts commit 3a1861ccfeae6add992d8d37a623f692e9730eb8. --- server.go | 1 - src/core/loader/loader.go | 33 --------------------------------- 2 files changed, 34 deletions(-) diff --git a/server.go b/server.go index a5811bcf..7c5c6677 100644 --- a/server.go +++ b/server.go @@ -38,7 +38,6 @@ func main() { var wg sync.WaitGroup logger.ConfigureConsole() logger.Install.Info("Starting setup...") - loader.SetupWorkingDir() loader.ReloadConfig() // Load the config file before starting the setup process loader.LoadCmdArgs() setup.Install(&wg) diff --git a/src/core/loader/loader.go b/src/core/loader/loader.go index ce211ef4..72830a12 100644 --- a/src/core/loader/loader.go +++ b/src/core/loader/loader.go @@ -3,9 +3,6 @@ package loader import ( "embed" - "os" - "path/filepath" - "runtime" "sync" "github.com/JacksonTheMaster/StationeersServerUI/v5/src/config" @@ -19,36 +16,6 @@ import ( "github.com/JacksonTheMaster/StationeersServerUI/v5/src/steamcmd" ) -func SetupWorkingDir() error { - if runtime.GOOS == "windows" { - // For now Windows doesn't have symlinking issues so we'll just let is use the current working directory - return nil - } - if runtime.GOOS == "linux" { - // Get the current executable path from /proc/self/exe - exePath, err := os.Readlink("/proc/self/exe") - if err != nil { - return err - } - // Get the directory path of the executable - dirPath := filepath.Dir(exePath) - // Change the working directory to the executable's directory - cwd, err := os.Getwd() - if err != nil { - return err - } - if cwd != dirPath { - logger.Core.Info("Changing working directory to " + dirPath) - err = os.Chdir(dirPath) - if err != nil { - return err - } - } - return nil - } - return nil -} - // only call this once at startup func InitBackend(wg *sync.WaitGroup) { wg.Add(1) From 9b633aed3cd3f292a026b58567546610ae5b4d13 Mon Sep 17 00:00:00 2001 From: JacksonTheMaster <81807824+JacksonTheMaster@users.noreply.github.com> Date: Thu, 18 Sep 2025 13:28:13 +0200 Subject: [PATCH 11/16] fixed linter warning in terminalmsg --- src/core/loader/terminalmsg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/loader/terminalmsg.go b/src/core/loader/terminalmsg.go index 22125f41..4697970d 100644 --- a/src/core/loader/terminalmsg.go +++ b/src/core/loader/terminalmsg.go @@ -31,7 +31,7 @@ func printStartupMessage() { logger.Core.Cleanf(" ╚═══════════════════════════════════════════════════════════════════════════════════════════════════╝") // Web UI info - logger.Core.Cleanf("\n 🌐 Web UI available at: https://localhost:8443 (default) or https://:" + config.GetSSUIWebPort()) + logger.Core.Cleanf("\n 🌐 Web UI available at: https://localhost:8443 (default) or https://:%s", config.GetSSUIWebPort()) logger.Core.Cleanf("\n 🌐 Support available at: https://discord.gg/8n3vN92MyJ") // Quote From db52b8bb125af945e56490a599a6bfd185bfb7ed Mon Sep 17 00:00:00 2001 From: JacksonTheMaster <81807824+JacksonTheMaster@users.noreply.github.com> Date: Thu, 18 Sep 2025 15:31:51 +0200 Subject: [PATCH 12/16] fix autostart script detection in gitignore --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a2349175..0021149c 100644 --- a/.gitignore +++ b/.gitignore @@ -36,10 +36,11 @@ modconfig.xml UIMod/config/config.json C:/custom/file.txt UIMod/config/customdetections.json +autostart.sh +autostart.ps1 winhttp.dll -autostart* __debug_bin* frontend/node_modules frontend/dist frontend/build -UIMod/onboard_bundled/v2 +UIMod/onboard_bundled/v2 \ No newline at end of file From 722467c11c1f95f8180eb1f2df25d744e85d7ae7 Mon Sep 17 00:00:00 2001 From: JacksonTheMaster <81807824+JacksonTheMaster@users.noreply.github.com> Date: Thu, 18 Sep 2025 15:34:56 +0200 Subject: [PATCH 13/16] fix (again) gitignore for autostart --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0021149c..c55c198a 100644 --- a/.gitignore +++ b/.gitignore @@ -36,8 +36,8 @@ modconfig.xml UIMod/config/config.json C:/custom/file.txt UIMod/config/customdetections.json -autostart.sh -autostart.ps1 +./autostart.sh +./autostart.ps1 winhttp.dll __debug_bin* frontend/node_modules From 2875167704a4b3e119d1f59abd05cefa74cf33e3 Mon Sep 17 00:00:00 2001 From: JacksonTheMaster <81807824+JacksonTheMaster@users.noreply.github.com> Date: Thu, 18 Sep 2025 19:35:03 +0200 Subject: [PATCH 14/16] - Introduced autostart package with Initialize function to set up autostart scripts and service. SSUI now can be run with --setupautostart to add a systemd service. - revised autostart.sh to only create the service file - moved SetupAutostartScripts to autostart package, handles script creation for both Windows and Linux. - Created service-lin.go for Linux service setup, including checks for existing service installation. - Added symlink-linux.go to manage symlink creation of a StationeersServerUI.lnk - Implemented container detection to skip symlink creation if running inside a Docker container. - Placeholder for Windows service setup in service-win.go. --- .gitignore | 3 +- UIMod/onboard_bundled/scripts/autostart.sh | 73 +++++++-------- autostart.sh | 78 ++++++++++++++++ server.go | 4 +- src/core/loader/afterstart.go | 1 - src/core/loader/cmdargs.go | 20 +++++ src/core/loader/terminalmsg.go | 5 ++ src/setup/autostart/autostart.go | 24 +++++ src/setup/{ => autostart}/autostartscripts.go | 37 ++++++-- src/setup/autostart/service-lin.go | 72 +++++++++++++++ src/setup/autostart/service-win.go | 8 ++ src/setup/autostart/symlink-linux.go | 88 +++++++++++++++++++ 12 files changed, 357 insertions(+), 56 deletions(-) create mode 100644 autostart.sh create mode 100644 src/setup/autostart/autostart.go rename src/setup/{ => autostart}/autostartscripts.go (57%) create mode 100644 src/setup/autostart/service-lin.go create mode 100644 src/setup/autostart/service-win.go create mode 100644 src/setup/autostart/symlink-linux.go diff --git a/.gitignore b/.gitignore index c55c198a..b1685147 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,5 @@ __debug_bin* frontend/node_modules frontend/dist frontend/build -UIMod/onboard_bundled/v2 \ No newline at end of file +UIMod/onboard_bundled/v2 +StationeersServerUI.lnk \ No newline at end of file diff --git a/UIMod/onboard_bundled/scripts/autostart.sh b/UIMod/onboard_bundled/scripts/autostart.sh index 71785604..a9ee7710 100644 --- a/UIMod/onboard_bundled/scripts/autostart.sh +++ b/UIMod/onboard_bundled/scripts/autostart.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -set -e # This script serves two purposes: # 1. Installation: Creates and configures a systemd service (ssui.service) to run the StationeersServerControl (StationeersServerUI) application. @@ -9,50 +8,30 @@ set -e if [[ $(id -u) = 0 ]]; then echo "For security reasons, it is not recommended to run this service as a root user." - exit 1 + exit 10 fi # Check if systemd is available -if ! command -v systemctl &> /dev/null; then - echo "Error: systemd is not available on this system." - exit 1 +if [[ ! -d /run/systemd/system ]]; then + echo "Error: systemd is not the active init system." + exit 2 fi # Determine the full path of this script SCRIPT_PATH=$(readlink -f "$0") -# Determine the base directory and locate the StationeersServerControl binary +# Determine the base directory BASEDIR=$(dirname "$SCRIPT_PATH") if [[ -z "$BASEDIR" || ! -d "$BASEDIR" ]]; then - echo "Error: Could not determine base directory." - exit 1 + echo "Error: Could not determine base directory from SCRIPT_PATH: '$SCRIPT_PATH'." + exit 3 fi -# Find the last modified SSUI binary if multiple exist -SSUI_BINARY=$(find "$BASEDIR" -maxdepth 1 -name 'StationeersServerControlv*' -type f -executable -print0 | xargs -0 ls -t | head -n 1) -if [[ -z "$SSUI_BINARY" || ! -x "$SSUI_BINARY" ]]; then - echo "Error: Could not find executable StationeersServerControl binary in $BASEDIR." - exit 1 -fi -# Create a link to the latest binary in /usr/local/bin for easier access -sudo ln -sf "$SSUI_BINARY" /usr/local/bin/StationeersServerControl -if ! sudo chmod 0755 /usr/local/bin/StationeersServerControl; then - echo "Error: Failed to create symlink or set executable permission." - exit 1 -fi - -# If the service is already running, stop it before updating -if systemctl is-active --quiet ssui.service; then - echo "Stopping ssui.service for the update..." - if ! sudo systemctl stop ssui.service; then - echo "Error: Failed to stop ssui.service." - exit 1 - fi -fi +USERNAME=$(whoami) # Create the systemd service file pointing to this script -if ! sudo tee /etc/systemd/system/ssui.service > /dev/null < /dev/null < /dev/null < Date: Thu, 18 Sep 2025 19:37:30 +0200 Subject: [PATCH 15/16] - Introduced autostart package with Initialize function to set up autostart scripts and service. SSUI now can be run with --setupautostart to add a systemd service. - revised autostart.sh to only create the service file - moved SetupAutostartScripts to autostart package, handles script creation for both Windows and Linux. - Created service-lin.go for Linux service setup, including checks for existing service installation. - Added symlink-linux.go to manage symlink creation of a StationeersServerUI.lnk - Implemented container detection to skip symlink creation if running inside a Docker container. - Placeholder for Windows service setup in service-win.go. - Added instructions to first time setup message - moved init of VirtFS earlier in server.go --- .gitignore | 3 +- UIMod/onboard_bundled/scripts/autostart.sh | 73 +++++++-------- server.go | 4 +- src/core/loader/afterstart.go | 1 - src/core/loader/cmdargs.go | 20 +++++ src/core/loader/terminalmsg.go | 5 ++ src/setup/autostart/autostart.go | 24 +++++ src/setup/{ => autostart}/autostartscripts.go | 37 ++++++-- src/setup/autostart/service-lin.go | 72 +++++++++++++++ src/setup/autostart/service-win.go | 8 ++ src/setup/autostart/symlink-linux.go | 88 +++++++++++++++++++ 11 files changed, 279 insertions(+), 56 deletions(-) create mode 100644 src/setup/autostart/autostart.go rename src/setup/{ => autostart}/autostartscripts.go (57%) create mode 100644 src/setup/autostart/service-lin.go create mode 100644 src/setup/autostart/service-win.go create mode 100644 src/setup/autostart/symlink-linux.go diff --git a/.gitignore b/.gitignore index c55c198a..b1685147 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,5 @@ __debug_bin* frontend/node_modules frontend/dist frontend/build -UIMod/onboard_bundled/v2 \ No newline at end of file +UIMod/onboard_bundled/v2 +StationeersServerUI.lnk \ No newline at end of file diff --git a/UIMod/onboard_bundled/scripts/autostart.sh b/UIMod/onboard_bundled/scripts/autostart.sh index 71785604..a9ee7710 100644 --- a/UIMod/onboard_bundled/scripts/autostart.sh +++ b/UIMod/onboard_bundled/scripts/autostart.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -set -e # This script serves two purposes: # 1. Installation: Creates and configures a systemd service (ssui.service) to run the StationeersServerControl (StationeersServerUI) application. @@ -9,50 +8,30 @@ set -e if [[ $(id -u) = 0 ]]; then echo "For security reasons, it is not recommended to run this service as a root user." - exit 1 + exit 10 fi # Check if systemd is available -if ! command -v systemctl &> /dev/null; then - echo "Error: systemd is not available on this system." - exit 1 +if [[ ! -d /run/systemd/system ]]; then + echo "Error: systemd is not the active init system." + exit 2 fi # Determine the full path of this script SCRIPT_PATH=$(readlink -f "$0") -# Determine the base directory and locate the StationeersServerControl binary +# Determine the base directory BASEDIR=$(dirname "$SCRIPT_PATH") if [[ -z "$BASEDIR" || ! -d "$BASEDIR" ]]; then - echo "Error: Could not determine base directory." - exit 1 + echo "Error: Could not determine base directory from SCRIPT_PATH: '$SCRIPT_PATH'." + exit 3 fi -# Find the last modified SSUI binary if multiple exist -SSUI_BINARY=$(find "$BASEDIR" -maxdepth 1 -name 'StationeersServerControlv*' -type f -executable -print0 | xargs -0 ls -t | head -n 1) -if [[ -z "$SSUI_BINARY" || ! -x "$SSUI_BINARY" ]]; then - echo "Error: Could not find executable StationeersServerControl binary in $BASEDIR." - exit 1 -fi -# Create a link to the latest binary in /usr/local/bin for easier access -sudo ln -sf "$SSUI_BINARY" /usr/local/bin/StationeersServerControl -if ! sudo chmod 0755 /usr/local/bin/StationeersServerControl; then - echo "Error: Failed to create symlink or set executable permission." - exit 1 -fi - -# If the service is already running, stop it before updating -if systemctl is-active --quiet ssui.service; then - echo "Stopping ssui.service for the update..." - if ! sudo systemctl stop ssui.service; then - echo "Error: Failed to stop ssui.service." - exit 1 - fi -fi +USERNAME=$(whoami) # Create the systemd service file pointing to this script -if ! sudo tee /etc/systemd/system/ssui.service > /dev/null < /dev/null < Date: Thu, 18 Sep 2025 07:16:47 +0200 Subject: [PATCH 16/16] Added working directory setup for Linux to handle symlink issues. --- server.go | 1 + src/core/loader/loader.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/server.go b/server.go index 5b7c840d..282e10d2 100644 --- a/server.go +++ b/server.go @@ -38,6 +38,7 @@ func main() { var wg sync.WaitGroup logger.ConfigureConsole() logger.Main.Debug("Initializing resources...") + loader.SetupWorkingDir() loader.InitVirtFS(v1uiFS) logger.Install.Info("Starting setup...") loader.ReloadConfig() // Load the config file before starting the setup process diff --git a/src/core/loader/loader.go b/src/core/loader/loader.go index 72830a12..ce211ef4 100644 --- a/src/core/loader/loader.go +++ b/src/core/loader/loader.go @@ -3,6 +3,9 @@ package loader import ( "embed" + "os" + "path/filepath" + "runtime" "sync" "github.com/JacksonTheMaster/StationeersServerUI/v5/src/config" @@ -16,6 +19,36 @@ import ( "github.com/JacksonTheMaster/StationeersServerUI/v5/src/steamcmd" ) +func SetupWorkingDir() error { + if runtime.GOOS == "windows" { + // For now Windows doesn't have symlinking issues so we'll just let is use the current working directory + return nil + } + if runtime.GOOS == "linux" { + // Get the current executable path from /proc/self/exe + exePath, err := os.Readlink("/proc/self/exe") + if err != nil { + return err + } + // Get the directory path of the executable + dirPath := filepath.Dir(exePath) + // Change the working directory to the executable's directory + cwd, err := os.Getwd() + if err != nil { + return err + } + if cwd != dirPath { + logger.Core.Info("Changing working directory to " + dirPath) + err = os.Chdir(dirPath) + if err != nil { + return err + } + } + return nil + } + return nil +} + // only call this once at startup func InitBackend(wg *sync.WaitGroup) { wg.Add(1)