summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rwxr-xr-xutil/empty-queue23
-rwxr-xr-xutil/multi-ping82
2 files changed, 105 insertions, 0 deletions
diff --git a/util/empty-queue b/util/empty-queue
new file mode 100755
index 0000000..3e5795b
--- /dev/null
+++ b/util/empty-queue
@@ -0,0 +1,23 @@
+#!/usr/bin/ruby
+
+require 'beanstalk-client'
+
+
+beanstalk = Beanstalk::Pool.new(['localhost:11300'])
+
+#
+# Run until we're killed
+#
+while(true)
+ begin
+ puts "\n\nWaiting for job.."
+ job = beanstalk.reserve(1)
+ puts "Job acquired: #{Time.new.inspect}"
+ job.delete
+ rescue Beanstalk::TimedOut => ex
+ puts "Queue is empty"
+ exit(0)
+ end
+end
+
+
diff --git a/util/multi-ping b/util/multi-ping
new file mode 100755
index 0000000..116f3f7
--- /dev/null
+++ b/util/multi-ping
@@ -0,0 +1,82 @@
+#!/usr/bin/ruby
+#
+# Given a hostname, or IP address, run a ping test against it.
+#
+# This tool looks up the IP address to determine whether to run the
+# test with "ping" or "ping6".
+#
+# Steve
+# --
+#
+
+
+
+require 'socket'
+
+
+#
+# Get the address to ping.
+#
+hostname = ARGV.shift
+
+#
+# If we have no host then abort
+#
+if ( hostname.nil? )
+ puts "Usage: #{$0} hostname"
+ exit 1
+end
+
+
+#
+# The IP we'll deal with
+#
+ip = nil
+
+
+#
+# Lookup the IP, catching any exception
+#
+begin
+ Socket.getaddrinfo(hostname, 'echo').each do |a|
+ ip = a[3]
+ end
+rescue SocketError
+ puts "Failed to resolve: #{hostname}"
+ exit 1
+end
+
+
+#
+# Was the result an IPv4 address?
+#
+if ( ip =~ /^([0-9]+).([0-9]+).([0-9]+).([0-9]+)$/ )
+
+ #
+ # If so invoke "ping"
+ #
+ if ( system( "ping -c 1 #{ip} 2>/dev/null >/dev/null" ) == true )
+ puts "#{hostname} alive."
+ exit 0
+ else
+ puts "ping4 failed - #{hostname} [#{ip}]"
+ exit 1
+ end
+elsif ( ip =~ /2001/ )
+
+ #
+ # Was the result an IPv6 address?
+ #
+ if ( system( "ping6 -c 1 -w1 #{ip} 2>/dev/null >/dev/null" ) == true )
+ puts "#{hostname} alive."
+ exit 0
+ else
+ puts "ping6 failed - #{hostname} [#{ip}]"
+ exit 1
+ end
+end
+
+
+#
+# All done.
+#