Created
November 11, 2015 22:51
-
-
Save jjam3774/06a88a3eb06f6fb94797 to your computer and use it in GitHub Desktop.
This monitors docker containers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# chkconfig: 2345 95 20 | |
# description: This will closely monitor the centro docker containers. | |
# processname: monitor_containers | |
e = `pgrep monitor_cont`.strip.to_i | |
count = 0 | |
IO.popen('ps -ef | grep monitor_containers | grep -v grep').each{|i| | |
count = count.next | |
if count > 1 | |
case ARGV.first | |
when 'status' | |
puts '---------' | |
when 'stop' | |
puts "+++++++++" | |
when 'start' | |
puts "Another monitor process is running.. exiting.." | |
exit 0 | |
end | |
end | |
} | |
case ARGV.first | |
when 'stop' | |
# Killing the process | |
puts "Killing.. " + e.to_s | |
Process.kill("HUP", e) | |
when 'start' | |
puts "Monitoring Centro Containers.." | |
Process.daemon # Anything Past This will be daemoized..... | |
loop{ | |
if `docker ps | grep mysql`.empty? | |
if `docker ps | grep jboss`.empty? | |
IO.popen('docker-compose -f /kube_yamls/docker-compose.yml up -d').each{|o| | |
puts o | |
} | |
end | |
IO.popen('docker-compose -f /kube_yamls/docker-compose.yml stop;docker-compose -f /kube_yamls/docker-compose.yml up -d').each{|o| | |
puts o | |
} | |
end | |
if `docker ps | grep jboss`.empty? | |
if `docker ps | grep mysql`.empty? | |
IO.popen('docker-compose -f /kube_yamls/docker-compose.yml up -d').each{|o| | |
puts o | |
} | |
end | |
IO.popen('docker-compose -f /kube_yamls/docker-compose.yml stop;docker-compose -f /kube_yamls/docker-compose.yml up -d').each{|o| | |
puts o | |
} | |
end | |
sleep 15 | |
} | |
when 'status' | |
IO.popen('docker-compose -f /kube_yamls/docker-compose.yml ps').each{|i| | |
puts i | |
} | |
else | |
puts "usage: | |
monitor_containers.rb start TO START MONITORING DOCKER CONTAINERS | |
monitor_containers.rb stop TO STOP MONITORING THE DOCKER CONTAINERS | |
monitor_containers.rb status TO GET A STATUS OF THE DOCKER CONTAINERS" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment