Skip to content

Instantly share code, notes, and snippets.

@jurgonaut
Forked from the-frey/pid_wrapper_docker.sh
Last active May 21, 2018 12:33
Show Gist options
  • Save jurgonaut/6d485c3ffce7c067c39f3b924c97c214 to your computer and use it in GitHub Desktop.
Save jurgonaut/6d485c3ffce7c067c39f3b924c97c214 to your computer and use it in GitHub Desktop.
PID Wrapper for Docker and Monit
#!/bin/bash
# First, create a folder: /var/run/monit
# Then, make sure your user or group owns it: chown user:user /var/run/monit
# USAGE:
# use option one to start or stop
# use option two as the docker name
# use option three as the docker run command it follows '-d' f you are starting a container
#
# Example:
# $ ./monit_docker_wrapper.sh start my-name "-p 80:80 ubuntu true"
#
# I would then expect to find /var/run/monit/my-name-docker-container.pid
case $1 in
start)
sudo rm /var/run/monit/$2-docker-container.pid;
sudo docker run --name $2 -d $3
sudo docker inspect --format '{{.State.Pid}}' $2 >> /var/run/$2-docker-container.pid
;;
stop)
sudo docker stop $2
sudo rm /var/run/monit/$2-docker-container.pid;
;;
*)
echo "usage: {start|stop} [name] [docker run command]" ;;
esac
exit 0
# This is adapted from the Monit examples. License: MIT.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment