Add sunshine as an optional background service
This commit is contained in:
16
overlay/etc/cont-init.d/90-configure_sunshine.sh
Normal file
16
overlay/etc/cont-init.d/90-configure_sunshine.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
echo "**** Configure Sunshine ****"
|
||||
|
||||
if ([ "${MODE}" != "s" ] && [ "${MODE}" != "secondary" ]); then
|
||||
if [ "${ENABLE_SUNSHINE:-}" = "true" ]; then
|
||||
echo "Enable Sunshine server"
|
||||
sed -i 's|^autostart.*=.*$|autostart=true|' /etc/supervisor.d/sunshine.ini
|
||||
chmod +x /usr/bin/start-sunshine.sh
|
||||
else
|
||||
echo "Disable Sunshine server"
|
||||
fi
|
||||
else
|
||||
echo "Sunshine server not available when container is run in 'secondary' mode"
|
||||
fi
|
||||
|
||||
echo "DONE"
|
||||
20
overlay/etc/supervisor.d/sunshine.ini
Normal file
20
overlay/etc/supervisor.d/sunshine.ini
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
[program:sunshine]
|
||||
priority=50
|
||||
autostart=false
|
||||
autorestart=true
|
||||
# Retry a restart a few times.
|
||||
# The start-sunshine.sh script has a section that will wait for the
|
||||
# X server to become available before executing sunshine. However, this will time out after 30 seconds.
|
||||
startretries=10
|
||||
user=%(ENV_USER)s
|
||||
directory=/home/%(ENV_USER)s
|
||||
command=/usr/bin/start-sunshine.sh
|
||||
environment=HOME="/home/%(ENV_USER)s",USER="%(ENV_USER)s",DISPLAY="%(ENV_DISPLAY)s",XDG_RUNTIME_DIR="%(ENV_XDG_RUNTIME_DIR)s"
|
||||
stopsignal=INT
|
||||
stdout_logfile=/home/%(ENV_USER)s/.cache/log/sunshine.log
|
||||
stdout_logfile_maxbytes=10MB
|
||||
stdout_logfile_backups=7
|
||||
stderr_logfile=/home/%(ENV_USER)s/.cache/log/sunshine.err.log
|
||||
stderr_logfile_maxbytes=10MB
|
||||
stderr_logfile_backups=7
|
||||
45
overlay/usr/bin/start-sunshine.sh
Executable file
45
overlay/usr/bin/start-sunshine.sh
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
###
|
||||
# File: start-sunshine.sh
|
||||
# Project: bin
|
||||
# File Created: Tuesday, 4th October 2022 8:22:17 pm
|
||||
# Author: Josh.5 (jsunnex@gmail.com)
|
||||
# -----
|
||||
# Last Modified: Tuesday, 4th October 2022 8:22:17 pm
|
||||
# Modified By: Josh.5 (jsunnex@gmail.com)
|
||||
###
|
||||
|
||||
# CATCH TERM SIGNAL:
|
||||
_term() {
|
||||
kill -TERM "$sunshine_pid" 2>/dev/null
|
||||
}
|
||||
trap _term SIGTERM
|
||||
|
||||
|
||||
# CONFIGURE:
|
||||
# TODO: Install default configurations
|
||||
# Reset the default username/password
|
||||
if ([ "X${SUNSHINE_USER:-}" != "X" ] && [ "X${SUNSHINE_PASS:-}" != "X" ]); then
|
||||
sunshine /home/${USER}/sunshine/sunshine.conf --creds ${SUNSHINE_USER:-} ${SUNSHINE_PASS:-}
|
||||
fi
|
||||
|
||||
|
||||
# EXECUTE PROCESS:
|
||||
# Wait for X server to start
|
||||
# (Credit: https://gist.github.com/tullmann/476cc71169295d5c3fe6)
|
||||
MAX=60 # About 30 seconds
|
||||
CT=0
|
||||
while ! xdpyinfo >/dev/null 2>&1; do
|
||||
sleep 0.50s
|
||||
CT=$(( CT + 1 ))
|
||||
if [ "$CT" -ge "$MAX" ]; then
|
||||
LOG "FATAL: $0: Gave up waiting for X server $DISPLAY"
|
||||
exit 11
|
||||
fi
|
||||
done
|
||||
sunshine min_log_level=info /home/${USER}/sunshine/sunshine.conf &
|
||||
sunshine_pid=$!
|
||||
|
||||
|
||||
# WAIT FOR CHILD PROCESS:
|
||||
wait "$sunshine_pid"
|
||||
Reference in New Issue
Block a user