Skip to content

Instantly share code, notes, and snippets.

@the-frey
Last active May 21, 2018 12:13
Show Gist options
  • Save the-frey/742e47bcefc0258ee414 to your computer and use it in GitHub Desktop.
Save the-frey/742e47bcefc0258ee414 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 echo $$ > /var/run/monit/$2-docker-container.pid;
sudo docker run --name $2 -d $3
;;
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