From 289b35a6b59701a2dcd6dccfd569494741f97b85 Mon Sep 17 00:00:00 2001 From: Dave Webb Date: Fri, 13 May 2016 20:44:56 +1200 Subject: [PATCH 1/4] Add systemd integration notes to README --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/README.md b/README.md index ceb8c9a99..adb87e514 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,54 @@ 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`. + +It's 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/`, and 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 +``` + ## Make it work on Synology NAS Here are the steps to run it on a Synology NAS (Tested on DSM 6) : From 09c978fc9b528c36d86f3a45e183e1f580104e6b Mon Sep 17 00:00:00 2001 From: Dave Webb Date: Fri, 13 May 2016 20:54:07 +1200 Subject: [PATCH 2/4] Attempt to prevent zombie processes when run under systemd When systemd restarts the transmission-openvpn container, it seems to leave zombie processes as below. $ ps uaxww | grep Z root 1872 0.0 0.0 0 0 ? Z 08:58 0:00 [transmission-da] The zombies do appear to be cleaned up by restarting docker itself, or by stopping the transmission-openvpn service. This is an attempt to prevent zombies being spawned via Yelp's dumb-init, which correctly handles the signals that PID1 gets. See: https://github.com/Yelp/dumb-init --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 88aa9f759..c3f44afd7 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"] From 1b357bf02e03abf60a3717b252c4b9c683caee81 Mon Sep 17 00:00:00 2001 From: Dave Webb Date: Fri, 13 May 2016 21:04:59 +1200 Subject: [PATCH 3/4] Further README notes for systemd --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index adb87e514..1649d4eb5 100644 --- a/README.md +++ b/README.md @@ -174,9 +174,11 @@ For example, another container may pause or restrict transmission speeds while t 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`. +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. -It's 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/`, and 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. +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] From 71f7f9ce49d23c267281d3d36530f6bb758a839d Mon Sep 17 00:00:00 2001 From: Dave Webb Date: Fri, 13 May 2016 21:17:25 +1200 Subject: [PATCH 4/4] Add systemd stop command to README --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 1649d4eb5..c2936eaf4 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,14 @@ $ 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) :