Skip to content

Instantly share code, notes, and snippets.

@JigSawFr
Created September 13, 2016 17:32
Show Gist options
  • Save JigSawFr/70d7f95f16f1f6f27528a18e183ee67c to your computer and use it in GitHub Desktop.
Save JigSawFr/70d7f95f16f1f6f27528a18e183ee67c to your computer and use it in GitHub Desktop.
PlexPy - Plex Docker Container Restart with Rancher
#!/bin/sh
# ############# PLEX DOCKER CONTAINER RESTART WITH RANCHER ############# #
# ###################################################################### #
# Written by JigSawFr <https://github.com/JigSawFr> #
# ###################################################################### #
# With this script, you can restart your plex container when an update is available, or if plex seems down.
# 1. You need to have installed Rancher Management Server (see: https://github.com/rancher/rancher#installation)
# 2. You need to have added an host in your Management Interface (Infrastructure -> Host -> Add host)
# 3. You need to create an API access to your environnement (API)
# 4. Report your ACCESS_KEY, SECRET_KEY, ENDPOINT and PLEX_CONTAINER in vars.
# 5. Enable this script on PlexPy and you're fine !
RANCHER_ACCESS_KEY=""
RANCHER_SECRET_KEY=""
RANCHER_ENDPOINT="" # Example: http://www.my-server.fr:8080/v1/projects/1a5
RANCHER_PLEX_CONTAINER="" # Example: 1i32
# ###################################################################### #
# #################### DON'T TOUCH AFTER THIS LINE #################### #
# ###################################################################### #
curl -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{}' \
'${RANCHER_ENDPOINT}/containers/${RANCHER_PLEX_CONTAINER}/?action=restart'
@TopperBG
Copy link

You can do it w/o 3d party managers:

curl -X POST --unix-socket /var/run/docker.sock -H "Content-Type: application/json" "http:/v1.41/containers/create?name=my-container" -d '{
  "Image": "linuxserver/my-image",
  "Cmd": ["--cmd", "--run", "-o", "--more-options"],
  "HostConfig": {
    "Binds": ["/opt/my-container/config:/config"],
    "AutoRemove": true
  }
}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment