karo 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of karo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/karo/cli.rb +142 -80
- data/lib/karo/config.rb +3 -1
- data/lib/karo/templates/karo.yml +5 -0
- data/lib/karo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 742fafe45e1d1395f8f579a88b3fb4c537481c91
|
4
|
+
data.tar.gz: c85269a286f75601dfeb54083bc2bad8319b8a2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90bddb90a979c4a9cf146197f04c62d8839f1f1c73e3e89cc2afc776ad10d3820349fdbdd4ae32a76c927fe786b922c7f521598ede759234972be9c25955c4a2
|
7
|
+
data.tar.gz: 46b8df075a2839bd684d6879aa7c5244a1cb1715d07c3e6cae22c6fc68f958b7d3fc2dd74a3f95bc2d17e4611b720d4a38ed661744668263dfda30a625b5490e
|
data/CHANGELOG.md
CHANGED
data/lib/karo/cli.rb
CHANGED
@@ -8,29 +8,29 @@ require 'ap'
|
|
8
8
|
|
9
9
|
module Karo
|
10
10
|
|
11
|
-
|
11
|
+
class CLI < Thor
|
12
12
|
|
13
|
-
|
13
|
+
include Thor::Actions
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
class_option :config_file, type: :string, default: Config.default_file_name,
|
16
|
+
aliases: "-c", desc: "name of the file containing server configuration"
|
17
|
+
class_option :environment, aliases: "-e", desc: "server environment", default: "production"
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
desc "log", "displays server log for a given environment"
|
20
|
+
def log(name="")
|
21
|
+
configuration = Config.load_configuration(options)
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
path = File.join(configuration["path"], "shared/log/#{options["environment"]}.log")
|
24
|
+
ssh = "ssh #{configuration["user"]}@#{configuration["host"]}"
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
if name.eql?("")
|
27
|
+
cmd = "tail -f #{path}"
|
28
|
+
else
|
29
|
+
cmd = "tail #{path} | grep -A 10 -B 10 #{name}"
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
system "#{ssh} '#{cmd}'"
|
33
|
+
end
|
34
34
|
|
35
35
|
desc "cache [search, remove]", "find or clears a specific or all cache from shared/cache directory on the server"
|
36
36
|
subcommand "cache", Cache
|
@@ -41,68 +41,130 @@ module Karo
|
|
41
41
|
desc "db [pull, push]", "syncs MySQL database between server and localhost"
|
42
42
|
subcommand "db", Db
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
44
|
+
desc "config", "displays server configuration stored in a config file"
|
45
|
+
def config
|
46
|
+
configuration = Config.load_configuration(options)
|
47
|
+
|
48
|
+
ap configuration if configuration
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.source_root
|
52
|
+
File.dirname(__FILE__)
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "generate", "generate a sample configuration file to be used by karo [default is .karo.yml]"
|
56
|
+
def generate
|
57
|
+
config_file = File.expand_path(options[:config_file])
|
58
|
+
copy_file 'templates/karo.yml', config_file
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "ssh", "open ssh console for a given server environment"
|
62
|
+
def ssh
|
63
|
+
configuration = Config.load_configuration(options)
|
64
|
+
|
65
|
+
path = File.join(configuration["path"], "current")
|
66
|
+
ssh = "ssh #{configuration["user"]}@#{configuration["host"]} -t"
|
67
|
+
cmd = "cd #{path} && $SHELL"
|
68
|
+
system "#{ssh} '#{cmd}'"
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "console", "open rails console for a given server environment"
|
72
|
+
def console
|
73
|
+
configuration = Config.load_configuration(options)
|
74
|
+
|
75
|
+
path = File.join(configuration["path"], "current")
|
76
|
+
ssh = "ssh #{configuration["user"]}@#{configuration["host"]} -t"
|
77
|
+
cmd = "cd #{path} && bundle exec rails console #{options[:environment]}"
|
78
|
+
system "#{ssh} '#{cmd}'"
|
79
|
+
end
|
80
|
+
|
81
|
+
desc "command [COMMAND]", "run any command within a given server environment"
|
82
|
+
method_option :tty, aliases: "-t", desc: "force pseudo-tty allocation",
|
83
|
+
type: :boolean, default: true
|
84
|
+
long_desc <<-LONGDESC
|
85
|
+
`karo command [command]` or `karo cmd [command]`
|
86
|
+
|
87
|
+
will run the [COMMAND] passed on the server.
|
88
|
+
|
89
|
+
You can optionally pass --no-tty to disable ssh force pseudo-tty allocation
|
90
|
+
|
91
|
+
e.g. Display list of files on the staging server
|
92
|
+
|
93
|
+
> $ karo command ls -e staging --no-tty
|
94
|
+
|
95
|
+
CHANGELOG.md Gemfile.lock README.md
|
96
|
+
|
97
|
+
e.g. Run top command on the production server
|
98
|
+
|
99
|
+
> $ karo command top
|
100
|
+
|
101
|
+
> top - 17:14:06 up 219 days, 11:30, 1 user, load average: 0.28, 0.49, 0.47
|
102
|
+
|
103
|
+
You can also store custom commands for a given environment in the configuration file
|
104
|
+
|
105
|
+
e.g. .karo.yml
|
106
|
+
|
107
|
+
production:
|
108
|
+
|
109
|
+
--host: example.com
|
110
|
+
|
111
|
+
--user: deploy
|
112
|
+
|
113
|
+
--path: /data/app_name
|
114
|
+
|
115
|
+
--commands:
|
116
|
+
|
117
|
+
----memory: watch vmstat -sSM
|
118
|
+
|
119
|
+
----top_5_memory: ps aux | sort -nk +4 | tail
|
120
|
+
|
121
|
+
> $ karo cmd memory
|
122
|
+
|
123
|
+
> Every 2.0s: vmstat -sSM Tue Jul 2 17:18:16 2013
|
124
|
+
|
125
|
+
> 35840140 total memory
|
126
|
+
|
127
|
+
> 35308456 used memory
|
128
|
+
|
129
|
+
> 25224800 active memory
|
130
|
+
LONGDESC
|
131
|
+
def command(cmd)
|
132
|
+
configuration = Config.load_configuration(options)
|
133
|
+
|
134
|
+
ssh = "ssh #{configuration["user"]}@#{configuration["host"]}"
|
135
|
+
|
136
|
+
# Forces pseudo-tty allocation
|
137
|
+
ssh << " -t" if options[:tty]
|
138
|
+
|
139
|
+
if configuration["commands"] && configuration["commands"][cmd]
|
140
|
+
cmd = configuration["commands"][cmd]
|
141
|
+
end
|
142
|
+
|
143
|
+
system "#{ssh} '#{cmd}'"
|
144
|
+
end
|
145
|
+
map cmd: :command
|
146
|
+
|
147
|
+
desc "on [COMMAND]", "run any command within a given server environment"
|
148
|
+
method_option :tty, aliases: "-t", desc: "force pseudo-tty allocation",
|
149
|
+
type: :boolean, default: true
|
150
|
+
def on(cmd)
|
151
|
+
say "Deprecated and will be removed in version 2.0", :yellow
|
152
|
+
say "Please use 'command' instead", :yellow
|
153
|
+
invoke :command
|
154
|
+
end
|
155
|
+
|
156
|
+
desc "top", "run top command on a given server environment"
|
157
|
+
method_option :tty, aliases: "-t", desc: "force pseudo-tty allocation",
|
158
|
+
type: :boolean, default: true
|
159
|
+
def top
|
160
|
+
invoke :command, ["top"]
|
161
|
+
end
|
162
|
+
|
163
|
+
desc "version", "displays karo's current version"
|
164
|
+
def version
|
165
|
+
say Karo::VERSION
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
107
169
|
|
108
170
|
end
|
data/lib/karo/config.rb
CHANGED
@@ -22,7 +22,9 @@ module Karo
|
|
22
22
|
configuration
|
23
23
|
end
|
24
24
|
rescue Karo::NoConfigFileFoundError
|
25
|
-
|
25
|
+
puts "You can use 'karo generate' to generate a skeleton .karo.yml file"
|
26
|
+
puts "Please make sure that this configuration file exists? '#{config_file}'"
|
27
|
+
raise Thor::Error, "and run the command again"
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
data/lib/karo/templates/karo.yml
CHANGED
@@ -2,7 +2,12 @@ production:
|
|
2
2
|
host: example.com
|
3
3
|
user: deploy
|
4
4
|
path: /data/app_name
|
5
|
+
commands:
|
6
|
+
memory: watch vmstat -sSM
|
7
|
+
top_5_memory: ps aux | sort -nk +4 | tail
|
5
8
|
staging:
|
6
9
|
host: example.com
|
7
10
|
user: deploy
|
8
11
|
path: /data/app_name
|
12
|
+
commands:
|
13
|
+
memory: vmstat -sSM
|
data/lib/karo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: karo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rahul Trikha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|