diff --git a/conf/geocoder-us/thin.yml b/conf/geocoder-us/thin.yml deleted file mode 100644 index e644c33..0000000 --- a/conf/geocoder-us/thin.yml +++ /dev/null @@ -1,8 +0,0 @@ -environment: production -chdir: /var/lib/geocoder-us -user: www-data -group: www-data -port: 8081 -pid: /var/run/geocoder-us/geocoder-us.pid -log: /var/log/geocoder-us/geocoder-us.log -tag: geocoder diff --git a/conf/geocoder-us/unicorn.rb b/conf/geocoder-us/unicorn.rb new file mode 100644 index 0000000..51d4245 --- /dev/null +++ b/conf/geocoder-us/unicorn.rb @@ -0,0 +1,12 @@ +worker_processes 4 +user "www-data", "www-data" +listen "/var/run/geocoder-us/unicorn.sock", :backlog => 64 +pid "/var/run/geocoder-us/unicorn.pid" +stderr_path "/var/log/geocoder-us/geocoder-err.log" +stdout_path "/var/log/geocoder-us/geocoder-out.log" + +# Have each process listen on a local port for debugging purposes. +after_fork do |server, worker| + addr = "127.0.0.1:#{40000 + worker.nr}" + server.listen(addr, :tries => 1, :delay => 5, :tcp_nopush => true) +end diff --git a/conf/init/geocoder-us.conf b/conf/init/geocoder-us.conf index 4d047de..e53f8a1 100644 --- a/conf/init/geocoder-us.conf +++ b/conf/init/geocoder-us.conf @@ -10,16 +10,6 @@ stop on runlevel [!2345] respawn script - cd /tmp - ruby /usr/lib/ruby/1.8/geocoder/us/rest.rb /mnt/geocoder-us/geocoder.db -end script - -post-start script - mkdir -p /var/run/geocoder-us - PID=`status geocoder-us | egrep -oi '([0-9]+)$' | head -n1` - echo $PID > /var/run/geocoder-us/geocoder-us.pid -end script - -post-stop script - rm -f /var/run/geocoder-us/geocoder-us.pid + . /etc/default/geocoder-us + unicorn -c /etc/geocoder-us/unicorn.rb -D /etc/geocoder-us/geocoder.ru end script diff --git a/debian/README.source b/debian/README.source deleted file mode 100644 index 722dd34..0000000 --- a/debian/README.source +++ /dev/null @@ -1,9 +0,0 @@ -geocoder-us for Debian ----------------------- - - - - - - diff --git a/debian/control b/debian/control index 4f3fd14..a20c5c6 100644 --- a/debian/control +++ b/debian/control @@ -9,6 +9,6 @@ Homepage: http://github.com/simplegeo/geocoder/ Package: geocoder-us Architecture: any -Depends: ${misc:Depends}, ${shlibs:Depends}, ruby1.8, libsqlite3-ruby (>= 1.3.0), libsinatra-ruby, libjson-ruby, thin +Depends: ${misc:Depends}, ${shlibs:Depends}, ruby1.8, libsqlite3-ruby (>= 1.3.0), libsinatra-ruby, libjson-ruby, unicorn Description: A US address geocoder. A US address geocoder. Requires a suitable database. diff --git a/debian/default b/debian/default new file mode 100644 index 0000000..13ecc25 --- /dev/null +++ b/debian/default @@ -0,0 +1,6 @@ +# Defaults for geocoder-us upstart job +# sourced by /etc/init/geocoder-us.conf +# installed at /etc/default/geocoder-us by maintainer scripts + +# Set the location of the geocoder database. +export GEOCODER_DB="/var/lib/geocoder-us/geocoder.db" diff --git a/lib/geocoder/us/rest.rb b/lib/geocoder/us/rest.rb index 4881c7f..dd90f70 100644 --- a/lib/geocoder/us/rest.rb +++ b/lib/geocoder/us/rest.rb @@ -3,7 +3,7 @@ require 'json' require 'timeout' -@@db = Geocoder::US::Database.new(ARGV[0] || ENV["GEOCODER_DB"]) +@@db = Geocoder::US::Database.new(ENV["GEOCODER_DB"] || ARGV[0]) set :port, 8081 get '/geocode' do @@ -43,12 +43,12 @@ :features => features }.to_json rescue JSON::GeneratorError - { + { :type => "FeatureCollection", :error => "JSON::GeneratorError", :features => [] }.to_json - end + end else status 400 "parameter 'q' is missing"