diff --git a/Dockerfile b/Dockerfile index 88aa9f7593..c3f44afd78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,9 @@ RUN apt-get update \ && apt-get update \ && apt-get install -y transmission-cli transmission-common transmission-daemon \ && apt-get install -y openvpn curl rar unrar zip unzip \ + && curl -sLO https://github.com/Yelp/dumb-init/releases/download/v1.0.1/dumb-init_1.0.1_amd64.deb \ + && dpkg -i dumb-init_*.deb \ + && rm -rf dumb-init_*.deb \ && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ && curl -L https://github.com/jwilder/dockerize/releases/download/v0.0.2/dockerize-linux-amd64-v0.0.2.tar.gz | tar -C /usr/local/bin -xzv @@ -101,4 +104,4 @@ ENV OPENVPN_USERNAME=**None** \ # Expose port and run EXPOSE 9091 -CMD ["/etc/openvpn/start.sh"] +CMD ["dumb-init", "/etc/openvpn/start.sh"] diff --git a/README.md b/README.md index ceb8c9a99d..c2936eaf43 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,64 @@ If you have transmission authentication enabled and want scripts in another cont control the transmission-daemon, this can be a handy way to access the credentials. For example, another container may pause or restrict transmission speeds while the server is streaming video. +## systemd Integration + +On many modern linux systems, including Ubuntu, systemd can be used to start the transmission-openvpn at boot time, and restart it after any failure. + +Save the following as `/etc/systemd/system/transmission-openvpn.service`, and replace the OpenVPN PROVIDER/USERNAME/PASSWORD directives with your settings, and add any other directives that you're using. + +This service is assuming that there is a `bittorrent` user set up with a home directory at `/home/bittorrent/`. The data directory will be mounted at `/home/bittorrent/data/`. This can be changed to whichever user and location you're using. + +OpenVPN is set to exit if there is a connection failure. OpenVPN exiting triggers the container to also exit, then the `Restart=always` definition in the `transmission-openvpn.service` file tells systems to restart things again. + +``` +[Unit] +Description=haugene/transmission-openvpn docker container +After=docker.service +Requires=docker.service + +[Service] +User=bittorrent +TimeoutStartSec=0 +ExecStartPre=-/usr/bin/docker kill transmission-openvpn +ExecStartPre=-/usr/bin/docker rm transmission-openvpn +ExecStartPre=/usr/bin/docker pull haugene/transmission-openvpn +ExecStart=/usr/bin/docker run \ + --name transmission-openvpn \ + --privileged \ + -v /home/bittorrent/data/:/data \ + -e "OPENVPN_PROVIDER=TORGUARD" \ + -e "OPENVPN_USERNAME=bittorrent@example.com" \ + -e "OPENVPN_PASSWORD=hunter2" \ + -e "OPENVPN_CONFIG=Netherlands" \ + -e "OPENVPN_OPTS=--inactive 3600 --ping 10 --ping-exit 60" \ + -e "TRANSMISSION_UMASK=0" \ + -p 9091:9091 \ + --dns 8.8.8.8 \ + --dns 8.8.4.4 \ + haugene/transmission-openvpn +Restart=always +RestartSec=5 + +[Install] +WantedBy=multi-user.target +``` + +Then enable and start the new service with: + +``` +$ sudo systemctl enable /etc/systemd/system/transmission-openvpn.service +$ sudo systemctl restart transmission-openvpn.service +``` + +If it is stopped or killed in any fashion, systemd will restart the container. If you do want to shut it down, then run the following command and it will stay down until you restart it. + +``` +$ sudo systemctl stop transmission-openvpn.service +# Later ... +$ sudo systemctl start transmission-openvpn.service +``` + ## Make it work on Synology NAS Here are the steps to run it on a Synology NAS (Tested on DSM 6) :