Class: Powify::Server
- Inherits:
-
Object
- Object
- Powify::Server
- Extended by:
- Powify
- Defined in:
- lib/powify/server.rb
Constant Summary collapse
- AVAILABLE_METHODS =
%w(install reinstall update uninstall remove start stop restart host unhost status config list logs help)
Constants included from Powify
Class Method Summary collapse
-
.config ⇒ Object
Print the current POW server configuration.
-
.host ⇒ Object
Add POW domains to the hosts file.
-
.install ⇒ Object
(also: reinstall, update)
Install the POW server.
-
.list ⇒ Object
List all active POW applications currently on the server.
-
.logs ⇒ Object
Tail the server logs.
-
.restart ⇒ Object
Restart the POW server.
- .run(args = []) ⇒ Object
-
.start ⇒ Object
Start the POW server (command taken from 37 Signals installation script).
-
.status ⇒ Object
Print the current POW server status.
-
.stop ⇒ Object
Stop the POW server (command taken from 37 Signals installation script).
-
.unhost ⇒ Object
Remove POW domains from the hosts file.
-
.uninstall ⇒ Object
(also: remove)
Uninstall the POW server.
Methods included from Powify
config, current_path, extension
Class Method Details
.config ⇒ Object
Print the current POW server configuration
113 114 115 116 117 118 119 |
# File 'lib/powify/server.rb', line 113 def config $stdout.puts "The current configuration of the pow server is:\n\n" result = %x{curl localhost/config.json --silent --header host:pow} json = JSON.parse(result) json.each_pair {|k,v| $stdout.puts " #{k}: #{v}"} $stdout.puts "\n" end |
.host ⇒ Object
Add POW domains to the hosts file
Original Author: Christopher Lindblom (github.com/lindblom) Original Context: github.com/lindblom/powder/commit/8b2f2609e91ddbc72f53c7fbb6daee92a82e21c0
This method was taken from Christopher Lindlom pull request to powder, a similar gem for managing pow applications. I DID NOT write this code (although I tested it), so don’t give me any credit!
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/powify/server.rb', line 61 def host hosts_file_path = '/etc/hosts' hosts_file = File.read(hosts_file_path) return $stdout.puts 'Pow is already in the hosts file. Please run `powify server unhost`' if hosts_file =~ /(#powify)/ || File.exists?("#{hosts_file_path}.powify.bak") # break our hosts file into lines hosts_file = hosts_file.split("\n") pow_domains = Dir["#{POWPATH}/*"].collect { |a| "127.0.0.1\t#{File.basename(a)}.#{extension}\t#powify" } # find the loop back and insert our domains after first_loopback_index = hosts_file.index{ |i| i =~ /^(127.0.0.1).+/ } hosts_file = hosts_file.insert(first_loopback_index + 1, pow_domains) %x{sudo cp #{hosts_file_path} #{hosts_file_path}.powify.bak} File.open(hosts_file_path, 'w+') { |f| f.puts hosts_file.join("\n") } %x{dscacheutil -flushcache} $stdout.puts "All Pow apps were added to the hosts file." $stdout.puts "The old host file is saved at #{hosts_file_path}.powify.bak." end |
.install ⇒ Object Also known as: reinstall, update
Install the POW server
18 19 20 21 22 |
# File 'lib/powify/server.rb', line 18 def install $stdout.puts "Installing/Re-installing/Updating pow server..." %x{curl get.pow.cx | sh} $stdout.puts "Done!" end |
.list ⇒ Object
List all active POW applications currently on the server
122 123 124 125 126 |
# File 'lib/powify/server.rb', line 122 def list $stdout.puts "The following POW applications are available:\n\n" Dir["#{POWPATH}/*"].each { |a| $stdout.puts " #{File.basename(a)} -> #{File.readlink(a)}" } $stdout.puts "\nRun `powify open [APP_NAME]` to browse an app" end |
.logs ⇒ Object
Tail the server logs
129 130 131 |
# File 'lib/powify/server.rb', line 129 def logs system "tail -f ~/Library/Logs/Pow/access.log" end |
.restart ⇒ Object
Restart the POW server
49 50 51 52 |
# File 'lib/powify/server.rb', line 49 def restart stop start end |
.run(args = []) ⇒ Object
11 12 13 14 15 |
# File 'lib/powify/server.rb', line 11 def run(args = []) method = args[0].to_s.downcase raise "The command `#{args.first}` does not exist for `powify server`!" unless Powify::Server::AVAILABLE_METHODS.include?(method) self.send(method) end |
.start ⇒ Object
Start the POW server (command taken from 37 Signals installation script)
35 36 37 38 39 |
# File 'lib/powify/server.rb', line 35 def start $stdout.puts "Starting the pow server..." %x{launchctl load "$HOME/Library/LaunchAgents/cx.pow.powd.plist"} $stdout.puts "Done!" end |
.status ⇒ Object
Print the current POW server status
104 105 106 107 108 109 110 |
# File 'lib/powify/server.rb', line 104 def status $stdout.puts "The current status of the pow server is:\n\n" result = %x{curl localhost/status.json --silent --header host:pow} json = JSON.parse(result) json.each_pair { |k,v| $stdout.puts " #{k}: #{v}" } $stdout.puts "\n" end |
.stop ⇒ Object
Stop the POW server (command taken from 37 Signals installation script)
42 43 44 45 46 |
# File 'lib/powify/server.rb', line 42 def stop $stdout.puts "Stopping the pow server..." %x{launchctl unload "$HOME/Library/LaunchAgents/cx.pow.powd.plist"} $stdout.puts "Done!" end |
.unhost ⇒ Object
Remove POW domains from the hosts file
Original Author: Christopher Lindblom (github.com/lindblom) Original Context: github.com/lindblom/powder/commit/8b2f2609e91ddbc72f53c7fbb6daee92a82e21c0
This method was taken from Christopher Lindlom pull request to powder, a similar gem for managing pow applications. I DID NOT write this code (although I tested it), so don’t give me any credit!
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/powify/server.rb', line 89 def unhost hosts_file_path = '/etc/hosts' hosts_file = File.read(hosts_file_path) return $stdout.puts 'Pow is not in the host file, and there is no backup file. Please run `powify server host`' unless hosts_file =~ /.+(#powify)/ || File.exists?("#{hosts_file_path}.powify.bak") hosts_file = hosts_file.split("\n").delete_if { |row| row =~ /.+(#powify)/ } # remove any existing records File.open(hosts_file_path, 'w+') { |f| f.puts hosts_file.join("\n") } %x{sudo rm #{hosts_file_path}.powify.bak} %x{dscacheutil -flushcache} $stdout.puts "All Pow apps were removed from the hosts file." end |
.uninstall ⇒ Object Also known as: remove
Uninstall the POW server
27 28 29 30 31 |
# File 'lib/powify/server.rb', line 27 def uninstall $stdout.puts "Uninstalling/Removing pow server..." %x{curl get.pow.cx/uninstall.sh | sh} $stdout.puts "Done!" end |