-
Notifications
You must be signed in to change notification settings - Fork 2
Add systemd service #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6378fbc
Added autostart script for systemd
7d65ae2
Update UIMod/onboard_bundled/scripts/autostart.sh
akirilov 6512c24
Implemented code review feedback
4b8cfbb
Updated the autorun.sh script to be more resilient
c8574e4
Minor fixes to squash into the PR
86df256
Add a check for systemd and change Restart policy to always.
c8afea7
Apply suggestions from code review
akirilov c67c7fc
Minor fixes including symlinking the binary to /usr/local/bin
698e176
Merge nightly into systemd feature branch
JacksonTheMaster 3a1861c
Added working directory setup for Linux to handle symlink issues.
aa2438e
Revert "Added working directory setup for Linux to handle symlink iss…
JacksonTheMaster 9b633ae
fixed linter warning in terminalmsg
JacksonTheMaster db52b8b
fix autostart script detection in gitignore
JacksonTheMaster 722467c
fix (again) gitignore for autostart
JacksonTheMaster 2875167
- Introduced autostart package with Initialize function to set up aut…
JacksonTheMaster 5a1eeb4
- Introduced autostart package with Initialize function to set up aut…
JacksonTheMaster 0e456fe
Merge branch 'feat-systemd-service' of https://github.com/SteamServer…
JacksonTheMaster 71dd035
Added working directory setup for Linux to handle symlink issues.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,78 @@ | ||
| #!/bin/bash | ||
| #!/usr/bin/env bash | ||
|
|
||
| # not yet implemented | ||
| # 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 10 | ||
| fi | ||
|
|
||
| # Check if systemd is available | ||
| 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 | ||
| BASEDIR=$(dirname "$SCRIPT_PATH") | ||
| if [[ -z "$BASEDIR" || ! -d "$BASEDIR" ]]; then | ||
| echo "Error: Could not determine base directory from SCRIPT_PATH: '$SCRIPT_PATH'." | ||
| exit 3 | ||
| fi | ||
|
|
||
|
|
||
| USERNAME=$(whoami) | ||
|
|
||
| # Create the systemd service file pointing to this script | ||
| sudo tee /etc/systemd/system/stationeersserverui.service > /dev/null <<EOF | ||
| [Unit] | ||
| Description=Stationeers Server UI | ||
| After=network.target | ||
|
|
||
| [Service] | ||
| Type=simple | ||
| Restart=always | ||
| RestartSec=5s | ||
| User=$USERNAME | ||
| WorkingDirectory=$BASEDIR | ||
| ExecStart=$BASEDIR/StationeersServerUI | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| EOF | ||
|
|
||
|
akirilov marked this conversation as resolved.
|
||
| sudo chmod 0644 /etc/systemd/system/ssui.service | ||
| if [[ $? -ne 0 ]]; then | ||
| echo "Error: Failed to set permissions on /etc/systemd/system/ssui.service." | ||
| exit 6 | ||
| fi | ||
|
|
||
| # Reload systemd daemon | ||
| sudo systemctl daemon-reload | ||
|
akirilov marked this conversation as resolved.
|
||
| if [[ $? -ne 0 ]]; then | ||
| echo "Error: Failed to reload systemd daemon." | ||
| exit 7 | ||
| fi | ||
|
|
||
| # Enable the service | ||
| sudo systemctl enable ssui.service | ||
|
akirilov marked this conversation as resolved.
|
||
| if [[ $? -ne 0 ]]; then | ||
| echo "Error: Failed to enable ssui.service." | ||
| exit 8 | ||
| fi | ||
|
|
||
| # Start the service | ||
| sudo systemctl start ssui.service | ||
|
akirilov marked this conversation as resolved.
|
||
| if [[ $? -ne 0 ]]; then | ||
| echo "Error: Failed to start ssui.service." | ||
| exit 9 | ||
| fi | ||
|
|
||
| echo "Success! Service installed in '/etc/systemd/system/ssui.service'" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # 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 10 | ||
| fi | ||
|
|
||
| # Check if systemd is available | ||
| 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 | ||
| BASEDIR=$(dirname "$SCRIPT_PATH") | ||
| if [[ -z "$BASEDIR" || ! -d "$BASEDIR" ]]; then | ||
| echo "Error: Could not determine base directory from SCRIPT_PATH: '$SCRIPT_PATH'." | ||
| exit 3 | ||
| fi | ||
|
|
||
|
|
||
| USERNAME=$(whoami) | ||
|
|
||
| # Create the systemd service file pointing to this script | ||
| sudo tee /etc/systemd/system/stationeersserverui.service > /dev/null <<EOF | ||
| [Unit] | ||
| Description=Stationeers Server UI | ||
| After=network.target | ||
|
|
||
| [Service] | ||
| Type=simple | ||
| Restart=always | ||
| RestartSec=5s | ||
| User=$USERNAME | ||
| WorkingDirectory=$BASEDIR | ||
| ExecStart=$BASEDIR/StationeersServerUI.lnk | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| EOF | ||
|
|
||
| sudo chmod 0644 /etc/systemd/system/ssui.service | ||
| if [[ $? -ne 0 ]]; then | ||
| echo "Error: Failed to set permissions on /etc/systemd/system/ssui.service." | ||
| exit 6 | ||
| fi | ||
|
|
||
| # Reload systemd daemon | ||
| sudo systemctl daemon-reload | ||
| if [[ $? -ne 0 ]]; then | ||
| echo "Error: Failed to reload systemd daemon." | ||
| exit 7 | ||
| fi | ||
|
|
||
| # Enable the service | ||
| sudo systemctl enable ssui.service | ||
| if [[ $? -ne 0 ]]; then | ||
| echo "Error: Failed to enable ssui.service." | ||
| exit 8 | ||
| fi | ||
|
|
||
| # Start the service | ||
| sudo systemctl start ssui.service | ||
| if [[ $? -ne 0 ]]; then | ||
| echo "Error: Failed to start ssui.service." | ||
| exit 9 | ||
| fi | ||
|
|
||
| echo "Success! Service installed in '/etc/systemd/system/ssui.service'" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package autostart | ||
|
|
||
| import ( | ||
| "fmt" | ||
| ) | ||
|
|
||
| func Initialize() error { | ||
|
|
||
| err := SetupAutostartScripts() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to setup autostart script, cannot proceed with autostart setup: %w", err) | ||
| } | ||
|
|
||
| err = SetupBinarySymlink() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create symlink for autostart: %w", err) | ||
| } | ||
|
|
||
| err = SetupService() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to setup service: %w", err) | ||
| } | ||
| return nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.