linuxserver / docker-emulatorjs

Web based retro emulation frontend with rom scanning and automated art ingestion.
GNU General Public License v3.0
509 stars 51 forks source link

[BUG] Boot sequence, IPFS before custom-cont-init.d #53

Closed hulkhaugen closed 7 months ago

hulkhaugen commented 8 months ago

Is there an existing issue for this?

Current Behavior

I'm trying to add a custom script to this container, but I'm facing some challenges. I'm very limited in this field, but it seems to me that the script(s) in custom-cont-init.d are ran after some IPFS related stuff. The issue for me personally is that I want to remove /data and make a symlink from a variable, let's say /share/emulatorjs to /data. I'm doing this for a Home Assistant Add-on, so I'm somewhat limited from the usual approaches.

Maybe i'm approaching this wrong, I just want to be able to move the roms folders to /share.

Expected Behavior

Run script before anything else inside the container

Steps To Reproduce

Environment

- OS: HassOS
- How docker service was installed: Plain, only added said script

CPU architecture

arm64

Docker creation

ARG BUILD_VERSION
FROM lscr.io/linuxserver/emulatorjs:$BUILD_VERSION
# Add custom script
COPY rootfs / 

********************
* custom-script.sh *
********************

#!/bin/sh

# Read the target folder from /data/options.json
# Default value is /share/emulatorjs
TARGET_FOLDER=$(jq -r '.rom_folder' /data/options.json)

# Ensure the target folder is owned by root
mkdir -p "$TARGET_FOLDER"
chown root:root "$TARGET_FOLDER"

# Create a symlink from /data to the specified target folder
rm -rf /data
ln -s "$TARGET_FOLDER" /data

# Debugging: Print the current state
ls -la /data/

Container logs

[custom-init] No custom services found, skipping...
[migrations] started
[migrations] no migrations found
───────────────────────────────────────

      ██╗     ███████╗██╗ ██████╗ 
      ██║     ██╔════╝██║██╔═══██╗
      ██║     ███████╗██║██║   ██║
      ██║     ╚════██║██║██║   ██║
      ███████╗███████║██║╚██████╔╝
      ╚══════╝╚══════╝╚═╝ ╚═════╝ 

   Brought to you by linuxserver.io
───────────────────────────────────────

To support LSIO projects visit:
https://www.linuxserver.io/donate/

───────────────────────────────────────
GID/UID
───────────────────────────────────────

User UID:    0
User GID:    0
───────────────────────────────────────

generating ED25519 keypair...done
peer identity: 12D3KooWAEFs7wwHxD9PCRWTnwfi9KUbbqaQwNfpUpMHiMNXFFwK
initializing IPFS node at /data/.ipfs
to get started, enter:

    ipfs cat /ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/readme

[custom-init] Files found, executing
[custom-init] 01-custom-data-folder.sh: executing...
rm: cannot remove '/data': Resource busy
total 8
drwxr-xr-x 2 root root 4096 Dec 16 20:33 .
drwxr-xr-x 1 root root 4096 Dec 16 20:33 ..
lrwxrwxrwx 1 root root   17 Dec 16 20:33 emulatorjs -> /share/emulatorjs
[custom-init] 01-custom-data-folder.sh: exited 0
Initializing daemon...
Kubo version: 0.19.2
Repo version: 13
System version: arm64/linux
Golang version: go1.20.11
aptalca commented 8 months ago

If you want things to run before certain init scripts, then you'll have to inject proper s6 init steps. Take a look at this mod for instance, where it injects two separate init steps into different spots, one before package install and one after: https://github.com/linuxserver/docker-mods/tree/code-server-flutter