Compare commits

..

No commits in common. "8dbec29c459a457115a798da0d9e1941eebde0c7" and "5a0094f4d9f60a151aef90fb3f030a35e414bd09" have entirely different histories.

12 changed files with 4 additions and 258 deletions

View File

@ -1,13 +0,0 @@
#!/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

View File

@ -1,16 +0,0 @@
#!/bin/sh
SOURCE=$(dirname $0)
[[ -e "$SOURCE/dbash" ]] || { echo "Please cd to the directory containing this file and try to run _install.sh again." ; exit 1 }
TARGET=/usr/local/bin
ln -sf "$SOURCE/dbash" "$TARGET/dbash"
ln -sf "$SOURCE/dhelp" "$TARGET/dhelp"
ln -sf "$SOURCE/dlogs" "$TARGET/dlogs"
ln -sf "$SOURCE/dlogsl" "$TARGET/dlogsl"
ln -sf "$SOURCE/dlr" "$TARGET/dlr"
ln -sf "$SOURCE/dps.rb" "$TARGET/dps"
ln -sf "$SOURCE/dsh" "$TARGET/dsh"
ln -sf "$SOURCE/dstats" "$TARGET/dstats"
ln -sf "$SOURCE/dup.rb" "$TARGET/dup"
ln -sf "$SOURCE/ofelias.rb" "$TARGET/ofelias"

5
dbash
View File

@ -1,5 +0,0 @@
#!/bin/sh
. $(dirname $0)/_get_container.sh
docker exec -it "$container" /bin/bash

9
dhelp
View File

@ -1,9 +0,0 @@
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
View File

@ -1,5 +0,0 @@
#!/bin/sh
. $(dirname $0)/_get_container.sh
docker logs --tail=100 -f "$container"

5
dlogsl
View File

@ -1,5 +0,0 @@
#!/bin/sh
. $(dirname $0)/_get_container.sh
docker logs -f "$container" 2>&1 | less

5
dlr
View File

@ -1,5 +0,0 @@
#!/bin/sh
. $(dirname $0)/_get_container.sh
docker restart "$container" && docker logs --tail=100 -f "$container"

130
dps.rb
View File

@ -1,130 +0,0 @@
#!/usr/bin/env ruby
require 'json'
require 'socket'
require 'net/http'
COLOR_GREEN = ""
COLOR_RED = ""
COLOR_GRAY = ""
COLOR_RESET = ""
class Container
FIELDS = [:state, :dup, :ouroboros, :name, :vhosts, :nginx_allow, :status, :image, :ports]
@@lengths = Hash.new(0)
def initialize(data)
@strings = {}
@data = data
set :state, (@data[:State]=="running" ? COLOR_GREEN : COLOR_RED) + @data[:State].capitalize + COLOR_RESET
set :dup, @data[:Labels][:"de.fabianonline.dup"]=="true" ? "" : ""
set :ouroboros, @data[:Labels][:"com.centurylinklabs.watchtower.enable"]=="true" ? "" : ""
set :name, @data[:Names].first[1..-1]
vh = @data[:Labels][:"nginx_virtual_host"]&.split(",")&.collect(&:strip)
if vh.nil? || vh.count==0
vh = ""
elsif vh.count==1
vh = vh.first
else
if FULL
vh = vh.join(", ")
else
vh = vh.first + ",…"
end
end
set :vhosts, vh
p = @data[:Ports].sort_by{|p| p[:PrivatePort]}.collect do |p|
type = p[:Type]=="tcp" ? "" : "/#{p[:Type]}"
if p[:PrivatePort]==p[:PublicPort]
"#{COLOR_GREEN}#{p[:PrivatePort]}#{type}"
elsif p[:PublicPort]==nil
"#{COLOR_GRAY}#{p[:PrivatePort]}#{type}"
else
"#{COLOR_RED}#{p[:PrivatePort]}->#{p[:PublicPort]}#{type}"
end
end.join(" ")
set :nginx_allow, @data[:Labels][:"nginx_allow"]
st = @data[:Status]
if st.end_with?("(healthy)")
st = COLOR_GREEN + st.gsub("(healthy)", "(v)") + COLOR_RESET
elsif st.end_with?("(unhealthy)")
st = COLOR_RED + st.gsub("(unhealthy)", "(x)") + COLOR_RESET
end
set :status, st
im = @data[:Image]
im = im.split(":")[0] unless FULL
set :image, im
set :ports, p
end
def set(key, value)
@data[key] = value
@@lengths[key] = [@@lengths[key], value.cleaned.length].max if value
end
def self.lengths; FIELDS.map{|k| @@lengths[k]}; end
def data
FIELDS.map{|k| @data[k]}
end
end
class String
def cleaned
self.gsub(/\[.+?m/, "")
end
def fix_length(len)
l = self.cleaned.length
shortened = self.length - l
if l >= len
return self.slice(0, len + shortened)
else
return self + (" " * (len - l))
end
end
end
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"#Host: localhost\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
FULL = ARGV[0]=="--full"
data = fetch_data
data = data.map{|c| Container.new(c).data}
lengths = Container.lengths
data.sort_by{|d| d[3]}.each do |row|
row.each_with_index do |d, index|
if index==row.length-1
print d.to_s
else
print d.to_s.fix_length(lengths[index]) + " "
end
end
puts
end

5
dsh
View File

@ -1,5 +0,0 @@
#!/bin/sh
. $(dirname $0)/_get_container.sh
docker exec -it "$container" /bin/sh

3
dstats
View File

@ -1,3 +0,0 @@
#!/bin/bash
echo docker stats $(docker inspect --format "{{.Name}}" $(docker ps -q))

19
dup.rb
View File

@ -155,15 +155,6 @@ def run_cmd(cmd, ignore_returnvalue=false, catch_interrupt=false, ignore_dry_run
return returnvalue return returnvalue
end end
def collect_commands(&block)
$commands = []
def run_cmd(cmd, ignore_returnvalue=false, catch_interrupt=false, ignore_dry_run: false); $commands<<cmd; return 0; end
yield
return $commands
end
def esc(obj, escape=true) def esc(obj, escape=true)
return obj unless escape return obj unless escape
return obj.to_s.shellescape return obj.to_s.shellescape
@ -227,7 +218,8 @@ end
def action_regenerate(container) def action_regenerate(container)
container.each do |c| container.each do |c|
data = c.regenerate data = c.regenerate
p collect_commands{ c.run } puts data.to_yaml
puts
end end
end end
@ -332,7 +324,7 @@ class Container
end end
end end
return cmd.compact.join(" ") return cmd
end end
def build def build
@ -411,7 +403,7 @@ class Container
verbose "Creating container..." verbose "Creating container..."
cmd = build_run_command cmd = build_run_command
run_cmd(cmd + " >/dev/null") run_cmd(cmd.compact.join(" ") + " >/dev/null")
self.connect_to_networks self.connect_to_networks
@ -448,7 +440,6 @@ class Container
data[name] = result data[name] = result
end end
@data = data
return data return data
end end
end end
@ -515,7 +506,6 @@ opts.each do |opt, arg|
$net_host = true $net_host = true
when '--regenerate' when '--regenerate'
action = :regenerate action = :regenerate
needs_container = false
when '--verbose' when '--verbose'
$verbose = true $verbose = true
when '--all' when '--all'
@ -543,7 +533,6 @@ elsif action == :update
action_update(base_dir) action_update(base_dir)
elsif action == :regenerate elsif action == :regenerate
action_regenerate(container) action_regenerate(container)
container.each {|c| puts c.build_run_command}
elsif action == :_completion elsif action == :_completion
action_completion($base_dir, completion_str) action_completion($base_dir, completion_str)
end end

View File

@ -1,47 +0,0 @@
#!/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"])