powify 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,51 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ #.DS_Store
31
+
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+
41
+ # For vim:
42
+ #*.swp
43
+
44
+ # For redcar:
45
+ #.redcar
46
+
47
+ # For rubinius:
48
+ #*.rbc
49
+
50
+ # Ignore gems built in this dir
51
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,16 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ powify (0.8.5)
5
+ json
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ json (1.6.5)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ powify!
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Seth Vargo
2
+
3
+ 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:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ 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,240 @@
1
+ Powify
2
+ ======
3
+
4
+ Powify is a management tool for [Pow](http://pow.cx/) by 37 signals. It allows you to easily install, update, and manage pow and pow applications seamlessly. To get started, read the installation section below.
5
+
6
+
7
+ Installation
8
+ ------------
9
+ Install powify using the `gem` command:
10
+
11
+ gem install powify
12
+
13
+ Important Notes
14
+ ---------------
15
+ Powify assumes that your current working directory has the same basename as Pow app. For example, if my site was in:
16
+
17
+ /Users/sethvargo/Development/my_site
18
+
19
+ Powify would expect the name of the Pow app to also be `my_site` (the name of the symlink). This is the default behavior if you just use the command `powify create`. However, it's feasible that you would want a different name that the folder. If this is the case, you'll always need to specify the name of the application like this:
20
+
21
+ powify restart foo
22
+ powify destroy foo
23
+ powify move foo new_foo
24
+
25
+
26
+ ### FAQ
27
+ Q: But Seth, why don't you just search the `~/.pow` directory and grab the symlink that points to the current directory?
28
+
29
+ A: Because it's inefficient and it could cause a problem if the same Pow apps are symlinked multiple times under different names, Powify could accidentally perform an operation on the wrong one.
30
+
31
+
32
+ Q: Why don't you just add a hidden file to the project directory when someone creates the app, then you'll know what the symlinked is named.
33
+
34
+ A: What happens when the same app is symlinked multiple times under a different name? I also hate when applications create files randomly on my hard drive.
35
+
36
+ Usage
37
+ -----
38
+
39
+ ### Server Commands
40
+ Server Commands can be run from anywhere. These are commands that apply to the Pow Server, not an individual application itself.
41
+
42
+ $ powify server install
43
+ => install pow server
44
+
45
+  
46
+
47
+ $ powify server reinstall
48
+ => reinstall pow server
49
+
50
+  
51
+
52
+ $ powify server update
53
+ => update pow server
54
+
55
+  
56
+
57
+ $ powify server uninstall
58
+ => uninstall pow server
59
+
60
+  
61
+
62
+ $ powify server list
63
+ => list all apps on this pow server
64
+
65
+  
66
+
67
+ $ powify server start
68
+ => start the pow server
69
+
70
+  
71
+
72
+ $ powify server stop
73
+ => stop the pow server
74
+
75
+  
76
+
77
+ $ powify server restart
78
+ => restart the pow server
79
+
80
+  
81
+
82
+ $ powify server host
83
+ => copies all pow apps to /etc/hosts - this is used for offline development when you aren't connected to a network
84
+
85
+ `host` was written by [Christopher Lindblom](https://github.com/lindblom)
86
+
87
+ $ powify server unhost
88
+ => removes all pow apps to /etc/hosts
89
+
90
+ `unhost` was written by [Christopher Lindblom](https://github.com/lindblom)
91
+
92
+ $ powify server status
93
+ => print the current status of the server
94
+
95
+  
96
+
97
+ $ powify server config
98
+ => print the current configuration of the server
99
+
100
+  
101
+
102
+ $ powify server logs
103
+ => tail the pow server logs
104
+
105
+ ### Utils Commands
106
+ Util commands were introduced after I created [powify.dev](https://github.com/sethvargo/powify.dev). They make installing `powify.dev` really easy!
107
+
108
+ $ powify utils install
109
+ => install powify.dev
110
+
111
+  
112
+
113
+ $ powify utils reinstall
114
+ => reinstall powify.dev
115
+
116
+  
117
+
118
+ $ powify utils uninstall
119
+ => uninstall powify.dev
120
+
121
+
122
+ ### App Commands
123
+ App commands should (but don't necessarily have to be) run from the application directory.
124
+
125
+ $ powify create
126
+ => create a pow app with the same name as the current directory
127
+
128
+  
129
+
130
+ $ powify create foo
131
+ => create a pow app named `foo` served from the current directory
132
+
133
+  
134
+
135
+ $ powify destroy
136
+ => destroy the pow app served from the current directory
137
+
138
+  
139
+
140
+ $ powify destroy foo
141
+ => destroy the pow app named `foo`
142
+
143
+  
144
+
145
+ $ powify restart
146
+ => restart the app served from the current directory
147
+
148
+  
149
+
150
+ $ powify always_restart
151
+ => tell pow to always reload the framework on each request
152
+
153
+  
154
+
155
+ $ powify always_restart foo
156
+ => tell pow to always reload the framework on each request to the pow app named `foo`
157
+
158
+  
159
+
160
+ $ powify always_restart_off
161
+ => tell pow to not reload the framework on each request
162
+
163
+  
164
+
165
+ $ powify always_restart_off foo
166
+ => tell pow to not reload the framework on each request to the pow app named `foo`
167
+
168
+  
169
+
170
+ $ powify restart foo
171
+ => restart the pow app named `foo`
172
+
173
+  
174
+
175
+ $ powify browse
176
+ => open the default browser and navigate to this app
177
+
178
+  
179
+
180
+ $ powify browse foo
181
+ => open the default browser and navigate to the app named `foo`
182
+
183
+  
184
+
185
+ $ powify browse foo test
186
+ => open the default browser and navigate to the app named `foo` resolved on test (http://foo.test)
187
+
188
+  
189
+
190
+ $ powify logs
191
+ => tail the app logs for the app served from this directory
192
+
193
+  
194
+
195
+ $ powify logs foo
196
+ => tail the app logs for the app named `foo`
197
+
198
+  
199
+
200
+ $ powify rename foo
201
+ => rename the pow app in the current directory to `foo`
202
+
203
+  
204
+
205
+ $ powify rename foo bar
206
+ => rename the pow app named `foo` to `bar`
207
+
208
+  
209
+
210
+ $ powify environment production
211
+ => run the current pow app in production
212
+
213
+  
214
+
215
+ $ powify env staging
216
+ => run the current pow app in staging
217
+
218
+  
219
+
220
+ $ powify help
221
+ => list pow commands
222
+
223
+
224
+ Contribution
225
+ ------------
226
+ - 9/2 [@lindblom](https://github.com/lindblom) - author of `host` and `unhost`
227
+ - 10/29 [@warwickp](https://github.com/warwickp) - wrote `always_restart_off`
228
+
229
+ If you would like to contribute, fork and send me a pull request.
230
+
231
+
232
+ License
233
+ -------
234
+ Copyright (c) 2012 Seth Vargo
235
+
236
+ 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:
237
+
238
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
239
+
240
+ 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 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'powify'
7
+
8
+ args = ARGV.dup
9
+ ARGV.clear
10
+
11
+ Powify::Client.run(args)
@@ -0,0 +1 @@
1
+ require 'powify/core'
@@ -0,0 +1,142 @@
1
+ module Powify
2
+ class App
3
+ extend Powify
4
+ AVAILABLE_METHODS = %w(create link new destroy unlink remove restart always_restart always_restart_off browse open rename environment env logs help)
5
+
6
+ class << self
7
+ def run(args)
8
+ method = args[0].strip.to_s.downcase
9
+ raise "The command `#{args.first}` does not exist!" unless AVAILABLE_METHODS.include?(method)
10
+ self.send(method, args[1..-1])
11
+ end
12
+
13
+ # powify create
14
+ # powify create foo
15
+ def create(args = [])
16
+ app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path)
17
+ symlink_path = "#{POWPATH}/#{app_name}"
18
+ FileUtils.ln_s(current_path, symlink_path)
19
+ $stdout.puts "Successfully created pow app #{app_name}!"
20
+ $stdout.puts "Type `powify browse #{app_name}` to open the application in your browser."
21
+ end
22
+ alias_method :link, :create
23
+ alias_method :new, :create
24
+
25
+ # powify destroy
26
+ # powify destroy foo
27
+ def destroy(args = [])
28
+ app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path)
29
+ symlink_path = "#{POWPATH}/#{app_name}"
30
+ if File.exists?(symlink_path)
31
+ FileUtils.rm(symlink_path)
32
+ $stdout.puts "Successfully destroyed pow app #{app_name}!"
33
+ $stdout.puts "If this was an accident, type `powify create #{app_name}` to re-create the app."
34
+ else
35
+ $stdout.puts "Powify could not find an app named `#{app_name}` on this server."
36
+ $stdout.puts "By default, powify tries to look for an application with the same name as the current directory."
37
+ $stdout.puts "If your application has a different name than the working directory, you'll need to specify in the command:"
38
+ $stdout.puts "\n\tpowify destroy [NAME]\n\n"
39
+ $stdout.puts "If your app was named `foo`, you would type:"
40
+ $stdout.puts "\n\tpowify destroy foo\n\n"
41
+ end
42
+ end
43
+ alias_method :unlink, :destroy
44
+ alias_method :remove, :destroy
45
+
46
+ # powify restart
47
+ # powify restart foo
48
+ def restart(args = [])
49
+ app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path)
50
+ symlink_path = "#{POWPATH}/#{app_name}"
51
+ if File.exists?(symlink_path)
52
+ FileUtils.mkdir_p("#{symlink_path}/tmp")
53
+ %x{touch #{symlink_path}/tmp/restart.txt}
54
+ $stdout.puts "Successfully restarted #{app_name}!"
55
+ else
56
+ $stdout.puts "Powify could not find an app to restart with the name #{app_name}"
57
+ $stdout.puts "Type `powify server list` for a full list of applications."
58
+ end
59
+ end
60
+
61
+ # powify always_restart
62
+ # powify always_restart foo
63
+ def always_restart(args = [])
64
+ app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path)
65
+ symlink_path = "#{POWPATH}/#{app_name}"
66
+ if File.exists?(symlink_path)
67
+ FileUtils.mkdir_p("#{symlink_path}/tmp")
68
+ %x{touch #{symlink_path}/tmp/always_restart.txt}
69
+ $stdout.puts "#{app_name} will now restart after every request!"
70
+ else
71
+ $stdout.puts "Powify could not find an app to always restart with the name #{app_name}"
72
+ $stdout.puts "Type `powify server list` for a full list of applications."
73
+ end
74
+ end
75
+
76
+ # powify always_restart_off
77
+ # powify always_restart_off foo
78
+ def always_restart_off(args = [])
79
+ app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path)
80
+ restart_txt_path = "#{POWPATH}/#{app_name}/tmp/always_restart.txt"
81
+ if File.exists?(restart_txt_path)
82
+ FileUtils.rm_f(restart_txt_path)
83
+ $stdout.puts "#{app_name} will no longer restart after every request!"
84
+ else
85
+ $stdout.puts "Powify detemined that the app with name #{app_name} is not set to always restart."
86
+ end
87
+ end
88
+
89
+ # powify browse
90
+ # powify browse foo
91
+ # powify browse foo test
92
+ def browse(args = [])
93
+ app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path)
94
+ ext = args[1] || extension
95
+ symlink_path = "#{POWPATH}/#{app_name}"
96
+ if File.exists?(symlink_path)
97
+ %x{open http://#{app_name}.#{ext}}
98
+ else
99
+ $stdout.puts "Powify could not find an app to browse with the name #{app_name}"
100
+ Powify::Server.list
101
+ end
102
+ end
103
+ alias_method :open, :browse
104
+
105
+ # powify rename bar
106
+ # powify rename foo bar
107
+ def rename(args = [])
108
+ return if args.empty?
109
+ original_app_name, new_app_name = File.basename(current_path), args[0].strip.to_s.downcase
110
+ original_app_name, new_app_name = args[0].strip.to_s.downcase, args[1].strip.to_s.downcase if args.size > 1
111
+ original_symlink_path, new_symlink_path = "#{POWPATH}/#{original_app_name}", "#{POWPATH}/#{new_app_name}"
112
+
113
+ FileUtils.rm(original_symlink_path)
114
+ FileUtils.ln_s(current_path, new_symlink_path)
115
+
116
+ $stdout.puts "Succesfully renamed #{original_app_name} to #{new_app_name}."
117
+ $stdout.puts "Type `powify browse #{new_app_name}` to open the application in your browser."
118
+ end
119
+
120
+ # powify environment production
121
+ # powify environment foo production
122
+ def environment(args = [])
123
+ return if args.empty?
124
+ app_name, env = File.basename(current_path), args[0].strip.to_s.downcase
125
+ app_name, env = args[0].strip.to_s.downcase, args[1].strip.to_s.downcase if args.size > 1
126
+ symlink_path = "#{POWPATH}/#{app_name}"
127
+ %x{echo export RAILS_ENV=#{env} > #{symlink_path}/.powenv}
128
+ $stdout.puts "Successfully changed environment to #{env}."
129
+ restart [app_name]
130
+ end
131
+ alias_method :env, :environment
132
+
133
+ # powify logs
134
+ # powify logs foo
135
+ def logs(args = [])
136
+ app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path)
137
+ symlink_path = "#{POWPATH}/#{app_name}"
138
+ system "tail -f #{symlink_path}/log/#{ENV['RAILS_ENV']||'development'}.log"
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,56 @@
1
+ module Powify
2
+ class Client
3
+ extend Powify
4
+ class << self
5
+ def run(args = [])
6
+ begin
7
+ if args[0] && args[0].strip != 'help'
8
+ return Powify::Server.run(args[1..-1]) if args[0].strip == 'server'
9
+ return Powify::Utils.run(args[1..-1]) if args[0].strip == 'utils'
10
+ return Powify::App.run(args)
11
+ end
12
+ rescue Exception => e
13
+ $stdout.puts e
14
+ end
15
+
16
+ help
17
+ end
18
+
19
+ def help
20
+ $stdout.puts ""
21
+ $stdout.puts " [SERVER COMMANDS]"
22
+ $stdout.puts " powify server install install pow server"
23
+ $stdout.puts " powify server reinstall reinstall pow server"
24
+ $stdout.puts " powify server update update pow server"
25
+ $stdout.puts " powify server uninstall uninstall pow server"
26
+ $stdout.puts " powify server list list all pow apps"
27
+ $stdout.puts " powify server start start the pow server"
28
+ $stdout.puts " powify server stop stop the pow server"
29
+ $stdout.puts " powify server restart restart the pow server"
30
+ $stdout.puts " powify server host adds all pow apps to /etc/hosts file"
31
+ $stdout.puts " powify server unhost removes all pow apps from /etc/hosts file"
32
+ $stdout.puts " powify server status print the current server status"
33
+ $stdout.puts " powify server config print the current server configuration"
34
+ $stdout.puts " powify server logs tails the pow server logs"
35
+ $stdout.puts ""
36
+ $stdout.puts " [UTILS COMMANDS]"
37
+ $stdout.puts " powify utils install install powify.dev server management tool"
38
+ $stdout.puts " powify utils reinstall reinstall powify.dev server management tool"
39
+ $stdout.puts " powify utils uninstall uninstall powify.dev server management tool"
40
+ $stdout.puts ""
41
+ $stdout.puts " [APP COMMANDS]"
42
+ $stdout.puts " powify create [NAME] creates a pow app from the current directory"
43
+ $stdout.puts " powify destroy [NAME] destroys the pow app linked to the current directory"
44
+ $stdout.puts " powify restart [NAME] restarts the pow app linked to the current directory"
45
+ $stdout.puts " powify always_restart [NAME] reload the pow app after each request"
46
+ $stdout.puts " powify always_restart_off [NAME] do not reload the pow app after each request"
47
+ $stdout.puts " powify rename [NAME] rename the pow app to [NAME]"
48
+ $stdout.puts " powify rename [OLD] [NEW] rename the pow app [OLD] to [NEW]"
49
+ $stdout.puts " powify environment [ENV] run the this pow app in a different environment (aliased `env`)"
50
+ $stdout.puts " powify browse [NAME] opens and navigates the default browser to this app"
51
+ $stdout.puts " powify logs [NAME] tail the application logs"
52
+ $stdout.puts ""
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,30 @@
1
+ require 'powify/app'
2
+ require 'powify/client'
3
+ require 'powify/server'
4
+ require 'powify/utils'
5
+ require 'fileutils'
6
+
7
+ module Powify
8
+ POWPATH = File.expand_path("~/.pow")
9
+
10
+ def current_path
11
+ %x{pwd}.strip
12
+ end
13
+
14
+ def extension
15
+ if File.exists?('~/.powconfig')
16
+ return %x{source ~/.powconfig; echo $POW_DOMAIN}.strip unless %x{source ~/.powconfig; echo $POW_DOMAIN}.strip.empty?
17
+ return %x{source ~/.powconfig; echo $POW_DOMAINS}.strip.split(',').first unless %x{source ~/.powconfig; echo $POW_DOMAINS}.strip.empty?
18
+ else
19
+ return %x{echo $POW_DOMAIN}.strip unless %x{echo $POW_DOMAIN}.strip.empty?
20
+ return %x{echo $POW_DOMAINS}.strip.split(',').first unless %x{echo $POW_DOMAINS}.strip.empty?
21
+ end
22
+
23
+ return 'dev'
24
+ end
25
+
26
+ def config
27
+ result = %x{curl localhost/config.json --silent --header host:pow}
28
+ JSON.parse(result)
29
+ end
30
+ end
@@ -0,0 +1,134 @@
1
+ require 'json'
2
+
3
+ # powify server functions
4
+ # invoked via powify server [COMMAND] [ARGS]
5
+ module Powify
6
+ class Server
7
+ extend Powify
8
+ AVAILABLE_METHODS = %w(install reinstall update uninstall remove start stop restart host unhost status config list logs help)
9
+
10
+ class << self
11
+ def run(args = [])
12
+ method = args[0].to_s.downcase
13
+ raise "The command `#{args.first}` does not exist for `powify server`!" unless Powify::Server::AVAILABLE_METHODS.include?(method)
14
+ self.send(method)
15
+ end
16
+
17
+ # Install the POW server
18
+ def install
19
+ $stdout.puts "Installing/Re-installing/Updating pow server..."
20
+ %x{curl get.pow.cx | sh}
21
+ $stdout.puts "Done!"
22
+ end
23
+ alias_method :reinstall, :install
24
+ alias_method :update, :install
25
+
26
+ # Uninstall the POW server
27
+ def uninstall
28
+ $stdout.puts "Uninstalling/Removing pow server..."
29
+ %x{curl get.pow.cx/uninstall.sh | sh}
30
+ $stdout.puts "Done!"
31
+ end
32
+ alias_method :remove, :uninstall
33
+
34
+ # Start the POW server (command taken from 37 Signals installation script)
35
+ def start
36
+ $stdout.puts "Starting the pow server..."
37
+ %x{launchctl load "$HOME/Library/LaunchAgents/cx.pow.powd.plist"}
38
+ $stdout.puts "Done!"
39
+ end
40
+
41
+ # Stop the POW server (command taken from 37 Signals installation script)
42
+ def stop
43
+ $stdout.puts "Stopping the pow server..."
44
+ %x{launchctl unload "$HOME/Library/LaunchAgents/cx.pow.powd.plist"}
45
+ $stdout.puts "Done!"
46
+ end
47
+
48
+ # Restart the POW server
49
+ def restart
50
+ stop
51
+ start
52
+ end
53
+
54
+ # Add POW domains to the hosts file
55
+ #
56
+ # Original Author: Christopher Lindblom (https://github.com/lindblom)
57
+ # Original Context: https://github.com/lindblom/powder/commit/8b2f2609e91ddbc72f53c7fbb6daee92a82e21c0
58
+ #
59
+ # This method was taken from Christopher Lindlom pull request to powder, a similar gem for managing
60
+ # pow applications. I DID NOT write this code (although I tested it), so don't give me any credit!
61
+ def host
62
+ hosts_file_path = '/etc/hosts'
63
+ hosts_file = File.read(hosts_file_path)
64
+ 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")
65
+
66
+ # break our hosts file into lines
67
+ hosts_file = hosts_file.split("\n")
68
+ pow_domains = Dir["#{POWPATH}/*"].collect { |a| "127.0.0.1\t#{File.basename(a)}.#{extension}\t#powify" }
69
+
70
+ # find the loop back and insert our domains after
71
+ first_loopback_index = hosts_file.index{ |i| i =~ /^(127.0.0.1).+/ }
72
+ hosts_file = hosts_file.insert(first_loopback_index + 1, pow_domains)
73
+
74
+ %x{sudo cp #{hosts_file_path} #{hosts_file_path}.powify.bak}
75
+ File.open(hosts_file_path, 'w+') { |f| f.puts hosts_file.join("\n") }
76
+
77
+ %x{dscacheutil -flushcache}
78
+ $stdout.puts "All Pow apps were added to the hosts file."
79
+ $stdout.puts "The old host file is saved at #{hosts_file_path}.powify.bak."
80
+ end
81
+
82
+ # Remove POW domains from the hosts file
83
+ #
84
+ # Original Author: Christopher Lindblom (https://github.com/lindblom)
85
+ # Original Context: https://github.com/lindblom/powder/commit/8b2f2609e91ddbc72f53c7fbb6daee92a82e21c0
86
+ #
87
+ # This method was taken from Christopher Lindlom pull request to powder, a similar gem for managing
88
+ # pow applications. I DID NOT write this code (although I tested it), so don't give me any credit!
89
+ def unhost
90
+ hosts_file_path = '/etc/hosts'
91
+ hosts_file = File.read(hosts_file_path)
92
+ 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")
93
+
94
+ hosts_file = hosts_file.split("\n").delete_if { |row| row =~ /.+(#powify)/ } # remove any existing records
95
+
96
+ File.open(hosts_file_path, 'w+') { |f| f.puts hosts_file.join("\n") }
97
+ %x{sudo rm #{hosts_file_path}.powify.bak}
98
+
99
+ %x{dscacheutil -flushcache}
100
+ $stdout.puts "All Pow apps were removed from the hosts file."
101
+ end
102
+
103
+ # Print the current POW server status
104
+ def status
105
+ $stdout.puts "The current status of the pow server is:\n\n"
106
+ result = %x{curl localhost/status.json --silent --header host:pow}
107
+ json = JSON.parse(result)
108
+ json.each_pair { |k,v| $stdout.puts " #{k}: #{v}" }
109
+ $stdout.puts "\n"
110
+ end
111
+
112
+ # Print the current POW server configuration
113
+ def config
114
+ $stdout.puts "The current configuration of the pow server is:\n\n"
115
+ result = %x{curl localhost/config.json --silent --header host:pow}
116
+ json = JSON.parse(result)
117
+ json.each_pair {|k,v| $stdout.puts " #{k}: #{v}"}
118
+ $stdout.puts "\n"
119
+ end
120
+
121
+ # List all active POW applications currently on the server
122
+ def list
123
+ $stdout.puts "The following POW applications are available:\n\n"
124
+ Dir["#{POWPATH}/*"].each { |a| $stdout.puts " #{File.basename(a)} -> #{File.readlink(a)}" }
125
+ $stdout.puts "\nRun `powify open [APP_NAME]` to browse an app"
126
+ end
127
+
128
+ # Tail the server logs
129
+ def logs
130
+ system "tail -f ~/Library/Logs/Pow/access.log"
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+ # powify server functions
3
+ # invoked via powify utils [COMMAND] [ARGS]
4
+ module Powify
5
+ class Utils
6
+ extend Powify
7
+ AVAILABLE_METHODS = %w(install reinstall uninstall remove help)
8
+
9
+ class << self
10
+ def run(args = [])
11
+ method = args[0].to_s.downcase
12
+ raise "The command `#{args.first}` does not exist for `powify utils`!" unless Powify::Utils::AVAILABLE_METHODS.include?(method)
13
+ self.send(method)
14
+ end
15
+
16
+ # Install powify.dev
17
+ def install
18
+ uninstall
19
+ $stdout.puts "Cloning powify.dev from github and bundling powify.dev..."
20
+ %x{git clone -q git@github.com:sethvargo/powify.dev.git powify && cd powify && bundle install --deployment && cd .. && mv powify "#{config['hostRoot']}"}
21
+ $stdout.puts "Done!"
22
+ end
23
+ alias_method :reinstall, :install
24
+
25
+ # Uninstall powify.dev
26
+ def uninstall
27
+ %x{rm -rf "#{config['hostRoot']}/powify"}
28
+ $stdout.puts "Successfully removed powify.dev"
29
+ end
30
+ alias_method :remove, :uninstall
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'powify'
6
+ s.version = '0.8.5'
7
+ s.author = 'Seth Vargo'
8
+ s.email = 'sethvargo@gmail.com'
9
+ s.homepage = 'https://github.com/sethvargo/powify'
10
+ s.summary = %q{Powify is an easy-to-use wrapper for 37 signal's pow}
11
+ s.description = %q{Powify provides an easy wrapper for use with 37 signal's pow. Use this gem to easily install and update pow server. Easily create, destroy, and manage pow apps.}
12
+
13
+ s.rubyforge_project = 'powify'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_runtime_dependency 'json'
21
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: powify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Seth Vargo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &70302583337720 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70302583337720
25
+ description: Powify provides an easy wrapper for use with 37 signal's pow. Use this
26
+ gem to easily install and update pow server. Easily create, destroy, and manage
27
+ pow apps.
28
+ email: sethvargo@gmail.com
29
+ executables:
30
+ - powify
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .document
35
+ - .gitignore
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE
39
+ - README.markdown
40
+ - Rakefile
41
+ - bin/powify
42
+ - lib/powify.rb
43
+ - lib/powify/app.rb
44
+ - lib/powify/client.rb
45
+ - lib/powify/core.rb
46
+ - lib/powify/server.rb
47
+ - lib/powify/utils.rb
48
+ - powify.gemspec
49
+ homepage: https://github.com/sethvargo/powify
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project: powify
69
+ rubygems_version: 1.8.15
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Powify is an easy-to-use wrapper for 37 signal's pow
73
+ test_files: []