Skip to content

Instantly share code, notes, and snippets.

@lightrush
Last active July 24, 2023 11:53
Show Gist options
  • Select an option

  • Save lightrush/c08b5e7749ba9ca20c3c8bdc5a66acef to your computer and use it in GitHub Desktop.

Select an option

Save lightrush/c08b5e7749ba9ca20c3c8bdc5a66acef to your computer and use it in GitHub Desktop.

Revisions

  1. lightrush revised this gist Nov 4, 2017. 3 changed files with 19 additions and 4 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -6,9 +6,11 @@ Fill in the blanks in `plex-docker-run.sh`, `plex-docker.service`, optionally `m
    ```
    sudo [Path to]/plex-docker-run.sh
    sudo cp [Path to]/plex-docker.service /etc/systemd/system/
    sudo cp [Path to]/network-internet.service /etc/systemd/system/
    # Optionally
    # sudo cp [Path to]/mount-remote-volume.service /etc/systemd/system/
    sudo systemctl daemon-reload
    sudo systemctl enable network-internet.service
    sudo systemctl enable plex-docker.service
    # Optionally
    # sudo systemctl enable mount-remote-volume.service
    16 changes: 16 additions & 0 deletions network-internet.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # This Systemd unit waits indefinitely for internet connection
    ## It's useful for starting other services after internet connection is established.
    ## Internet connection being established means being able to reach 8.8.8.8 and
    ## being able to resolve google.com using 8.8.8.8 as DNS.
    [Unit]
    Description=Wait for internet connection
    After=network-online.target

    [Service]
    Type=oneshot
    ExecStart=/bin/bash -c 'while ! nslookup google.com 8.8.8.8 &> /dev/null ; do echo No internet connection. Waiting... ; sleep 10 ; done'
    RemainAfterExit=yes
    TimeoutSec=infinity

    [Install]
    WantedBy=multi-user.target
    5 changes: 1 addition & 4 deletions plex-docker.service
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    [Unit]
    Description=Plex
    Requires=docker.service
    After=network-online.target docker.service
    After=network-internet.service docker.service
    # Put any local media locations below. If you put remote media volumes that may fail to mount before this service
    # starts, those will become a failed dependency for the service and Plex won't start. Therefore remote
    # media volumes are better mounted with oneshot services like mount-remote-volume.service provided in this gist.
    @@ -10,9 +10,6 @@ After=network-online.target docker.service

    [Service]
    Restart=always
    # Ensure plex.tv is resolvable when the server starts so that remote registration succeeds.
    ExecStartPre=/bin/bash -c 'while ! nslookup plex.tv 8.8.8.8 &> /dev/null ; do echo Cannot resolve plex.tv. Waiting... ; done'
    TimeoutSec=infinity
    ExecStart=/usr/bin/docker start -a plex
    ExecStop=/usr/bin/docker stop -t 2 plex

  2. lightrush revised this gist Nov 4, 2017. 3 changed files with 5 additions and 5 deletions.
    6 changes: 3 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,14 @@

    ## Docker run script and Systemd unit files for setting up Plex using the official image by Plex Inc

    Fill in the blanks in `plex-docker-run.sh`, `plex-docker.service`, optionally `mount-volume-wait.service` and save them. Then:
    Fill in the blanks in `plex-docker-run.sh`, `plex-docker.service`, optionally `mount-remote-volume.service` and save them. Then:
    ```
    sudo [Path to]/plex-docker-run.sh
    sudo cp [Path to]/plex-docker.service /etc/systemd/system/
    # Optionally
    # sudo cp [Path to]/mount-volume-wait.service /etc/systemd/system/
    # sudo cp [Path to]/mount-remote-volume.service /etc/systemd/system/
    sudo systemctl daemon-reload
    sudo systemctl enable plex-docker.service
    # Optionally
    # sudo systemctl enable mount-volume-wait.service
    # sudo systemctl enable mount-remote-volume.service
    ```
    4 changes: 2 additions & 2 deletions plex-docker.service
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,8 @@ Requires=docker.service
    After=network-online.target docker.service
    # Put any local media locations below. If you put remote media volumes that may fail to mount before this service
    # starts, those will become a failed dependency for the service and Plex won't start. Therefore remote
    # media volumes are better mounted with oneshot services like mount-volume-wait.service provided below.
    # If you use one or more mount-volume-wait.service units, you should add them to the After directive above.
    # media volumes are better mounted with oneshot services like mount-remote-volume.service provided in this gist.
    # If you use one or more mount-remote-volume.service units, you should add them to the After directive above.
    # RequiresMountsFor=[Path to your media on host machine e.g. /media/somedisk/music] [Path to your media on host machine e.g. /media/someotherdisk/music]

    [Service]
  3. lightrush renamed this gist Nov 4, 2017. 1 changed file with 2 additions and 2 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # This Systemd unit waits indefinitely for a volume to mount
    # This Systemd unit waits indefinitely for a remote volume to mount
    ## It's useful for mounting remote volumes and starting other services after mounting succeeds
    [Unit]
    Description=Mount remote media volume
    Description=Mount remote volume
    After=network-online.target

    [Service]
  4. lightrush revised this gist Nov 4, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions plex-docker.service
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,8 @@ Requires=docker.service
    After=network-online.target docker.service
    # Put any local media locations below. If you put remote media volumes that may fail to mount before this service
    # starts, those will become a failed dependency for the service and Plex won't start. Therefore remote
    # media volumes are better mounted with oneshot services like `mount-volume-wait.service` provided below.
    # If you use one or more `mount-volume-wait.service` units, you should add them to the `After` directive above.
    # media volumes are better mounted with oneshot services like mount-volume-wait.service provided below.
    # If you use one or more mount-volume-wait.service units, you should add them to the After directive above.
    # RequiresMountsFor=[Path to your media on host machine e.g. /media/somedisk/music] [Path to your media on host machine e.g. /media/someotherdisk/music]

    [Service]
  5. lightrush revised this gist Nov 4, 2017. 3 changed files with 13 additions and 8 deletions.
    8 changes: 6 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,15 @@
    # Setup Plex with Docker

    ## Docker run script and Systemd unit file for setting up Plex using the official image by Plex Inc
    ## Docker run script and Systemd unit files for setting up Plex using the official image by Plex Inc

    Fill in the blanks in `plex-docker-run.sh`, `plex-docker.service` and save them. Then:
    Fill in the blanks in `plex-docker-run.sh`, `plex-docker.service`, optionally `mount-volume-wait.service` and save them. Then:
    ```
    sudo [Path to]/plex-docker-run.sh
    sudo cp [Path to]/plex-docker.service /etc/systemd/system/
    # Optionally
    # sudo cp [Path to]/mount-volume-wait.service /etc/systemd/system/
    sudo systemctl daemon-reload
    sudo systemctl enable plex-docker.service
    # Optionally
    # sudo systemctl enable mount-volume-wait.service
    ```
    5 changes: 3 additions & 2 deletions remote-media-volume-0.service → mount-volume-wait.service
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    # This Systemd unit waits indefinitely for a remote media volume to mount
    # This Systemd unit waits indefinitely for a volume to mount
    ## It's useful for mounting remote volumes and starting other services after mounting succeeds
    [Unit]
    Description=Remote media volume 0
    Description=Mount remote media volume
    After=network-online.target

    [Service]
    8 changes: 4 additions & 4 deletions plex-docker.service
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,10 @@
    Description=Plex
    Requires=docker.service
    After=network-online.target docker.service
    # Put any local media locations below. If you put remote media volumes that fail to mount on boot
    # this will become a failed dependency for the service and Plex won't start. Therefore remote
    # media volumes are better mounted with oneshot services like remote-media-volume-0.service.
    # If you use such services, you probably want to add them to the After directive above.
    # Put any local media locations below. If you put remote media volumes that may fail to mount before this service
    # starts, those will become a failed dependency for the service and Plex won't start. Therefore remote
    # media volumes are better mounted with oneshot services like `mount-volume-wait.service` provided below.
    # If you use one or more `mount-volume-wait.service` units, you should add them to the `After` directive above.
    # RequiresMountsFor=[Path to your media on host machine e.g. /media/somedisk/music] [Path to your media on host machine e.g. /media/someotherdisk/music]

    [Service]
  6. lightrush revised this gist Nov 4, 2017. 2 changed files with 18 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions plex-docker.service
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,11 @@
    Description=Plex
    Requires=docker.service
    After=network-online.target docker.service
    # Put any media locations below.
    # RequiresMountsFor=[path to your media on host machine e.g. /media/somedisk/music] [path to your media on host machine e.g. /media/someotherdisk/music]
    # Put any local media locations below. If you put remote media volumes that fail to mount on boot
    # this will become a failed dependency for the service and Plex won't start. Therefore remote
    # media volumes are better mounted with oneshot services like remote-media-volume-0.service.
    # If you use such services, you probably want to add them to the After directive above.
    # RequiresMountsFor=[Path to your media on host machine e.g. /media/somedisk/music] [Path to your media on host machine e.g. /media/someotherdisk/music]

    [Service]
    Restart=always
    13 changes: 13 additions & 0 deletions remote-media-volume-0.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    # This Systemd unit waits indefinitely for a remote media volume to mount
    [Unit]
    Description=Remote media volume 0
    After=network-online.target

    [Service]
    Type=oneshot
    ExecStart=/bin/bash -c 'while ! [Your mount command here. E.g. mount -t cifs //someserver/someshare /media/someshare] &> /dev/null ; do echo Cannot mount share. Retrying... ; sleep 10 ; done'
    RemainAfterExit=yes
    TimeoutSec=infinity

    [Install]
    WantedBy=multi-user.target
  7. lightrush revised this gist Nov 4, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Setup Plex with Docker

    ## Docker run script and Systemd unit file for setting up Plex using the official Docker image by Plex Inc
    ## Docker run script and Systemd unit file for setting up Plex using the official image by Plex Inc

    Fill in the blanks in `plex-docker-run.sh`, `plex-docker.service` and save them. Then:
    ```
  8. lightrush revised this gist Nov 4, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    # Setup Plex with Docker

    ## This gist sets up Plex Media Server using the official Docker image by Plex
    ## Docker run script and Systemd unit file for setting up Plex using the official Docker image by Plex Inc

    Fill in the blanks in plex-docker-run.sh and save it. Then:
    Fill in the blanks in `plex-docker-run.sh`, `plex-docker.service` and save them. Then:
    ```
    sudo [Path to]/plex-docker-run.sh
    sudo cp [Path to]/plex-docker.service /etc/systemd/system/
  9. lightrush revised this gist Nov 4, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,8 @@

    Fill in the blanks in plex-docker-run.sh and save it. Then:
    ```
    sudo [path to]/plex-docker-run.sh
    sudo cp [path to]/plex-docker.service /etc/systemd/system/
    sudo [Path to]/plex-docker-run.sh
    sudo cp [Path to]/plex-docker.service /etc/systemd/system/
    sudo systemctl daemon-reload
    sudo systemctl enable plex-docker.service
    ```
  10. lightrush revised this gist Nov 4, 2017. 2 changed files with 13 additions and 4 deletions.
    14 changes: 10 additions & 4 deletions plex-docker-run.sh
    Original file line number Diff line number Diff line change
    @@ -5,10 +5,16 @@ docker run \
    --name plex \
    --net=host \
    -e TZ="US/Eastern" \
    -e PLEX_CLAIM="[Go to https://www.plex.tv/claim/ and copy the token here. Do this last since you have 4 minutes to use each token.]" \
    `# Go to https://www.plex.tv/claim/ and copy a token from there.` \
    `# Do this last since you have 4 minutes to use each token and container creation can take time.` \
    -e PLEX_CLAIM="[Plex claim token]" \
    -e PLEX_GID="[The GID that can access your media]" \
    -e PLEX_UID="[The UID that can access your media]" \
    -v "/home/lightrush/opt/plex/config:/config" \
    # Make sure the locations below are mounted before the container starts. Putting them in /etc/fstab works well. Repeat the line for all the media locations you have.
    -v "[path to your media on host machine e.g. /media/somedisk/music]:[path to your media in container e.g. /media/somedisk/music]" \
    -v "[Path to your Plex database on host machine. This is specified so that your Plex database survives container recreation. E.g. /opt/plex/config]:/config" \
    `# Make sure the locations below are mounted before the container starts. Putting them in /etc/fstab works well.` \
    `# There's a mount dependency in the Systemd unit file where you should probably add them.` \
    `# Repeat for all the media locations you have.` \
    -v "[Path to your media on host machine. E.g. /media/somedisk/music]:[Path to your media in container. E.g. /media/somedisk/music]" \
    `# This is the image used for your container.` \
    `# If you don't have plexpass, you should change the image tag from ":plexpass" to ":latest".` \
    plexinc/pms-docker:plexpass
    3 changes: 3 additions & 0 deletions plex-docker.service
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,12 @@
    Description=Plex
    Requires=docker.service
    After=network-online.target docker.service
    # Put any media locations below.
    # RequiresMountsFor=[path to your media on host machine e.g. /media/somedisk/music] [path to your media on host machine e.g. /media/someotherdisk/music]

    [Service]
    Restart=always
    # Ensure plex.tv is resolvable when the server starts so that remote registration succeeds.
    ExecStartPre=/bin/bash -c 'while ! nslookup plex.tv 8.8.8.8 &> /dev/null ; do echo Cannot resolve plex.tv. Waiting... ; done'
    TimeoutSec=infinity
    ExecStart=/usr/bin/docker start -a plex
  11. lightrush created this gist Nov 3, 2017.
    10 changes: 10 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    # Setup Plex with Docker

    ## This gist sets up Plex Media Server using the official Docker image by Plex

    Fill in the blanks in plex-docker-run.sh and save it. Then:
    ```
    sudo [path to]/plex-docker-run.sh
    sudo cp [path to]/plex-docker.service /etc/systemd/system/
    sudo systemctl enable plex-docker.service
    ```
    14 changes: 14 additions & 0 deletions plex-docker-run.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!/bin/bash

    docker run \
    -d \
    --name plex \
    --net=host \
    -e TZ="US/Eastern" \
    -e PLEX_CLAIM="[Go to https://www.plex.tv/claim/ and copy the token here. Do this last since you have 4 minutes to use each token.]" \
    -e PLEX_GID="[The GID that can access your media]" \
    -e PLEX_UID="[The UID that can access your media]" \
    -v "/home/lightrush/opt/plex/config:/config" \
    # Make sure the locations below are mounted before the container starts. Putting them in /etc/fstab works well. Repeat the line for all the media locations you have.
    -v "[path to your media on host machine e.g. /media/somedisk/music]:[path to your media in container e.g. /media/somedisk/music]" \
    plexinc/pms-docker:plexpass
    14 changes: 14 additions & 0 deletions plex-docker.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    [Unit]
    Description=Plex
    Requires=docker.service
    After=network-online.target docker.service

    [Service]
    Restart=always
    ExecStartPre=/bin/bash -c 'while ! nslookup plex.tv 8.8.8.8 &> /dev/null ; do echo Cannot resolve plex.tv. Waiting... ; done'
    TimeoutSec=infinity
    ExecStart=/usr/bin/docker start -a plex
    ExecStop=/usr/bin/docker stop -t 2 plex

    [Install]
    WantedBy=multi-user.target