Skip to content

Commit

Permalink
✨ feat(server): Add startup script (#63)
Browse files Browse the repository at this point in the history
## Description

**What issue are you solving (or what feature are you adding) and how
are you doing it?**

We start the container using supervisord, which is limiting as the user
has no way of telling the container what game to run. So, the idea is to
run like so: `docker run... ghcr.io/netrisdotme/netris/server:<tag>
netris-proton /game/yourgame.exe`


Co-authored by @djpremier
  • Loading branch information
wanjohiryan authored May 24, 2024
1 parent e6fa6ea commit 2047304
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .scripts/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#TODO: Fix the warp-input startup problem
if [ -z "$SESSION_ID" ]; then
echo "Error: SESSION_ID environment variable is not set."
exit 1
fi

xarg="$*"

if [ -z "$xarg" ]; then
echo "Error: No command specified to run the game. Exiting."
exit 1
fi

#Open udp port to listed for QUIC events on
export PORT=${PORT:-"8080"}

escaped_xarg=$(printf '%s\n' "$xarg" | sed -e 's/[\/&]/\\&/g')

sudo sed -i "s|^command.*=.*$|command=bash -c \"$escaped_xarg\"|" /etc/supervisord.d/game.ini

sudo sed -i 's|^autostart.*=.*$|autostart=true|' /etc/supervisord.d/game.ini

sudo -E /usr/bin/supervisord -c /etc/supervisord.conf
3 changes: 3 additions & 0 deletions .scripts/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ loglevel=info
logfile=/tmp/supervisord.log
pidfile=/tmp/supervisord.pid

[include]
files = /etc/supervisord.d/*.ini

[program:entrypoint]
command=/etc/entrypoint.sh
logfile=/tmp/entrypoint.log
Expand Down
14 changes: 14 additions & 0 deletions .scripts/supervisord.d/game.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[program:game]
priority=30
autostart=false
autorestart=true
user=netris
# directory=/
command=netris-proton -r /games/AlanWake.exe
stopsignal=INT
logfile=/tmp/game.log
pidfile=/tmp/game.pid
stopsignal=INT
autostart=true
autorestart=true
redirect_stderr=true
3 changes: 3 additions & 0 deletions dev/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

docker build -t server -f server.Dockerfile .
3 changes: 3 additions & 0 deletions dev/run-input.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

cargo run -- --namespace $SESSION_ID --bind "[::]:8080" https://fst.so:4443
5 changes: 5 additions & 0 deletions dev/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -e
NAME="${NAME:-$(head /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | head -c 16)}"

# docker run --gpus all --device=/dev/dri --rm -it --entrypoint /bin/bash -e SESSION_ID=G4r06Kc8vDmwIXPG -v "$(pwd)":/game -p 8080:8080/udp --cap-add=SYS_NICE --cap-add=SYS_ADMIN server
docker run --gpus all --device=/dev/dri --rm -it --entrypoint /bin/bash -e SESSION_ID=$NAME -v "$(pwd)":/game -p 8080:8080/udp --cap-add=SYS_NICE --cap-add=SYS_ADMIN server
File renamed without changes.
4 changes: 2 additions & 2 deletions server.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
COPY --from=ghcr.io/wanjohiryan/netris/warp:nightly /usr/bin/warp /usr/bin/
COPY --from=ghcr.io/games-on-whales/inputtino:stable /inputtino/input-server /inputtino/input-server
RUN chmod +x /usr/bin/warp
COPY .scripts/entrypoint.sh .scripts/supervisord.conf /etc/
RUN chmod 755 /etc/supervisord.conf /etc/entrypoint.sh
COPY .scripts /etc/
RUN chmod 755 /etc/supervisord.conf /etc/entrypoint.sh /etc/startup.sh

USER 1000
ENV SHELL=/bin/bash \
Expand Down

0 comments on commit 2047304

Please sign in to comment.