invoker 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/invoker/parsers/option_parser.rb +7 -0
- data/lib/invoker/power/config.rb +6 -0
- data/lib/invoker/power/setup.rb +46 -6
- data/lib/invoker/runner.rb +6 -0
- data/lib/invoker/version.rb +1 -1
- data/readme.md +2 -85
- data/spec/invoker/power/setup_spec.rb +25 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDQxOTg1ZTE4N2EwYTUyMzA5MDhjNWUyNjZiY2NlMTI5MGFlMDdlYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjNiOWYwM2UzZDkwNmQ3ZGU0NDcwMGY5YTRlYmJhZTY5ZWRmMWIwYw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzQxY2VhODQxNzIwN2VlNmI1MmQzN2EzMDEwMWM3MmUyM2MwMDYwYzE1MzFj
|
10
|
+
OWIwMTViN2RkZDgyZmI3YWYwNjA0MDczZWU1MDcxMTUzM2NmZDZhNGIzOTEy
|
11
|
+
NDMyMWQzNjhkYzZlNzA3ODAwMmIzMTQ2MWZmNTI4MWQ2NGZlMjg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWE3Njc4Y2FkZTdhYTg4OGU4YzcyMmRkZjAwMGU1MjJhNWQxYTdiYmNiMDQw
|
14
|
+
ODFkNGVkZWYzMDcwZjViNzM2YjQyZmVkOTc0ZTczNDQzNDFhNDMyNDgyZmZk
|
15
|
+
ZDVkZGEwMDkxNmFiYjc2ZWVkNzM1ZWIzMTQ2MGRlYzA3ZjE3NzM=
|
@@ -32,6 +32,13 @@ module Invoker
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
command 'uninstall' do
|
36
|
+
banner "Usage : invoker uninstall \n Removes firewall rules created by setup"
|
37
|
+
run do |cmd_opts, cmd_args|
|
38
|
+
selected_command = OpenStruct.new(:command => 'uninstall')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
35
42
|
command 'list' do
|
36
43
|
banner "Usage : invoker list\n List processes managed by invoker"
|
37
44
|
run do |cmd_opts, cmd_args|
|
data/lib/invoker/power/config.rb
CHANGED
data/lib/invoker/power/setup.rb
CHANGED
@@ -7,11 +7,21 @@ module Invoker
|
|
7
7
|
FIREWALL_PLIST_FILE = "/Library/LaunchDaemons/com.codemancers.invoker.firewall.plist"
|
8
8
|
def self.install
|
9
9
|
installer = new
|
10
|
-
|
11
|
-
installer.
|
10
|
+
if Invoker.darwin?
|
11
|
+
if installer.check_if_setup_can_run?
|
12
|
+
installer.setup_invoker
|
13
|
+
else
|
14
|
+
Invoker::Logger.puts("The setup has been already run.".color(:red))
|
15
|
+
end
|
12
16
|
else
|
13
|
-
Invoker::Logger.puts("
|
17
|
+
Invoker::Logger.puts("Domain feature is currently not supported on systems other than OSX".color(:red))
|
14
18
|
end
|
19
|
+
installer
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.uninstall
|
23
|
+
installer = new
|
24
|
+
installer.uninstall_invoker
|
15
25
|
end
|
16
26
|
|
17
27
|
def setup_invoker
|
@@ -29,6 +39,18 @@ module Invoker
|
|
29
39
|
self
|
30
40
|
end
|
31
41
|
|
42
|
+
def uninstall_invoker
|
43
|
+
uninstall_invoker_flag = agree("Are you sure you want to uninstall firewall rules created by setup (y/n) : ")
|
44
|
+
|
45
|
+
if uninstall_invoker_flag
|
46
|
+
remove_resolver_file
|
47
|
+
unload_firewall_rule(true)
|
48
|
+
flush_dns_rules
|
49
|
+
Invoker::Power::Config.delete
|
50
|
+
Invoker::Logger.puts("Firewall rules were removed")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
32
54
|
def drop_to_normal_user
|
33
55
|
EventMachine.set_effective_user(ENV["SUDO_USER"])
|
34
56
|
end
|
@@ -61,18 +83,36 @@ module Invoker
|
|
61
83
|
raise
|
62
84
|
end
|
63
85
|
|
64
|
-
def
|
65
|
-
File.exists?(
|
86
|
+
def remove_resolver_file
|
87
|
+
if File.exists?(RESOLVER_FILE)
|
88
|
+
File.delete(RESOLVER_FILE)
|
89
|
+
end
|
90
|
+
rescue Errno::EACCES
|
91
|
+
Invoker::Logger.puts("Running uninstall requires root access, please rerun it with sudo".color(:red))
|
92
|
+
raise
|
93
|
+
end
|
94
|
+
|
95
|
+
def check_if_setup_can_run?
|
96
|
+
!File.exists?(Invoker::Power::Config::CONFIG_LOCATION)
|
66
97
|
end
|
67
98
|
|
68
99
|
def install_firewall(balancer_port)
|
69
100
|
File.open(FIREWALL_PLIST_FILE, "w") { |fl|
|
70
101
|
fl.write(plist_string(balancer_port))
|
71
102
|
}
|
72
|
-
|
103
|
+
unload_firewall_rule
|
104
|
+
load_firewall_rule
|
105
|
+
end
|
106
|
+
|
107
|
+
def load_firewall_rule
|
73
108
|
system("launchctl load -Fw #{FIREWALL_PLIST_FILE} 2>/dev/null")
|
74
109
|
end
|
75
110
|
|
111
|
+
def unload_firewall_rule(remove = false)
|
112
|
+
system("launchctl unload -w #{FIREWALL_PLIST_FILE} 2>/dev/null")
|
113
|
+
system("rm -rf #{FIREWALL_PLIST_FILE}") if remove
|
114
|
+
end
|
115
|
+
|
76
116
|
# Ripped from POW code
|
77
117
|
def plist_string(balancer_port)
|
78
118
|
plist =<<-EOD
|
data/lib/invoker/runner.rb
CHANGED
@@ -16,6 +16,8 @@ module Invoker
|
|
16
16
|
case selected_command.command
|
17
17
|
when 'setup'
|
18
18
|
setup_pow(selected_command)
|
19
|
+
when 'uninstall'
|
20
|
+
uninstall_pow(selected_command)
|
19
21
|
when 'start'
|
20
22
|
start_server(selected_command)
|
21
23
|
when 'add'
|
@@ -35,6 +37,10 @@ module Invoker
|
|
35
37
|
Invoker::Power::Setup.install()
|
36
38
|
end
|
37
39
|
|
40
|
+
def self.uninstall_pow(selected_command)
|
41
|
+
Invoker::Power::Setup.uninstall()
|
42
|
+
end
|
43
|
+
|
38
44
|
def self.start_server(selected_command)
|
39
45
|
config = Invoker::Parsers::Config.new(selected_command.file, selected_command.port)
|
40
46
|
Invoker.const_set(:CONFIG, config)
|
data/lib/invoker/version.rb
CHANGED
data/readme.md
CHANGED
@@ -11,92 +11,9 @@ First we need to install `invoker` gem to get command line utility called `invok
|
|
11
11
|
|
12
12
|
Currently it only works with Ruby 1.9.3 and 2.0.
|
13
13
|
|
14
|
-
|
15
|
-
`ini` file is included in the repo.
|
16
|
-
|
17
|
-
[rails]
|
18
|
-
directory = /home/gnufied/god_particle
|
19
|
-
command = zsh -c 'bundle exec rails s -p 5000'
|
20
|
-
|
21
|
-
[dj]
|
22
|
-
directory = /home/gnufied/god_particle
|
23
|
-
command = zsh -c 'bundle exec ruby script/delayed_job'
|
24
|
-
|
25
|
-
[events]
|
26
|
-
directory = /home/gnufied/god_particle
|
27
|
-
command = zsh -c 'bundle exec ruby script/event_server'
|
28
|
-
|
29
|
-
## Invoker as Pow alternative
|
30
|
-
|
31
|
-
Invoker now supports pow like `.dev` subdomain. It will automatically
|
32
|
-
make all your app servers defined on subdomain `label.dev`.
|
33
|
-
|
34
|
-
To make it work though, you need to run following command, just once from anywhere:
|
35
|
-
|
36
|
-
~> sudo invoker setup
|
37
|
-
|
38
|
-
Now because invoker is making your app server available on a subdomain. It requires
|
39
|
-
control over port on which your applications will be listening. This can be simply
|
40
|
-
done by replacing specific port number in `ini` file with `$PORT`. For example:
|
41
|
-
|
42
|
-
[spree]
|
43
|
-
directory = /home/gnufied/spree
|
44
|
-
command = zsh -c 'bundle exec rails s -p $PORT'
|
45
|
-
|
46
|
-
[api]
|
47
|
-
directory = /home/gnufied/api
|
48
|
-
command = zsh -c 'bundle exec rails s -p $PORT'
|
49
|
-
|
50
|
-
[events]
|
51
|
-
directory = /home/gnufied/god_particle
|
52
|
-
command = zsh -c 'bundle exec ruby script/event_server'
|
53
|
-
|
54
|
-
The subdomain feature won't work for apps which don't use `$PORT` placeholder.
|
55
|
-
|
56
|
-
## Running Invoker
|
57
|
-
|
58
|
-
After that you can start process manager via:
|
59
|
-
|
60
|
-
~> invoker start invoker.ini
|
61
|
-
|
62
|
-
Above command will start all your processes in one terminal with their stdout/stderr merged and labelled.
|
63
|
-
|
64
|
-
Now additionally you can control individual process by,
|
65
|
-
|
66
|
-
# Will try to stop running delayed job by sending SIGINT to the process
|
67
|
-
~> invoker remove dj
|
68
|
-
|
69
|
-
# If Process can't be killed by SIGINT send a custom signal
|
70
|
-
~> invoker remove dj -s 9
|
71
|
-
|
72
|
-
# add and start running
|
73
|
-
~> invoker add dj
|
74
|
-
|
75
|
-
# List currently running processes managed by invoker
|
76
|
-
~> invoker list
|
77
|
-
|
78
|
-
# Restart process given by command Label
|
79
|
-
~> invoker reload dj
|
80
|
-
|
81
|
-
# Restart process given by command label using specific signal for killing
|
82
|
-
~> invoker reload dj -s 9
|
83
|
-
|
84
|
-
You can also enable OSX notifications for crashed processes by installing `terminal-notifier` gem. It is not a dependency, but can be useful if something crashed and you weren't paying attention.
|
85
|
-
|
86
|
-
## Using with rbenv or rvm ##
|
87
|
-
|
88
|
-
The way `rbenv` and `rvm` work sometimes creates problems when you are trying to use a process supervisor like `invoker`. There are couple of things to keep in mind,
|
89
|
-
If you are running `invoker` with Ruby version x, but your application requires Ruby version Y:
|
90
|
-
|
91
|
-
* When using `rbenv`, you can define the command with environment variable `RBENV_VERSION=Y` and then start your application. In other words:
|
92
|
-
|
93
|
-
command = RBENV_VERSION=2.0.0-p0 zsh -c "bundle exec rails s"
|
94
|
-
|
95
|
-
* Unless version of Ruby using which you are running `invoker` command and version of Ruby you are using in the application is same, you almost always will want to use
|
96
|
-
`zsh -c` or `bash -c`. `RVM` in particular requires a login shell and hence sometimes you may have to use `bash -lc`. For example:
|
97
|
-
|
98
|
-
command = bash -lc "rvm 2.0.0-p0 do bundle exec rails s"
|
14
|
+
## Manual ##
|
99
15
|
|
16
|
+
Information about configuring and using Invoker can be found on - [Invoker Website](http://invoker.codemancers.com)
|
100
17
|
|
101
18
|
## Bug reports and Feature requests
|
102
19
|
|
@@ -2,6 +2,8 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe "Setup" do
|
4
4
|
before {
|
5
|
+
@original_verbosity = $VERBOSE
|
6
|
+
$VERBOSE = nil
|
5
7
|
@old_config = Invoker::Power::Config::CONFIG_LOCATION
|
6
8
|
Invoker::Power::Config.const_set(:CONFIG_LOCATION, "/tmp/.invoker")
|
7
9
|
|
@@ -24,6 +26,7 @@ describe "Setup" do
|
|
24
26
|
File.exists?(Invoker::Power::Setup::RESOLVER_FILE) &&
|
25
27
|
File.delete(Invoker::Power::Setup::RESOLVER_FILE)
|
26
28
|
Invoker::Power::Setup.const_set(:RESOLVER_FILE, @old_resolver)
|
29
|
+
$VERBOSE = @original_verbosity
|
27
30
|
}
|
28
31
|
|
29
32
|
describe "When no setup exists" do
|
@@ -42,6 +45,14 @@ describe "Setup" do
|
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
48
|
+
describe "setup on non osx systems" do
|
49
|
+
it "should not run setup" do
|
50
|
+
Invoker.expects(:ruby_platform).returns("i686-linux")
|
51
|
+
Invoker::Power::Setup.any_instance.expects(:check_if_setup_can_run?).never()
|
52
|
+
Invoker::Power::Setup.install
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
45
56
|
describe "when a setup file exists" do
|
46
57
|
it "should throw error about existing file" do
|
47
58
|
File.open(Invoker::Power::Config::CONFIG_LOCATION, "w") {|fl|
|
@@ -84,4 +95,18 @@ describe "Setup" do
|
|
84
95
|
end
|
85
96
|
end
|
86
97
|
end
|
98
|
+
|
99
|
+
describe "uninstalling firewall rules" do
|
100
|
+
it "should uninstall firewall rules and remove all files created by setup" do
|
101
|
+
setup = Invoker::Power::Setup.new
|
102
|
+
|
103
|
+
HighLine.any_instance.expects(:agree).returns(true)
|
104
|
+
setup.expects(:remove_resolver_file).once
|
105
|
+
setup.expects(:unload_firewall_rule).with(true).once
|
106
|
+
setup.expects(:flush_dns_rules).once
|
107
|
+
Invoker::Power::Config.expects(:delete).once
|
108
|
+
|
109
|
+
setup.uninstall_invoker
|
110
|
+
end
|
111
|
+
end
|
87
112
|
end
|