crazy-max / docker-rtorrent-rutorrent

rTorrent and ruTorrent Docker image
MIT License
457 stars 103 forks source link

Custom Init script #249

Open tigerkzr opened 1 year ago

tigerkzr commented 1 year ago

Is there a way of running a custom init script at container start?

the gist: At container startup, set a default route within the torrent container so that traffic goes through through my VPN container that uses IP masquerade. (I am avoiding setting the network mode to container or service)

how I normally accomplish this: Using linuxserver images, one can just mount a script into the container at ./script/dir:/custom-init-script.d and the container will run every script there at startup

What I have tried: mount script into cont-init: ./script.sh:/etc/cont-init.d/99-script.sh result: Container starts but script fails Command line is not complete. Try option "help" /var/run/s6/etc/cont-init.d/99-script.sh: line 7: curl: command not found

mount script directory into container and use command in docker compose 'command: /script/dir/script.sh result: Script works but the container goes on a restart/terminate loop.

I can run the script after container startup using docker exec, and it works, but this doesn't persist between restarts.

script I am trying to run(env vars are passed via docker compose environment:):

#!/bin/bash

ip route del default
ip route add default via ${VPN_CONT_IP}
ip route add ${HOST_LAN:-10.0.1.0/24} via 10.0.10.1

wanip=$(curl icanhazip.com)

echo "##############################################################"
echo "# Now routing through ${VPN_CONT_IP} to WAN IP $wanip. #"
echo "##############################################################"

any suggestions on how I can accomplish this are greatly appreciated

gnammix commented 11 months ago

Similar issue here, would like to set WAN and incoming port at container startup. I could probably achieve that by running a script at startup.

trunet commented 8 months ago

I agree that this should be done properly, but mounting a shell script into /etc/cont-init.d worked fine for me. Try to add the full path to the curl command like /usr/local/bin/curl, it's possible that the s6-init is not appending all the known bin locations on PATH environment variable.