More commands.
This commit is contained in:
parent
bb0b5f7b6f
commit
ee25ee5fe1
13
_get_container.sh
Normal file
13
_get_container.sh
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
base=`realpath . --relative-to="/data/containers" | cut -d"/" -f1`
|
||||||
|
if [ "$base" = ".." -o "$base" = "." ]; then
|
||||||
|
echo "No container given and not within /data/containers"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
container="$base"
|
||||||
|
echo "Working on container $container."
|
||||||
|
else
|
||||||
|
container="$1"
|
||||||
|
fi
|
5
dbash
Executable file
5
dbash
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. $(dirname $0)/_get_container.sh
|
||||||
|
|
||||||
|
docker exec -it "$container" /bin/bash
|
9
dhelp
Executable file
9
dhelp
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
echo "Docker-Tools"
|
||||||
|
echo
|
||||||
|
echo "dps - Shows a tabular list of running containers."
|
||||||
|
echo "dlogs - Show latest log entries of container."
|
||||||
|
echo "dlogsl - Shows latest log entries using less."
|
||||||
|
echo "dup - Creates and runs containers from YAML files."
|
||||||
|
echo "dbash - Starts a bash shell in the container."
|
||||||
|
echo "dsh - Starts a sh shell in the container."
|
||||||
|
echo "dstats - Shows stats for all running containers."
|
5
dlogs
Executable file
5
dlogs
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. $(dirname $0)/_get_container.sh
|
||||||
|
|
||||||
|
docker logs --tail=100 -f "$container"
|
5
dlogsl
Executable file
5
dlogsl
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. $(dirname $0)/_get_container.sh
|
||||||
|
|
||||||
|
docker logs -f "$container" 2>&1 | less
|
5
dlr
Executable file
5
dlr
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. $(dirname $0)/_get_container.sh
|
||||||
|
|
||||||
|
docker restart "$container" && docker logs --tail=100 -f "$container"
|
5
dsh
Executable file
5
dsh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. $(dirname $0)/_get_container.sh
|
||||||
|
|
||||||
|
docker exec -it "$container" /bin/sh
|
3
dstats
Executable file
3
dstats
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo docker stats $(docker inspect --format "{{.Name}}" $(docker ps -q))
|
47
ofelias.rb
Executable file
47
ofelias.rb
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require 'socket'
|
||||||
|
require 'json'
|
||||||
|
require 'terminal-table'
|
||||||
|
|
||||||
|
def fetch_data
|
||||||
|
socket = UNIXSocket.new("/var/run/docker.sock")
|
||||||
|
request = "GET /v1.24/containers/json?all=1 HTTP/1.0\r\n\r\n"
|
||||||
|
socket.write(request)
|
||||||
|
|
||||||
|
response = ""
|
||||||
|
|
||||||
|
loop do
|
||||||
|
break if socket.eof?
|
||||||
|
line = socket.gets
|
||||||
|
break if line=="\r\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
until socket.eof?
|
||||||
|
line = socket.gets
|
||||||
|
response += line
|
||||||
|
end
|
||||||
|
|
||||||
|
return JSON.parse(response, symbolize_names: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
rows = []
|
||||||
|
data = fetch_data
|
||||||
|
data.each do |d|
|
||||||
|
next unless labels = d[:Labels]
|
||||||
|
name = d[:Names][0][1..-1]
|
||||||
|
|
||||||
|
next unless labels[:"ofelia.enabled"]
|
||||||
|
tasks = labels.keys.map(&:to_s).map{|s| s.scan(/\Aofelia\.job-([a-z]+)\.([^.]*)\./).first}.uniq.compact
|
||||||
|
next unless tasks.count>0
|
||||||
|
tasks.each do |task|
|
||||||
|
type, taskname = *task
|
||||||
|
schedule = labels[:"ofelia.job-#{type}.#{taskname}.schedule"]
|
||||||
|
command = labels[:"ofelia.job-#{type}.#{taskname}.command"]
|
||||||
|
rows << [name, type, taskname, schedule, command]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
exit 0 unless rows.count>0
|
||||||
|
|
||||||
|
puts Terminal::Table.new(rows: rows, headings: ["Container", "Type", "Task", "Schedule", "Command"])
|
Loading…
Reference in New Issue
Block a user