bin/powder in powder-0.1.2 vs bin/powder in powder-0.1.3
- old
+ new
@@ -14,19 +14,50 @@
map '-r' => 'restart'
map '-l' => 'list'
map '-L' => 'link'
map '-o' => 'open'
map '-v' => 'version'
+ map 'update' => 'install'
- POWPATH = "#{`echo ~`.chomp}/.pow"
+ POW_PATH = "#{ENV['HOME']}/.pow"
+ POW_DAEMON_PLIST_PATH="#{ENV['HOME']}/Library/LaunchAgents/cx.pow.powd.plist"
+ POW_FIREWALL_PLIST_PATH = "/Library/LaunchDaemons/cx.pow.firewall.plist"
+ desc "up", "Enable pow"
+ def up
+ if File.exists? POW_FIREWALL_PLIST_PATH
+ %x{sudo launchctl load /Library/LaunchDaemons/cx.pow.firewall.plist}
+ else
+ say "Pow firewall configuration missing."
+ end
+ end
+
+ desc "down", "Disable pow"
+ def down
+ if File.exists? POW_FIREWALL_PLIST_PATH
+ if not %x{sudo launchctl list | grep cx.pow.firewall}.empty?
+ %x{sudo launchctl unload /Library/LaunchDaemons/cx.pow.firewall.plist}
+ end
+ if ports = File.open(POW_FIREWALL_PLIST_PATH).read.match(/fwd .*?,([\d]+).*?dst-port ([\d]+)/)
+ http_port, dst_port = ports[1..2]
+ end
+ end
+
+ http_port ||= 20559
+ dst_port ||= 80
+
+ if rule = %x{sudo ipfw show | grep ",#{http_port} .* dst-port #{dst_port} in"}.split.first
+ %x{sudo ipfw delete #{rule} && sudo sysctl -w net.inet.ip.forwarding=0}
+ end
+ end
+
desc "link", "Link a pow"
def link(name=nil)
return unless is_powable?
current_path = %x{pwd}.chomp
name ||= current_dir_pow_name
- symlink_path = "#{POWPATH}/#{name}"
+ symlink_path = "#{POW_PATH}/#{name}"
FileUtils.ln_s(current_path, symlink_path) unless File.exists?(symlink_path)
say "Your application is now available at http://#{name}.#{domain}/"
end
desc "restart", "Restart current pow"
@@ -36,22 +67,22 @@
%x{touch tmp/restart.txt}
end
desc "list", "List current pows"
def list
- Dir[POWPATH + "/*"].map { |a| say File.basename(a) }
+ Dir[POW_PATH + "/*"].map { |a| say File.basename(a) }
end
desc "open", "Open a pow in the browser"
def open(name=nil)
%x{open http://#{name || current_dir_pow_name}.#{domain}}
end
desc "remove", "Remove a pow"
def remove(name=nil)
return unless is_powable?
- FileUtils.rm_f POWPATH + '/' + (name || current_dir_pow_name)
+ FileUtils.rm_f POW_PATH + '/' + (name || current_dir_pow_name)
end
desc "install", "Installs pow"
def install
%x{curl get.pow.cx | sh}
@@ -60,15 +91,20 @@
desc "log", "Tails the Pow log"
def log(name=nil)
system "tail -f ~/Library/Logs/Pow/apps/#{name || current_dir_pow_name}.log"
end
+ desc "applog", "Tails in current app"
+ def applog(env="development")
+ system "tail -f log/#{env}.log" if is_powable?
+ end
+
desc "uninstall", "Uninstalls pow"
def uninstall
%x{curl get.pow.cx/uninstall.sh | sh}
end
-
+
desc "version", "Shows the version"
def version
say "powder #{Powder::VERSION}"
end
@@ -99,10 +135,10 @@
say "This does not appear to be a rack app as there is no config.ru."
say "Pow can also host static apps if there is an index.html in public/"
return false
end
end
-
+
def is_rails2_app?
File.exists?('config/environment.rb') && !`grep RAILS_GEM_VERSION config/environment.rb`.empty?
end
def domain