Permalink
Browse files

first-blush implementation based on vlad-merb

  • Loading branch information...
Kevin Bullock
Kevin Bullock committed May 25, 2010
0 parents commit f92f1224bc0f6726d0a09cb95a0730d89d79e61c
Showing with 202 additions and 0 deletions.
  1. +23 −0 .autotest
  2. +6 −0 History.txt
  3. +9 −0 Manifest.txt
  4. +69 −0 README.txt
  5. +12 −0 Rakefile
  6. +27 −0 lib/vlad/unicorn.rb
  7. +25 −0 lib/vlad/unicorn_common.rb
  8. +23 −0 lib/vlad/unicorn_rails.rb
  9. +8 −0 test/test_vlad_unicorn.rb
@@ -0,0 +1,23 @@
+# -*- ruby -*-
+
+require 'autotest/restart'
+
+# Autotest.add_hook :initialize do |at|
+# at.extra_files << "../some/external/dependency.rb"
+#
+# at.libs << ":../some/external"
+#
+# at.add_exception 'vendor'
+#
+# at.add_mapping(/dependency.rb/) do |f, _|
+# at.files_matching(/test_.*rb$/)
+# end
+#
+# %w(TestA TestB).each do |klass|
+# at.extra_class_map[klass] = "test/test_misc.rb"
+# end
+# end
+
+# Autotest.add_hook :run_command do |at|
+# system "rake build"
+# end
@@ -0,0 +1,6 @@
+=== 2.0.0 / 2010-XX-XX [FIX]
+
+* 1 major enhancement
+
+ * Birthday!
+
@@ -0,0 +1,9 @@
+.autotest
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+lib/vlad/unicorn.rb
+lib/vlad/unicorn_common.rb
+lib/vlad/unicorn_rails.rb
+test/test_vlad_unicorn.rb
@@ -0,0 +1,69 @@
+= vlad-unicorn
+
+* http://bitbucket.org/krbullock/vlad-unicorn/
+
+== DESCRIPTION:
+
+Unicorn app server support for Vlad. Adds support for vlad:start_app and
+vlad:stop_app using Unicorn[http://unicorn.bogomips.org/].
+
+== FEATURES/PROBLEMS:
+
+* Unicorn support for vlad:start_app and vlad:stop_app tasks.
+
+== SYNOPSIS:
+
+ # lib/tasks/vlad.rake
+ begin
+ require 'vlad'
+ Vlad.load(:app => :unicorn)
+ rescue LoadError
+ end
+
+or for legacy Rails (1.2.x thru 2.2.x) apps
+
+ # lib/tasks/vlad.rake
+ begin
+ require 'vlad'
+ Vlad.load(:app => :unicorn_rails)
+ rescue LoadError
+ end
+
+== REQUIREMENTS:
+
+* Vlad[http://rubyhitsquad.com/Vlad_the_Deployer.html]
+
+* Unicorn[http://unicorn.bogomips.org/]
+
+== INSTALL:
+
+ $ sudo gem install vlad-unicorn
+
+== VARIABLES:
+
+* FIX
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2010 Kevin Bullock and the rest of the Ruby Hit Squad
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
+# -*- ruby -*-
+
+require 'rubygems'
+require 'hoe'
+
+Hoe.spec 'vlad_unicorn' do
+ self.rubyforge_name = 'hitsquad'
+ developer('Kevin R. Bullock', 'kbullock@ringworld.org')
+ extra_deps << ['vlad', '~> 2.0']
+end
+
+# vim: syntax=ruby
@@ -0,0 +1,27 @@
+require 'vlad/unicorn_common'
+
+namespace :vlad do
+ ##
+ # Unicorn app server
+
+ set :unicorn_command, "unicorn"
+ set :unicorn_environment, "production"
+ set :unicorn_config, "#{current_path}/config/unicorn.rb"
+ set :unicorn_rackup, "#{current_path}/config.ru"
+ set :unicorn_use_sudo, false
+
+ desc "(Re)Start the app servers"
+ remote_task :start_app, :roles => :app do
+ Rake::Task['vlad:stop_app'].invoke
+ cmd = "#{unicorn_command} -D --config-file #{unicorn_config}"
+ cmd << " --env #{unicorn_environment}"
+ cmd << " #{unicorn_rackup}"
+ Vlad::Unicorn.maybe_sudo cmd
+ end
+
+ desc "Stop the app servers"
+ remote_task :stop_app, :roles => :app do
+ cmd = "#{unicorn_command} -m #{current_path} -K all"
+ Vlad::Unicorn.maybe_sudo cmd
+ end
+end
@@ -0,0 +1,25 @@
+require 'vlad'
+
+module Vlad
+ module Unicorn
+ VERSION = '2.0.0' #:nodoc:
+
+ # Runs +cmd+ using sudo if the +:merb_use_sudo+ variable is set.
+ def self.maybe_sudo(cmd)
+ if merb_use_sudo
+ sudo cmd
+ else
+ run cmd
+ end
+ end
+ end
+end
+
+namespace :vlad do
+
+ set :unicorn_command, "unicorn"
+ set :unicorn_environment, "production"
+ set :unicorn_config, "#{current_path}/config/unicorn.rb"
+ set :unicorn_use_sudo, false
+
+end
@@ -0,0 +1,23 @@
+require 'vlad/unicorn_common'
+
+namespace :vlad do
+ ##
+ # Unicorn app server for legacy Rails apps
+
+ set :unicorn_command, "unicorn_rails"
+
+ desc "(Re)Start the app servers"
+ remote_task :start_app, :roles => :app do
+ Rake::Task['vlad:stop_app'].invoke
+ cmd = "#{unicorn_command} -D --config-file #{unicorn_config}"
+ cmd << " --env #{unicorn_environment}"
+ cmd << " #{unicorn_rackup}"
+ Vlad::Unicorn.maybe_sudo cmd
+ end
+
+ desc "Stop the app servers"
+ remote_task :stop_app, :roles => :app do
+ cmd = "#{unicorn_command} -m #{current_path} -K all"
+ Vlad::Unicorn.maybe_sudo cmd
+ end
+end
@@ -0,0 +1,8 @@
+require "test/unit"
+require "vlad/unicorn"
+
+class TestVladUnicorn < Test::Unit::TestCase
+ def test_sanity
+ flunk "write tests or I will kneecap you"
+ end
+end

0 comments on commit f92f122

Please sign in to comment.