mybot 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/Botfile +7 -61
  2. data/CHANGELOG.md +2 -25
  3. data/README.md +72 -189
  4. data/lib/mybot.rb +20 -21
  5. data/lib/mybot/base.rb +6 -2
  6. data/lib/mybot/cli.rb +45 -5
  7. data/lib/mybot/command.rb +37 -28
  8. data/lib/mybot/fmt.rb +143 -52
  9. data/lib/mybot/helpers.rb +24 -0
  10. data/lib/mybot/installer.rb +31 -0
  11. data/lib/mybot/lib.rb +20 -59
  12. data/lib/mybot/libs.rb +31 -28
  13. data/lib/mybot/loader.rb +25 -0
  14. data/lib/mybot/node.rb +100 -47
  15. data/lib/mybot/nodes.rb +16 -0
  16. data/lib/mybot/tasks.rb +47 -11
  17. data/lib/mybot/template.rb +8 -8
  18. data/lib/mybot/templates.rb +15 -0
  19. data/lib/mybot/version.rb +1 -1
  20. data/vendor/lib/{core/.gitkeep → .gitkeep} +0 -0
  21. data/vendor/{recipes → plugins}/.gitkeep +0 -0
  22. data/vendor/{tpl/core → tasks}/.gitkeep +0 -0
  23. data/vendor/tpl/.gitkeep +0 -0
  24. metadata +11 -34
  25. data/lib/mybot/aws.rb +0 -54
  26. data/lib/mybot/commands.rb +0 -108
  27. data/lib/mybot/core-ext/array.rb +0 -9
  28. data/lib/mybot/core-ext/class.rb +0 -53
  29. data/lib/mybot/core-ext/kernel.rb +0 -21
  30. data/lib/mybot/messages.rb +0 -30
  31. data/lib/mybot/recipes.rb +0 -25
  32. data/lib/mybot/result.rb +0 -26
  33. data/lib/mybot/utils.rb +0 -7
  34. data/vendor/lib/core/fs.rb +0 -191
  35. data/vendor/lib/core/osx/git.rb +0 -31
  36. data/vendor/lib/core/osx/rails.rb +0 -31
  37. data/vendor/lib/core/osx/static.rb +0 -31
  38. data/vendor/lib/core/ubuntu/apache.rb +0 -42
  39. data/vendor/lib/core/ubuntu/apt.rb +0 -57
  40. data/vendor/lib/core/ubuntu/git.rb +0 -48
  41. data/vendor/lib/core/ubuntu/mysql.rb +0 -214
  42. data/vendor/lib/core/ubuntu/nginx.rb +0 -43
  43. data/vendor/lib/core/ubuntu/passenger.rb +0 -55
  44. data/vendor/lib/core/ubuntu/php.rb +0 -76
  45. data/vendor/lib/core/ubuntu/rails.rb +0 -105
  46. data/vendor/lib/core/ubuntu/ruby.rb +0 -166
  47. data/vendor/lib/core/ubuntu/service.rb +0 -30
  48. data/vendor/lib/core/ubuntu/static.rb +0 -50
  49. data/vendor/lib/core/ubuntu/users.rb +0 -76
  50. data/vendor/lib/core/ubuntu/vim.rb +0 -31
  51. data/vendor/tpl/core/ubuntu/apache/apache2.conf.erb +0 -80
  52. data/vendor/tpl/core/ubuntu/nginx/nginx.conf.erb +0 -72
  53. data/vendor/tpl/core/ubuntu/php/php.ini.erb +0 -1818
@@ -1,166 +0,0 @@
1
- module Core
2
- module Ubuntu
3
- class Ruby < Mybot::Lib
4
- RBENV_ROOT = "/usr/local/rbenv"
5
-
6
- def initialize(node)
7
- @node = node
8
- @node.use [
9
- "core/fs",
10
- "core/ubuntu/apt"
11
- ]
12
- end
13
-
14
- def system_installed?(options = {})
15
- options[:file] = "/usr/bin/ruby"
16
- @node.fs.exists?(options)
17
- end
18
-
19
- def system_install(options = {})
20
- options[:pkg] = "ruby"
21
- @node.apt.install(options)
22
- end
23
-
24
- def system_remove(options = {})
25
- options[:pkg] = "ruby"
26
- @node.apt.remove(options)
27
- end
28
-
29
- def rbenv_installed?(options = {})
30
- options[:file] = "/usr/bin/rbenv"
31
- @node.fs.exists?(options)
32
- end
33
-
34
- def rbenv_install(options = {})
35
- options[:pkg] = "rbenv"
36
- @node.apt.install(options)
37
-
38
- options[:pkg] = "ruby-build"
39
- @node.apt.install(options)
40
-
41
- options.delete(:file)
42
- options[:dir] = RBENV_ROOT
43
- @node.fs.create(options)
44
- end
45
-
46
- def rbenv_remove(options = {})
47
- options[:pkg] = "rbenv"
48
- @node.apt.remove(options)
49
-
50
- options[:pkg] = "ruby-build"
51
- @node.apt.remove(options)
52
-
53
- options[:dir] = RBENV_ROOT
54
- @node.fs.remove(options)
55
- end
56
-
57
- def rbenv_version_list(options = {})
58
- options[:env] ||= {
59
- "RBENV_ROOT" => RBENV_ROOT
60
- }
61
- options[:cmd] = "rbenv versions"
62
- versions = @node.run(options).stdout
63
- versions.split("\r\n").map { |v| v.strip }
64
- end
65
-
66
- def rbenv_version_installed?(options = {})
67
- error "ruby_version is required" unless options[:ruby_version]
68
-
69
- rbenv_version_list(options).include?(options[:ruby_version])
70
- end
71
-
72
- def rbenv_version_install(options = {})
73
- error "ruby_version is required" unless options[:ruby_version]
74
-
75
- options[:env] ||= {
76
- "RBENV_ROOT" => RBENV_ROOT
77
- }
78
-
79
- if options[:ruby_version].include?("1.8.7")
80
- options[:env]["CFLAGS"] = "-O2 "
81
- options[:env]["CFLAGS"] += "-fno-tree-dce "
82
- options[:env]["CFLAGS"] += "-fno-optimize-sibling-calls"
83
- end
84
-
85
- options[:cmd] = "rbenv install #{options[:ruby_version]}"
86
- @node.run(options)
87
- end
88
-
89
- def rbenv_version_remove(options = {})
90
- error "ruby_version is required" unless options[:ruby_version]
91
-
92
- options[:dir] = "#{RBENV_ROOT}/versions/#{options[:ruby_version]}"
93
- @node.fs.remove(options)
94
- end
95
-
96
- def rbenv_exec(options = {})
97
- error "ruby_version is required" unless options[:ruby_version]
98
- error "cmd is required" unless options[:cmd]
99
-
100
- options[:env] ||= {
101
- "RBENV_ROOT" => RBENV_ROOT,
102
- "RBENV_VERSION" => options[:ruby_version]
103
- }
104
-
105
- options[:cmd] = "rbenv exec #{options[:cmd]}"
106
- @node.run(options).stdout
107
- end
108
-
109
- def rbenv_gem_list(options = {})
110
- options[:cmd] = "gem list"
111
- gems = rbenv_exec(options)
112
- gems = gems.split("\r\n").reject do |g|
113
- g.strip == "" || g == "*** LOCAL GEMS ***"
114
- end.map do |g|
115
- parts = g.split("(")
116
- {
117
- :gem_name => parts[0].strip,
118
- :gem_versions => parts[1].split(",").map do |v|
119
- v.gsub(")", "").strip
120
- end
121
- }
122
- end
123
- end
124
-
125
- def rbenv_gem_installed?(options = {})
126
- error "gem_name is required" unless options[:gem_name]
127
-
128
- rbenv_gem_list(options).each do |g|
129
- if g[:gem_name] == options[:gem_name]
130
- if options[:gem_version]
131
- if g[:gem_versions].include?(options[:gem_version])
132
- return true
133
- end
134
- else
135
- return true
136
- end
137
- end
138
- end
139
-
140
- false
141
- end
142
-
143
- def rbenv_gem_install(options = {})
144
- error "gem_name is required" unless options[:gem_name]
145
-
146
- options[:cmd] = "gem install #{options[:gem_name]} --no-ri --no-rdoc"
147
- if options[:gem_version]
148
- options[:cmd] += " -v=#{options[:gem_version]}"
149
- end
150
-
151
- rbenv_exec(options)
152
- end
153
-
154
- def rbenv_gem_remove(options = {})
155
- error "gem is required" unless options[:gem_name]
156
-
157
- options[:cmd] = "gem uninstall #{options[:gem]} -Iax"
158
- if options[:gem_version]
159
- options[:cmd] += " -v=#{options[:gem_version]}"
160
- end
161
-
162
- rbenv_exec(options)
163
- end
164
- end
165
- end
166
- end
@@ -1,30 +0,0 @@
1
- module Core
2
- module Ubuntu
3
- class Service < Mybot::Lib
4
- def initialize(node)
5
- @node = node
6
- end
7
-
8
- def start(options = {})
9
- error "service is required" unless options[:service]
10
-
11
- options[:cmd] = "service #{options[:service]} start"
12
- @node.run(options)
13
- end
14
-
15
- def stop(options = {})
16
- error "service is required" unless options[:service]
17
-
18
- options[:cmd] = "service #{options[:service]} stop"
19
- @node.run(options)
20
- end
21
-
22
- def restart(options = {})
23
- error "service is required" unless options[:service]
24
-
25
- options[:cmd] = "service #{options[:service]} restart"
26
- @node.run(options)
27
- end
28
- end
29
- end
30
- end
@@ -1,50 +0,0 @@
1
- module Core
2
- module Ubuntu
3
- class Static < Mybot::Lib
4
- def initialize(node)
5
- @node = node
6
- @node.use [
7
- "core/fs"
8
- ]
9
- end
10
-
11
- def setup_deployment(options = {})
12
- error "app_name is required" unless options[:app_name]
13
-
14
- options[:dir] = "/home/#{options[:app_name]}/releases"
15
- @node.fs.require_created(options)
16
- end
17
-
18
- def deploy(options = {})
19
- error "app_name is required" unless options[:app_name]
20
- error "release is required" unless options[:release]
21
-
22
- releases_path = "/home/#{options[:app_name]}/releases"
23
- release_path = "#{releases_path}/#{options[:release]}"
24
- current_path = "/home/#{options[:app_name]}/current"
25
-
26
- # upload release archive
27
- options[:from] = options[:to] = "/tmp/#{options[:release]}.tar.gz"
28
- @node.fs.upload(options)
29
-
30
- # extract archive
31
- options[:to] = releases_path
32
- @node.fs.extract(options)
33
-
34
- # link current
35
- options[:dir] = current_path
36
- @node.fs.remove(options)
37
-
38
- options[:from] = release_path
39
- options[:to] = current_path
40
- @node.fs.link(options)
41
-
42
- # repair permissions
43
- options[:dir] = "/home/#{options[:app_name]}"
44
- options[:user] = options[:app_name]
45
- options[:group] = options[:app_name]
46
- @node.fs.chown(options)
47
- end
48
- end
49
- end
50
- end
@@ -1,76 +0,0 @@
1
- module Core
2
- module Ubuntu
3
- class Users < Mybot::Lib
4
- def initialize(node)
5
- @node = node
6
- end
7
-
8
- def list(options = {})
9
- options[:cmd] = "cat /etc/passwd | cut -d: -f1"
10
- out = @node.run(options).stdout
11
- out.split("\r\n")
12
- end
13
-
14
- def exists?(options = {})
15
- error "username is required" unless options[:username]
16
-
17
- list(options).include?(options[:username])
18
- end
19
-
20
- def create(options = {})
21
- error "username is required" unless options[:username]
22
- error "password is required" unless options[:password]
23
-
24
- options[:cmd] = "adduser #{options[:username]}"
25
- options[:fullname] ||= ""
26
- options[:room_number] ||= ""
27
- options[:work_phone] ||= ""
28
- options[:home_phone] ||= ""
29
-
30
- @node.run(options) do |cmd|
31
- cmd.on "Enter new UNIX password:" do
32
- cmd.write options[:password]
33
- end
34
-
35
- cmd.on "Retype new UNIX password:" do
36
- cmd.write options[:password]
37
- end
38
-
39
- cmd.on "Full Name []:" do
40
- cmd.write options[:fullname]
41
- end
42
-
43
- cmd.on "Room Number []:" do
44
- cmd.write options[:room_number]
45
- end
46
-
47
- cmd.on "Work Phone []:" do
48
- cmd.write options[:work_phone]
49
- end
50
-
51
- cmd.on "Home Phone []:" do
52
- cmd.write options[:home_phone]
53
- end
54
-
55
- cmd.on "Other []:" do
56
- cmd.write "user created by mybot"
57
- end
58
-
59
- cmd.on "Is the information correct? [Y/n]" do
60
- cmd.write "Y"
61
- end
62
- end
63
- end
64
-
65
- def remove(options = {})
66
- error "username is required" unless options[:username]
67
-
68
- options[:cmd] = "userdel #{options[:username]}"
69
- @node.run(options)
70
-
71
- options[:cmd] = "rm -rf /home/#{options[:username]}"
72
- @node.run(options)
73
- end
74
- end
75
- end
76
- end
@@ -1,31 +0,0 @@
1
- module Core
2
- module Ubuntu
3
- class Vim < Mybot::Lib
4
- def initialize(node)
5
- @node = node
6
- @node.use [
7
- "core/fs",
8
- "core/ubuntu/apt"
9
- ]
10
- end
11
-
12
- def installed?(options = {})
13
- options[:file] = "/usr/bin/vim"
14
- @node.fs.exists?(options)
15
- end
16
-
17
- def install(options = {})
18
- options[:pkg] = "vim"
19
- @node.apt.install(options)
20
- end
21
-
22
- def remove(options = {})
23
- options[:pkg] = "vim"
24
- @node.apt.remove(options)
25
- end
26
-
27
- def reconfigure(options = {})
28
- end
29
- end
30
- end
31
- end
@@ -1,80 +0,0 @@
1
- LockFile ${APACHE_LOCK_DIR}/accept.lock
2
- PidFile ${APACHE_PID_FILE}
3
- Timeout 300
4
- KeepAlive On
5
- MaxKeepAliveRequests 100
6
- KeepAliveTimeout 5
7
-
8
- <IfModule mpm_prefork_module>
9
- StartServers 5
10
- MinSpareServers 5
11
- MaxSpareServers 10
12
- MaxClients 150
13
- MaxRequestsPerChild 0
14
- </IfModule>
15
-
16
- <IfModule mpm_worker_module>
17
- StartServers 2
18
- MinSpareThreads 25
19
- MaxSpareThreads 75
20
- ThreadLimit 64
21
- ThreadsPerChild 25
22
- MaxClients 150
23
- MaxRequestsPerChild 0
24
- </IfModule>
25
-
26
- <IfModule mpm_event_module>
27
- StartServers 2
28
- MinSpareThreads 25
29
- MaxSpareThreads 75
30
- ThreadLimit 64
31
- ThreadsPerChild 25
32
- MaxClients 150
33
- MaxRequestsPerChild 0
34
- </IfModule>
35
-
36
- User ${APACHE_RUN_USER}
37
- Group ${APACHE_RUN_GROUP}
38
- AccessFileName .htaccess
39
-
40
- <Files ~ "^\.ht">
41
- Order allow,deny
42
- Deny from all
43
- Satisfy all
44
- </Files>
45
-
46
- DefaultType None
47
- HostnameLookups Off
48
- ErrorLog ${APACHE_LOG_DIR}/error.log
49
- LogLevel warn
50
-
51
- Include mods-enabled/*.load
52
- Include mods-enabled/*.conf
53
- Include ports.conf
54
-
55
- LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
56
- LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
57
- LogFormat "%h %l %u %t \"%r\" %>s %O" common
58
- LogFormat "%{Referer}i -> %U" referer
59
- LogFormat "%{User-agent}i" agent
60
-
61
- Include conf.d/
62
-
63
- <% if passenger[:enabled] %>
64
- LoadModule passenger_module <%= passenger[:rbenv_root] %>/versions/<%= passenger[:ruby_version] %>/lib/ruby/gems/<%= passenger[:ruby_system_version] %>/gems/passenger-<%= passenger[:version] %>/libout/apache2/mod_passenger.so
65
- PassengerRoot <%= passenger[:rbenv_root] %>/versions/<%= passenger[:ruby_version] %>/lib/ruby/gems/<%= passenger[:ruby_system_version] %>/gems/passenger-<%= passenger[:version] %>
66
- PassengerDefaultRuby <%= passenger[:rbenv_root] %>/versions/<%= passenger[:ruby_version] %>/bin/ruby
67
- <% end %>
68
-
69
- <% apps.each do |name, app| %>
70
- <% if app[:type] == "rails" %>
71
- <VirtualHost *:80>
72
- ServerName <%= app[:server_name] %>
73
- DocumentRoot <%= app[:path] %>/public
74
- <Directory <%= app[:path] %>/public>
75
- AllowOverride all
76
- Options -MultiViews
77
- </Directory>
78
- </VirtualHost>
79
- <% end %>
80
- <% end %>
@@ -1,72 +0,0 @@
1
- user www-data;
2
- worker_processes 4;
3
- pid /var/run/nginx.pid;
4
-
5
- events {
6
- worker_connections 768;
7
- # multi_accept on;
8
- }
9
-
10
- http {
11
- sendfile on;
12
- tcp_nopush on;
13
- tcp_nodelay on;
14
- keepalive_timeout 65;
15
- types_hash_max_size 2048;
16
-
17
- include /etc/nginx/mime.types;
18
- default_type application/octet-stream;
19
-
20
- access_log /var/log/nginx/access.log;
21
- error_log /var/log/nginx/error.log;
22
-
23
- gzip on;
24
- gzip_disable "msie6";
25
-
26
- #passenger_root /usr;
27
- #passenger_ruby /usr/bin/ruby;
28
-
29
- <% apps.each do |name, app| %>
30
- <% if app[:type] == "static" %>
31
- server {
32
- listen <%= app[:listen] %>;
33
- server_name <%= app[:server_name] %>;
34
- root <%= app[:root] %>;
35
-
36
- location / {
37
- try_files $uri $uri/ $uri.html index.html;
38
- }
39
- }
40
- <% elsif app[:type] == "php" %>
41
- server {
42
- listen <%= app[:listen] %>;
43
- server_name <%= app[:server_name] %>;
44
- root <%= app[:root] %>;
45
- index index.html index.php;
46
-
47
- location / {
48
- try_files $uri $uri/ $uri.html index.html;
49
- }
50
-
51
- location ~ \.php$ {
52
- fastcgi_split_path_info ^(.+\.php)(/.+)$;
53
- fastcgi_pass unix:/var/run/php5-fpm.sock;
54
- fastcgi_index index.php;
55
- include fastcgi_params;
56
- }
57
- }
58
- <% end %>
59
- <% if app[:redirect_to_www] %>
60
- server {
61
- server_name <%= app[:server_name_without_www] %>;
62
- rewrite ^(.*) http://<%= app[:server_name] %>$1 permanent;
63
- }
64
- <% end %>
65
- <% if app[:redirect_from_www] %>
66
- server {
67
- server_name <%= app[:server_name_with_www] %>;
68
- rewrite ^(.*) http://<%= app[:server_name] %>$1 permanent;
69
- }
70
- <% end %>
71
- <% end %>
72
- }