Skip to content

Commit 34c4ef4

Browse files
committed
more emulatorjs fixes
1 parent 6c44f0b commit 34c4ef4

3 files changed

Lines changed: 60 additions & 45 deletions

File tree

porting/emulatorjs/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ RUN \
110110
apt-get install -y --no-install-recommends \
111111
file \
112112
flac \
113+
libcap2-bin \
113114
nginx \
114115
nodejs \
115116
p7zip-full \
@@ -118,6 +119,8 @@ RUN \
118119
apt-get install -y --no-install-recommends \
119120
mame-tools && \
120121
mkdir -p /data && \
122+
echo "**** allow non-root nginx to bind low ports ****" && \
123+
setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx && \
121124
echo "**** cleanup ****" && \
122125
rm -rf \
123126
/tmp/* && \

porting/emulatorjs/root/etc/nginx/nginx.conf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
user apps;
21
worker_processes 4;
3-
pid /run/nginx.pid;
2+
pid /tmp/nginx/nginx.pid;
43
include /etc/nginx/modules/*.conf;
54

65
events {
76
worker_connections 768;
87
}
98

109
http {
10+
client_body_temp_path /tmp/nginx/client_body;
11+
proxy_temp_path /tmp/nginx/proxy;
12+
fastcgi_temp_path /tmp/nginx/fastcgi;
13+
uwsgi_temp_path /tmp/nginx/uwsgi;
14+
scgi_temp_path /tmp/nginx/scgi;
15+
access_log /dev/stdout;
16+
error_log /dev/stderr;
1117
disable_symlinks off;
1218
sendfile on;
1319
tcp_nopush on;

porting/emulatorjs/start.sh

100755100644
Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,80 @@
11
#!/usr/bin/env bash
2+
set -u
23

3-
4-
# check if ipfs is disabled
4+
# ---- ipfs (optional) -------------------------------------------------------
55
if [[ -z ${DISABLE_IPFS+x} ]] && command -v ipfs >/dev/null 2>&1; then
6-
7-
# ipfs migrate check on startup
86
if [[ -d "/data/.ipfs" ]]; then
97
echo "[ipfs-upgrade] Checking if fs-repo needs to be upgraded (this may take some time)"
10-
HOME=/data /usr/bin/fs-repo-migrations -y -to 15
8+
HOME=/data /usr/bin/fs-repo-migrations -y -to 15 || true
119
fi
12-
13-
# ipfs config
1410
if [[ ! -d "/data/.ipfs" ]]; then
15-
HOME=/data ipfs init --profile lowpower
11+
HOME=/data ipfs init --profile lowpower || true
1612
fi
1713
fi
1814

19-
# link user data to frontend
20-
if [[ -w '/emulatorjs/frontend' ]] && [[ ! -L '/emulatorjs/frontend/user' ]]; then
15+
# ---- frontend user data link ----------------------------------------------
16+
if [[ -w /emulatorjs/frontend ]] && [[ ! -L /emulatorjs/frontend/user ]]; then
2117
ln -s /data /emulatorjs/frontend/user
2218
fi
2319

24-
# Default profile directory
25-
if [[ ! -d '/config/profile/default' ]]; then
20+
# ---- /config seeding -------------------------------------------------------
21+
if [[ ! -d /config/profile/default ]]; then
2622
mkdir -p /config/profile/default
27-
echo "input_menu_toggle_gamepad_combo = 3
28-
system_directory = /home/web_user/retroarch/system/" >/config/profile/default/retroarch.cfg
29-
23+
cat >/config/profile/default/retroarch.cfg <<EOF
24+
input_menu_toggle_gamepad_combo = 3
25+
system_directory = /home/web_user/retroarch/system/
26+
EOF
3027
fi
31-
if [[ ! -f '/config/profile/profile.json' ]]; then
28+
if [[ ! -f /config/profile/profile.json ]]; then
3229
echo '{}' >/config/profile/profile.json
33-
3430
fi
3531

36-
# nginx mime types
37-
if [[ -w /etc/nginx ]]; then
32+
# ---- nginx writable dirs (read-only-rootfs friendly) -----------------------
33+
mkdir -p /tmp/nginx/client_body /tmp/nginx/proxy /tmp/nginx/fastcgi \
34+
/tmp/nginx/uwsgi /tmp/nginx/scgi
35+
if [[ -w /etc/nginx ]] && [[ -f /defaults/mime.types ]]; then
3836
cp /defaults/mime.types /etc/nginx/mime.types
3937
fi
4038

41-
# allow users to mount in ro rom dirs
42-
DIRS='3do atari2600 atari5200 atari7800 colecovision doom gba lynx n64 nes odyssey2 psx segaCD segaMD segaSaturn snes vb ws arcade atari5200 gb gbc jaguar msx nds ngp pce sega32x segaGG segaMS segaSG vectrex'
39+
# ---- bind-mount roms into /data -------------------------------------------
40+
DIRS='3do atari2600 atari5200 atari7800 colecovision doom gba lynx n64 nes odyssey2 psx segaCD segaMD segaSaturn snes vb ws arcade gb gbc jaguar msx nds ngp pce sega32x segaGG segaMS segaSG vectrex'
4341
for DIR in ${DIRS}; do
4442
if [[ -d "/roms/${DIR}" ]] && [[ ! -L "/data/${DIR}/roms" ]]; then
4543
mkdir -p "/data/${DIR}"
4644
ln -s "/roms/${DIR}" "/data/${DIR}/roms"
47-
4845
fi
4946
done
5047

51-
cd /emulatorjs
52-
## Config?
53-
HOME=/data
54-
exec node index.js
55-
56-
if [ ! -z ${DISABLE_IPFS+x} ]; then
57-
sleep infinity
58-
fi
59-
60-
## Why?
61-
exec ipfs daemon
62-
63-
64-
if pgrep -f "[n]ginx:" > /dev/null; then
65-
pkill -ef [n]ginx:
48+
# ---- supervisor ------------------------------------------------------------
49+
PIDS=()
50+
shutdown() {
51+
trap - TERM INT
52+
for pid in "${PIDS[@]}"; do
53+
kill -TERM "$pid" 2>/dev/null || true
54+
done
55+
wait
56+
exit 0
57+
}
58+
trap shutdown TERM INT
59+
60+
# nginx (foreground via daemon off in nginx.conf)
61+
/usr/sbin/nginx -c /etc/nginx/nginx.conf &
62+
PIDS+=($!)
63+
64+
# profile service
65+
( cd /emulatorjs && HOME=/config exec node profile.js ) &
66+
PIDS+=($!)
67+
68+
# optional ipfs daemon
69+
if [[ -z ${DISABLE_IPFS+x} ]] && command -v ipfs >/dev/null 2>&1; then
70+
HOME=/data ipfs daemon &
71+
PIDS+=($!)
6672
fi
6773

68-
## TODO: Needs to be another container entirely
69-
exec /usr/sbin/nginx -c /etc/nginx/nginx.conf
74+
# main frontend service
75+
( cd /emulatorjs && HOME=/data exec node index.js ) &
76+
PIDS+=($!)
7077

71-
cd /emulatorjs
72-
HOME=/config
73-
## TODO: What to do with this?
74-
exec node profile.js
78+
# exit when any child exits, then propagate shutdown to remaining children
79+
wait -n
80+
shutdown

0 commit comments

Comments
 (0)