Permalink
Browse files

Changes for Ruby 1.8/9 compatibilty, and Debian packaging guidelines

* Allow proxy to work on both ruby 1.9 and 1.8
* Require ping gem on ruby1.8
* Handle public folder changes in Sinatra
* Don't load rubygems if USE_GEMS=false specified, to comply with Debian guidelines
* Add USE_GEMS to the initscript
  • Loading branch information...
1 parent fcf097c commit ad8bb0c7f0b5f142093a8fcbd6cc64bc8d430fd9 Greg Sutcliffe committed with ohadlevy Jun 13, 2012
Showing with 30 additions and 7 deletions.
  1. +9 −2 bin/smart-proxy
  2. +1 −0 extra/debian/init.d
  3. +12 −0 lib/checks.rb
  4. +2 −1 lib/proxy.rb
  5. +1 −1 lib/proxy/dhcp/server/isc.rb
  6. +2 −1 lib/proxy/dhcp/server/native_ms.rb
  7. +3 −2 lib/proxy/dhcp/subnet.rb
View
@@ -3,7 +3,8 @@
$LOAD_PATH.unshift *Dir["#{File.dirname(__FILE__)}/../lib"]
APP_ROOT = "#{File.dirname(__FILE__)}/.."
-require "rubygems"
+require "checks"
+require "rubygems" if USE_GEMS
require "proxy"
require "sinatra-patch"
require "json"
@@ -18,11 +19,17 @@ class SmartProxy < Sinatra::Base
set :root, APP_ROOT
set :views, APP_ROOT + '/views'
- set :public, APP_ROOT + '/public'
set :logging, true
set :env, :production
set :run, true
+ # This changed in later Sinatra versions
+ if ( Sinatra::VERSION.split('.').map{|s|s.to_i} <=> [1,3,0] ) > 0
+ set :public_folder, APP_ROOT + '/public'
+ else
+ set :public, APP_ROOT + '/public'
+ end
+
require "tftp_api" if SETTINGS.tftp
require "puppet_api" if SETTINGS.puppet
require "puppetca_api" if SETTINGS.puppetca
View
@@ -55,6 +55,7 @@ do_start()
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
+ export USE_GEMS=false # No need for rubygems here
start-stop-daemon --start --quiet --chuid $DAEMON_USER --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
View
@@ -0,0 +1,12 @@
+# included in various places, to check the ruby environment
+
+# Test for 1.9
+if (RUBY_VERSION.split('.').map{|s|s.to_i} <=> [1,9,0]) > 0 then
+ PLATFORM = RUBY_PLATFORM
+ RUBY_1_9 = true
+else
+ RUBY_1_9 = false
+end
+
+# Don't load rubygems in production, it's for developers
+USE_GEMS = ENV['USE_GEMS'] == "false" ? false : true
View
@@ -2,10 +2,11 @@ module Proxy
MODULES = %w{dns dhcp tftp puppetca puppet}
VERSION = "0.3.1"
+ require "checks"
require "proxy/settings"
require "fileutils"
require "pathname"
- require "rubygems" # required for testing
+ require "rubygems" if USE_GEMS # required for testing
require "proxy/log"
require "proxy/util"
require "proxy/tftp" if SETTINGS.tftp
@@ -162,7 +162,7 @@ def omcmd cmd, msg=nil
end
def report msg, response=""
- if response.nil? or !response.grep(/can't|no more|not connected|Syntax error/).empty?
+ if response.nil? or (!response.empty? and !response.grep(/can't|no more|not connected|Syntax error/).empty?)
logger.error "Omshell failed:\n" + (response.nil? ? "No response from DHCP server" : response.join(", "))
msg.sub! /Removed/, "remove"
msg.sub! /Added/, "add"
@@ -1,4 +1,5 @@
-require 'rubygems'
+require 'checks'
+require 'rubygems' if USE_GEMS
require 'win32/open3'
module Proxy::DHCP
View
@@ -1,8 +1,9 @@
+require 'checks'
require 'ipaddr'
require 'proxy/dhcp/monkey_patches' unless IPAddr.new.respond_to?('to_range')
-require 'ping'
+require 'ping' unless RUBY_1_9
require 'proxy/validations'
-require "net/ping"
+require 'net/ping'
module Proxy::DHCP
# Represents a DHCP Subnet

0 comments on commit ad8bb0c

Please sign in to comment.