superhosting 0.0.1 → 0.0.2
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/.gitignore +1 -0
- data/.travis.yml +13 -0
- data/Gemfile.lock +43 -7
- data/LICENSE.txt +4 -1
- data/Vagrantfile +6 -3
- data/bin/sx +6 -2
- data/bootstrap/etc/sx/default_model +1 -0
- data/bootstrap/etc/sx/models/base/container/docker/command +1 -0
- data/bootstrap/etc/sx/models/base/container/docker/user.erb +1 -0
- data/bootstrap/etc/sx/models/base/container/docker/volume.erb +2 -0
- data/bootstrap/etc/sx/models/bitrix_l/inherit +3 -0
- data/bootstrap/etc/sx/models/bitrix_m/inherit +3 -0
- data/bootstrap/etc/sx/models/bitrix_xl/inherit +3 -0
- data/bootstrap/etc/sx/models/common_bitrix/abstract +1 -0
- data/bootstrap/etc/sx/models/common_bitrix/container/mux +1 -0
- data/bootstrap/etc/sx/models/common_bitrix/inherit +1 -0
- data/bootstrap/etc/sx/models/common_bitrix/site/php/admin_value +2 -0
- data/bootstrap/etc/sx/models/common_bitrix/site/php/flag +1 -0
- data/bootstrap/etc/sx/models/common_bitrix/site/php/value +6 -0
- data/bootstrap/etc/sx/models/common_fcgi/abstract +1 -0
- data/bootstrap/etc/sx/models/common_fcgi/container/config.rb +6 -0
- data/bootstrap/etc/sx/models/common_fcgi/container/config_templates/supervisord.conf.erb +16 -0
- data/bootstrap/etc/sx/models/common_fcgi/container/docker/image +1 -0
- data/bootstrap/etc/sx/models/common_fcgi/container/docker/user.erb +1 -0
- data/bootstrap/etc/sx/models/common_fcgi/container/system_users +1 -0
- data/bootstrap/etc/sx/models/common_fcgi/site/config.rb +4 -0
- data/bootstrap/etc/sx/models/common_fcgi/site/config_templates/nginx_vhost.erb +21 -0
- data/bootstrap/etc/sx/models/common_joomla/abstract +1 -0
- data/bootstrap/etc/sx/models/common_joomla/site/php/flag +1 -0
- data/bootstrap/etc/sx/models/common_joomla/site/php/value +2 -0
- data/bootstrap/etc/sx/models/common_joomla_v2/abstract +1 -0
- data/bootstrap/etc/sx/models/common_joomla_v2/container/mux +1 -0
- data/bootstrap/etc/sx/models/common_joomla_v2/inherit +2 -0
- data/bootstrap/etc/sx/models/common_joomla_v3/abstract +1 -0
- data/bootstrap/etc/sx/models/common_joomla_v3/container/mux +1 -0
- data/bootstrap/etc/sx/models/common_joomla_v3/inherit +2 -0
- data/bootstrap/etc/sx/models/common_l/abstract +1 -0
- data/bootstrap/etc/sx/models/common_l/container/docker/blkio_weight +1 -0
- data/bootstrap/etc/sx/models/common_l/container/docker/cpu_period +1 -0
- data/bootstrap/etc/sx/models/common_l/container/docker/cpu_quota +1 -0
- data/bootstrap/etc/sx/models/common_l/container/docker/cpu_shares +1 -0
- data/bootstrap/etc/sx/models/common_l/container/docker/memory +1 -0
- data/bootstrap/etc/sx/models/common_l/container/docker/memory_swap +1 -0
- data/bootstrap/etc/sx/models/common_m/abstract +1 -0
- data/bootstrap/etc/sx/models/common_m/container/docker/blkio_weight +1 -0
- data/bootstrap/etc/sx/models/common_m/container/docker/cpu_period +1 -0
- data/bootstrap/etc/sx/models/common_m/container/docker/cpu_quota +1 -0
- data/bootstrap/etc/sx/models/common_m/container/docker/cpu_shares +1 -0
- data/bootstrap/etc/sx/models/common_m/container/docker/memory +1 -0
- data/bootstrap/etc/sx/models/common_m/container/docker/memory_swap +1 -0
- data/bootstrap/etc/sx/models/common_mail/abstract +1 -0
- data/bootstrap/etc/sx/models/common_mail/container/config.rb +12 -0
- data/bootstrap/etc/sx/models/common_mail/container/config_templates/postfwd_rules.erb +12 -0
- data/bootstrap/etc/sx/models/common_mail/container/config_templates/ssmtp.conf.erb +6 -0
- data/bootstrap/etc/sx/models/common_mail/container/mail/daily_limit +1 -0
- data/bootstrap/etc/sx/models/common_mail/container/mail/enabled +1 -0
- data/bootstrap/etc/sx/models/common_mail/container/mail/hourly_limit +1 -0
- data/bootstrap/etc/sx/models/common_php_l/abstract +1 -0
- data/bootstrap/etc/sx/models/common_php_l/container/mail/daily_limit +1 -0
- data/bootstrap/etc/sx/models/common_php_l/container/mail/hourly_limit +1 -0
- data/bootstrap/etc/sx/models/common_php_l/inherit +1 -0
- data/bootstrap/etc/sx/models/common_php_l/site/php/pm +1 -0
- data/bootstrap/etc/sx/models/common_php_l/site/php/pm_max_children +1 -0
- data/bootstrap/etc/sx/models/common_php_l/site/php/pm_max_spare_servers +1 -0
- data/bootstrap/etc/sx/models/common_php_l/site/php/pm_min_spare_servers +1 -0
- data/bootstrap/etc/sx/models/common_php_l/site/php/pm_start_servers +1 -0
- data/bootstrap/etc/sx/models/common_php_m/abstract +1 -0
- data/bootstrap/etc/sx/models/common_php_m/inherit +1 -0
- data/bootstrap/etc/sx/models/common_php_m/site/php/pm_max_children +1 -0
- data/bootstrap/etc/sx/models/common_php_s/abstract +1 -0
- data/bootstrap/etc/sx/models/common_php_s/inherit +1 -0
- data/bootstrap/etc/sx/models/common_php_xl/abstract +1 -0
- data/bootstrap/etc/sx/models/common_php_xl/container/mail/daily_limit +1 -0
- data/bootstrap/etc/sx/models/common_php_xl/container/mail/hourly_limit +1 -0
- data/bootstrap/etc/sx/models/common_php_xl/inherit +1 -0
- data/bootstrap/etc/sx/models/common_php_xl/site/php/pm +1 -0
- data/bootstrap/etc/sx/models/common_php_xl/site/php/pm_max_children +1 -0
- data/bootstrap/etc/sx/models/common_php_xl/site/php/pm_max_spare_servers +1 -0
- data/bootstrap/etc/sx/models/common_php_xl/site/php/pm_min_spare_servers +1 -0
- data/bootstrap/etc/sx/models/common_php_xl/site/php/pm_start_servers +1 -0
- data/bootstrap/etc/sx/models/common_php_xs/abstract +1 -0
- data/bootstrap/etc/sx/models/common_php_xs/container/mail/daily_limit +1 -0
- data/bootstrap/etc/sx/models/common_php_xs/container/mail/hourly_limit +1 -0
- data/bootstrap/etc/sx/models/common_php_xs/inherit +1 -0
- data/bootstrap/etc/sx/models/common_php_xs/site/php/pm_max_children +1 -0
- data/bootstrap/etc/sx/models/common_s/abstract +1 -0
- data/bootstrap/etc/sx/models/common_s/container/docker/blkio_weight +1 -0
- data/bootstrap/etc/sx/models/common_s/container/docker/cpu_period +1 -0
- data/bootstrap/etc/sx/models/common_s/container/docker/cpu_quota +1 -0
- data/bootstrap/etc/sx/models/common_s/container/docker/cpu_shares +1 -0
- data/bootstrap/etc/sx/models/common_s/container/docker/memory +1 -0
- data/bootstrap/etc/sx/models/common_s/container/docker/memory_swap +1 -0
- data/bootstrap/etc/sx/models/common_symfony/abstract +1 -0
- data/bootstrap/etc/sx/models/common_symfony/container/mux +1 -0
- data/bootstrap/etc/sx/models/common_symfony/container/system_users +1 -0
- data/bootstrap/etc/sx/models/common_symfony/inherit +1 -0
- data/bootstrap/etc/sx/models/common_symfony/site/php/flag +3 -0
- data/bootstrap/etc/sx/models/common_symfony/site/php/user +1 -0
- data/bootstrap/etc/sx/models/common_symfony/site/use_apache +1 -0
- data/bootstrap/etc/sx/models/common_xl/abstract +1 -0
- data/bootstrap/etc/sx/models/common_xl/container/docker/blkio_weight +1 -0
- data/bootstrap/etc/sx/models/common_xl/container/docker/cpu_shares +1 -0
- data/bootstrap/etc/sx/models/common_xl/container/docker/memory +1 -0
- data/bootstrap/etc/sx/models/common_xl/container/docker/memory_swap +1 -0
- data/bootstrap/etc/sx/models/common_xs/abstract +1 -0
- data/bootstrap/etc/sx/models/common_xs/container/docker/blkio_weight +1 -0
- data/bootstrap/etc/sx/models/common_xs/container/docker/cpu_period +1 -0
- data/bootstrap/etc/sx/models/common_xs/container/docker/cpu_quota +1 -0
- data/bootstrap/etc/sx/models/common_xs/container/docker/cpu_shares +1 -0
- data/bootstrap/etc/sx/models/common_xs/container/docker/memory +1 -0
- data/bootstrap/etc/sx/models/common_xs/container/docker/memory_swap +1 -0
- data/bootstrap/etc/sx/models/fcgi_l/inherit +3 -0
- data/bootstrap/etc/sx/models/fcgi_m/inherit +3 -0
- data/bootstrap/etc/sx/models/fcgi_s/inherit +3 -0
- data/bootstrap/etc/sx/models/fcgi_xl/inherit +3 -0
- data/bootstrap/etc/sx/models/joomla_v2_l/inherit +3 -0
- data/bootstrap/etc/sx/models/joomla_v2_m/inherit +3 -0
- data/bootstrap/etc/sx/models/joomla_v2_s/inherit +3 -0
- data/bootstrap/etc/sx/models/joomla_v2_xs/inherit +3 -0
- data/bootstrap/etc/sx/models/joomla_v3_l/inherit +3 -0
- data/bootstrap/etc/sx/models/joomla_v3_m/inherit +3 -0
- data/bootstrap/etc/sx/models/joomla_v3_s/inherit +3 -0
- data/bootstrap/etc/sx/models/joomla_v3_xs/inherit +3 -0
- data/bootstrap/etc/sx/models/symfony_l/inherit +3 -0
- data/bootstrap/etc/sx/models/symfony_m/inherit +3 -0
- data/bootstrap/etc/sx/models/symfony_xl/inherit +3 -0
- data/bootstrap/etc/sx/models/test/container/config.rb +4 -0
- data/bootstrap/etc/sx/models/test/container/config_templates/supervisord.conf.erb +16 -0
- data/bootstrap/etc/sx/models/test/container/docker/blkio_weight +1 -0
- data/bootstrap/etc/sx/models/test/container/docker/command +1 -0
- data/bootstrap/etc/sx/models/test/container/docker/cpu_period +1 -0
- data/bootstrap/etc/sx/models/test/container/docker/cpu_quota +1 -0
- data/bootstrap/etc/sx/models/test/container/docker/cpu_shares +1 -0
- data/bootstrap/etc/sx/models/test/container/docker/image +1 -0
- data/bootstrap/etc/sx/models/test/container/docker/memory +1 -0
- data/bootstrap/etc/sx/models/test/container/docker/memory_swap +1 -0
- data/bootstrap/etc/sx/models/test/container/docker/user.erb +1 -0
- data/bootstrap/etc/sx/models/test/container/docker/volume.erb +2 -0
- data/bootstrap/etc/sx/models/test/container/system_users +1 -0
- data/bootstrap/etc/sx/models/test/site/config.rb +4 -0
- data/bootstrap/etc/sx/models/test/site/config_templates/nginx_vhost.erb +21 -0
- data/bootstrap/etc/sx/models/test_with_mux/container/mux +1 -0
- data/bootstrap/etc/sx/models/test_with_mux/inherit +1 -0
- data/bootstrap/etc/sx/muxs/base/docker/command +1 -0
- data/bootstrap/etc/sx/muxs/php-5.3/container/docker/image +1 -0
- data/bootstrap/etc/sx/muxs/php-5.3/docker/image +1 -0
- data/bootstrap/etc/sx/muxs/php-5.3/inherit +2 -0
- data/bootstrap/etc/sx/muxs/php-5.5/container/docker/image +1 -0
- data/bootstrap/etc/sx/muxs/php-5.5/docker/image +1 -0
- data/bootstrap/etc/sx/muxs/php-5.5/inherit +2 -0
- data/bootstrap/etc/sx/muxs/php-5.6/container/docker/image +1 -0
- data/bootstrap/etc/sx/muxs/php-5.6/docker/image +1 -0
- data/bootstrap/etc/sx/muxs/php-5.6/inherit +2 -0
- data/bootstrap/etc/sx/muxs/php/abstract +1 -0
- data/bootstrap/etc/sx/muxs/php/docker/pid +1 -0
- data/bootstrap/etc/sx/muxs/php/docker/privileged +1 -0
- data/bootstrap/etc/sx/muxs/php/docker/volume +3 -0
- data/bootstrap/etc/sx/muxs/php/site/config.rb +10 -0
- data/bootstrap/etc/sx/muxs/php/site/config_templates/apache_vhost.erb +26 -0
- data/bootstrap/etc/sx/muxs/php/site/config_templates/nginx_vhost.erb +39 -0
- data/bootstrap/etc/sx/muxs/php/site/config_templates/php_fpm_pool.erb +22 -0
- data/bootstrap/etc/sx/muxs/php/site/php/pm +1 -0
- data/bootstrap/etc/sx/muxs/php/site/php/pm_max_children +1 -0
- data/bootstrap/etc/sx/muxs/php/site/use_apache +1 -0
- data/bootstrap/etc/sx/muxs/test/container/docker/image +1 -0
- data/bootstrap/etc/sx/muxs/test/docker/command +1 -0
- data/bootstrap/etc/sx/muxs/test/docker/image +1 -0
- data/bootstrap/etc/sx/muxs/test/inherit +1 -0
- data/bootstrap/etc/sx/password_strength +1 -0
- data/bootstrap/etc/sx/smtp_hostname +1 -0
- data/dockerfile/almost_base +19 -0
- data/dockerfile/base +18 -0
- data/dockerfile/mux +6 -0
- data/lib/superhosting.rb +39 -5
- data/lib/superhosting/base.rb +15 -21
- data/lib/superhosting/cli/base.rb +56 -40
- data/lib/superhosting/cli/cmd/admin_add.rb +5 -0
- data/lib/superhosting/cli/cmd/admin_container_list.rb +4 -0
- data/lib/superhosting/cli/cmd/admin_list.rb +11 -0
- data/lib/superhosting/cli/cmd/admin_passwd.rb +4 -0
- data/lib/superhosting/cli/cmd/container_admin_list.rb +4 -0
- data/lib/superhosting/cli/cmd/container_inspect.rb +11 -0
- data/lib/superhosting/cli/cmd/container_list.rb +18 -0
- data/lib/superhosting/cli/cmd/container_reconfigure.rb +11 -0
- data/lib/superhosting/cli/cmd/container_rename.rb +16 -0
- data/lib/superhosting/cli/cmd/model_list.rb +11 -0
- data/lib/superhosting/cli/cmd/{container_reconfig.rb → model_reconfigure.rb} +1 -1
- data/lib/superhosting/cli/cmd/model_tree.rb +30 -0
- data/lib/superhosting/cli/cmd/model_update.rb +11 -0
- data/lib/superhosting/cli/cmd/mux_reconfigure.rb +11 -0
- data/lib/superhosting/cli/cmd/repair.rb +8 -0
- data/lib/superhosting/cli/cmd/site_container.rb +15 -0
- data/lib/superhosting/cli/cmd/site_inspect.rb +11 -0
- data/lib/superhosting/cli/cmd/site_list.rb +35 -0
- data/lib/superhosting/cli/cmd/site_name.rb +15 -0
- data/lib/superhosting/cli/cmd/site_reconfigure.rb +11 -0
- data/lib/superhosting/cli/cmd/site_rename.rb +4 -0
- data/lib/superhosting/cli/cmd/user_add.rb +11 -5
- data/lib/superhosting/cli/cmd/user_change.rb +12 -6
- data/lib/superhosting/cli/cmd/user_list.rb +7 -0
- data/lib/superhosting/cli/cmd/user_passwd.rb +9 -0
- data/lib/superhosting/composite_mapper.rb +12 -0
- data/lib/superhosting/composite_mapper/base.rb +17 -0
- data/lib/superhosting/composite_mapper/container.rb +9 -0
- data/lib/superhosting/composite_mapper/site.rb +13 -0
- data/lib/superhosting/config/net_status.yml +122 -0
- data/lib/superhosting/config_executor.rb +12 -0
- data/lib/superhosting/{script_executor → config_executor}/base.rb +6 -5
- data/lib/superhosting/config_executor/container.rb +69 -0
- data/lib/superhosting/config_executor/site.rb +18 -0
- data/lib/superhosting/controller/admin.rb +84 -4
- data/lib/superhosting/controller/admin/container.rb +62 -2
- data/lib/superhosting/controller/base.rb +18 -0
- data/lib/superhosting/controller/container.rb +185 -122
- data/lib/superhosting/controller/container/admin.rb +25 -3
- data/lib/superhosting/controller/container/states.rb +296 -0
- data/lib/superhosting/controller/model.rb +62 -0
- data/lib/superhosting/controller/mux.rb +88 -0
- data/lib/superhosting/controller/mysql.rb +2 -2
- data/lib/superhosting/controller/site.rb +217 -72
- data/lib/superhosting/controller/site/alias.rb +32 -6
- data/lib/superhosting/controller/site/states.rb +41 -0
- data/lib/superhosting/controller/user.rb +233 -4
- data/lib/superhosting/docker_api.rb +170 -6
- data/lib/superhosting/helper/cmd.rb +40 -0
- data/lib/superhosting/helper/config.rb +80 -0
- data/lib/superhosting/helper/file.rb +56 -0
- data/lib/superhosting/helper/i18n.rb +13 -0
- data/lib/superhosting/helper/logger.rb +136 -0
- data/lib/superhosting/helper/states.rb +69 -0
- data/lib/superhosting/helpers.rb +5 -21
- data/lib/superhosting/mapper_inheritance/base.rb +16 -0
- data/lib/superhosting/mapper_inheritance/model.rb +96 -0
- data/lib/superhosting/mapper_inheritance/mux.rb +49 -0
- data/lib/superhosting/patches/path_mapper/dir_node.rb +23 -0
- data/lib/superhosting/patches/path_mapper/file_node.rb +47 -0
- data/lib/superhosting/patches/path_mapper/null_node.rb +35 -0
- data/lib/superhosting/patches/string/punycode.rb +21 -0
- data/lib/superhosting/version.rb +1 -1
- data/provision/bootstrap.sh +11 -0
- data/provision/docker.sh +25 -0
- data/provision/pam_docker.sh +5 -0
- data/{bootstrap.sh → provision/vagrant.sh} +5 -8
- data/superhosting.gemspec +14 -3
- metadata +368 -12
- data/lib/superhosting/script_executor/container.rb +0 -36
- data/lib/superhosting/script_executor/site.rb +0 -13
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
module Superhosting
|
|
2
2
|
class DockerApi
|
|
3
|
+
include Helper::Cmd
|
|
4
|
+
include Helper::Logger
|
|
5
|
+
|
|
6
|
+
AVAILABLE_DOCKER_OPTIONS = [:user, :cpu_period, :cpu_quota, :cpu_shares, :memory, :memory_swap]
|
|
7
|
+
|
|
3
8
|
def initialize(**kwargs)
|
|
4
9
|
@socket = kwargs[:socket] || '/var/run/docker.sock'
|
|
5
10
|
end
|
|
@@ -12,20 +17,179 @@ module Superhosting
|
|
|
12
17
|
JSON.load(resp.body) if resp.status == 200
|
|
13
18
|
end
|
|
14
19
|
|
|
20
|
+
def image_info(name)
|
|
21
|
+
resp_if_success raw_connection.request(method: :get, path: "/images/#{name}/json")
|
|
22
|
+
end
|
|
23
|
+
|
|
15
24
|
def container_info(name)
|
|
16
25
|
resp_if_success raw_connection.request(method: :get, path: "/containers/#{name}/json")
|
|
17
26
|
end
|
|
18
27
|
|
|
19
|
-
def
|
|
20
|
-
resp_if_success raw_connection.request(method: :
|
|
28
|
+
def container_list
|
|
29
|
+
resp_if_success raw_connection.request(method: :get, path: '/containers/json')
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def container_kill!(name)
|
|
33
|
+
self.debug_operation(desc: { code: :container, data: { name: name } }) do |&blk|
|
|
34
|
+
self.with_dry_run do |dry_run|
|
|
35
|
+
self.storage.delete(name) if dry_run
|
|
36
|
+
resp_if_success raw_connection.request(method: :post, path: "/containers/#{name}/kill") unless dry_run
|
|
37
|
+
end
|
|
38
|
+
blk.call(code: :killed)
|
|
39
|
+
end
|
|
21
40
|
end
|
|
22
41
|
|
|
23
|
-
def container_rm(name)
|
|
24
|
-
|
|
42
|
+
def container_rm!(name)
|
|
43
|
+
self.debug_operation(desc: { code: :container, data: { name: name } }) do |&blk|
|
|
44
|
+
self.with_dry_run do |dry_run|
|
|
45
|
+
self.storage.delete(name) if dry_run
|
|
46
|
+
resp_if_success raw_connection.request(method: :delete, path: "/containers/#{name}") unless dry_run
|
|
47
|
+
end
|
|
48
|
+
blk.call(code: :removed)
|
|
49
|
+
end
|
|
25
50
|
end
|
|
26
51
|
|
|
27
|
-
def
|
|
28
|
-
|
|
52
|
+
def container_stop!(name)
|
|
53
|
+
self.debug_operation(desc: { code: :container, data: { name: name } }) do |&blk|
|
|
54
|
+
self.with_dry_run do |dry_run|
|
|
55
|
+
self.storage[name] = 'exited' if dry_run
|
|
56
|
+
resp_if_success raw_connection.request(method: :post, path: "/containers/#{name}/stop") unless dry_run
|
|
57
|
+
end
|
|
58
|
+
blk.call(code: :stopped)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def container_start!(name)
|
|
63
|
+
self.debug_operation(desc: { code: :container, data: { name: name } }) do |&blk|
|
|
64
|
+
self.with_dry_run do |dry_run|
|
|
65
|
+
self.storage[name] = 'running' if dry_run
|
|
66
|
+
resp_if_success raw_connection.request(method: :post, path: "/containers/#{name}/start") unless dry_run
|
|
67
|
+
end
|
|
68
|
+
blk.call(code: :started)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def container_pause!(name)
|
|
73
|
+
self.debug_operation(desc: { code: :container, data: { name: name } }) do |&blk|
|
|
74
|
+
self.with_dry_run do |dry_run|
|
|
75
|
+
self.storage[name] = 'paused' if dry_run
|
|
76
|
+
resp_if_success raw_connection.request(method: :post, path: "/containers/#{name}/pause") unless dry_run
|
|
77
|
+
end
|
|
78
|
+
blk.call(code: :paused)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def container_unpause!(name)
|
|
83
|
+
self.debug_operation(desc: { code: :container, data: { name: name } }) do |&blk|
|
|
84
|
+
self.with_dry_run do |dry_run|
|
|
85
|
+
self.storage[name] = 'running' if dry_run
|
|
86
|
+
resp_if_success raw_connection.request(method: :post, path: "/containers/#{name}/unpause") unless dry_run
|
|
87
|
+
end
|
|
88
|
+
blk.call(code: :unpaused)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def container_restart!(name)
|
|
93
|
+
self.debug_operation(desc: { code: :container, data: { name: name } }) do |&blk|
|
|
94
|
+
self.with_dry_run do |dry_run|
|
|
95
|
+
resp_if_success raw_connection.request(method: :post, path: "/containers/#{name}/restart") unless dry_run
|
|
96
|
+
self.storage[name] = 'running' if dry_run
|
|
97
|
+
end
|
|
98
|
+
blk.call(code: :restarted)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def container_rm_inactive!(name)
|
|
103
|
+
self.container_rm!(name) if self.container_exists?(name) and !self.container_running?(name)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def container_status?(name, status)
|
|
107
|
+
self.with_dry_run do |dry_run|
|
|
108
|
+
return true if dry_run and self.storage[name] == status
|
|
109
|
+
resp = container_info(name)
|
|
110
|
+
if resp.nil?
|
|
111
|
+
false
|
|
112
|
+
else
|
|
113
|
+
resp['State'][status.capitalize]
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def container_running?(name)
|
|
119
|
+
self.with_dry_run do |dry_run|
|
|
120
|
+
return true if dry_run and self.storage[name] == 'running'
|
|
121
|
+
resp = container_info(name)
|
|
122
|
+
if resp.nil?
|
|
123
|
+
false
|
|
124
|
+
else
|
|
125
|
+
resp['State']['Running'] and %w(Restarting Paused OOMKilled Dead).all? {|c| !resp['State'][c] }
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def container_not_running?(name)
|
|
131
|
+
!container_running?(name)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def container_restarting?(name)
|
|
135
|
+
container_status?(name, 'restarting')
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def container_paused?(name)
|
|
139
|
+
container_status?(name, 'paused')
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def container_exited?(name)
|
|
143
|
+
container_status?(name, 'exited')
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def container_dead?(name)
|
|
147
|
+
container_status?(name, 'dead')
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def container_not_exists?(name)
|
|
151
|
+
!container_exists?(name)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def container_exists?(name)
|
|
155
|
+
self.with_dry_run do |dry_run|
|
|
156
|
+
return true if dry_run and self.storage.key? name
|
|
157
|
+
container_info(name).nil? ? false : true
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def container_image?(name, image)
|
|
162
|
+
container = container_info(name)
|
|
163
|
+
image = image_info(image)
|
|
164
|
+
|
|
165
|
+
if container.nil? or image.nil?
|
|
166
|
+
false
|
|
167
|
+
else
|
|
168
|
+
container['Image'] == image['Id']
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def container_run(name, options, image, command)
|
|
173
|
+
cmd = "docker run --detach --name #{name} #{options.join(' ')} #{image} #{command}"
|
|
174
|
+
self.debug_operation(desc: { code: :container, data: { name: name } }) do |&blk|
|
|
175
|
+
self.with_dry_run do |dry_run|
|
|
176
|
+
self.storage[name] = 'running' if dry_run
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
self.command!(cmd).tap do
|
|
180
|
+
blk.call(code: :added)
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def grab_container_options(command_options)
|
|
186
|
+
options = []
|
|
187
|
+
AVAILABLE_DOCKER_OPTIONS.map do |k|
|
|
188
|
+
unless (value = command_options[k]).nil?
|
|
189
|
+
value.lines.each {|val| options << "--#{k.to_s.sub('_', '-')} #{val}" }
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
options
|
|
29
193
|
end
|
|
30
194
|
end
|
|
31
195
|
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Superhosting
|
|
2
|
+
module Helper
|
|
3
|
+
module Cmd
|
|
4
|
+
def command!(*command_args, **kwargs)
|
|
5
|
+
self._command(*command_args, **kwargs) do |cmd|
|
|
6
|
+
raise NetStatus::Exception.new(error: :error, code: :command_with_error, data: { error: [cmd.stdout, cmd.stderr].join("\n") })
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def command(*command_args, **kwargs)
|
|
11
|
+
self._command(command_args, **kwargs)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def _command(*command_args, debug: true, logger: nil, &b)
|
|
15
|
+
self.with_logger(logger: logger) do
|
|
16
|
+
desc = { code: :command, data: { command: command_args.join } }
|
|
17
|
+
if debug
|
|
18
|
+
self.debug_operation(desc: desc) do |&blk|
|
|
19
|
+
self._command_without_debug(*command_args, &b)
|
|
20
|
+
blk.call(code: :ok)
|
|
21
|
+
end
|
|
22
|
+
else
|
|
23
|
+
self._command_without_debug(*command_args, &b)
|
|
24
|
+
end
|
|
25
|
+
{} # net_status
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def _command_without_debug(*command_args)
|
|
30
|
+
self.with_dry_run do |dry_run|
|
|
31
|
+
unless dry_run
|
|
32
|
+
cmd = Mixlib::ShellOut.new(*command_args)
|
|
33
|
+
cmd.run_command
|
|
34
|
+
yield cmd if block_given? and !cmd.status.success?
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
module Superhosting
|
|
2
|
+
module Helper
|
|
3
|
+
module Config
|
|
4
|
+
def configure(name:)
|
|
5
|
+
self._config(name: name, on_reconfig: false, on_config: true)
|
|
6
|
+
{}
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def unconfigure(name:)
|
|
10
|
+
case self.index[name][:mapper].parent.name
|
|
11
|
+
when 'containers'
|
|
12
|
+
registry_mapper = self.index[name][:mapper].lib.registry.container
|
|
13
|
+
when 'sites'
|
|
14
|
+
registry_mapper = self.index[name][:container_mapper].lib.registry.sites.f(name)
|
|
15
|
+
else raise NetStatus::Exception, { error: :logical_error, code: :mapper_type_not_supported, data: { name: type } }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
unless registry_mapper.nil?
|
|
19
|
+
registry_mapper.lines.each {|path| PathMapper.new(path).delete! }
|
|
20
|
+
registry_mapper.delete!
|
|
21
|
+
end
|
|
22
|
+
{}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def apply(name:)
|
|
26
|
+
self._config(name: name, on_reconfig: true, on_config: false)
|
|
27
|
+
{}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def unapply(name:)
|
|
31
|
+
apply(name: name)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def configure_with_apply(name:)
|
|
35
|
+
self._config(name: name, on_reconfig: true, on_config: true)
|
|
36
|
+
{}
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def unconfigure_with_unapply(name:)
|
|
40
|
+
self.unconfigure(name: name)
|
|
41
|
+
self.unapply(name: name)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def reconfig(name:)
|
|
45
|
+
self.unconfigure(name: name)
|
|
46
|
+
self.configure(name: name)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def _config(name:, on_reconfig:, on_config:)
|
|
50
|
+
mapper = self.index[name][:mapper]
|
|
51
|
+
options = self._config_options(name: name, on_reconfig: on_reconfig, on_config: on_config)
|
|
52
|
+
registry_mapper = options.delete(:registry_mapper)
|
|
53
|
+
registry_files = []
|
|
54
|
+
|
|
55
|
+
mapper.f('config.rb', overlay: false).reverse.each do |config|
|
|
56
|
+
ex = ConfigExecutor.new(options)
|
|
57
|
+
ex.execute(config)
|
|
58
|
+
ex.run_commands
|
|
59
|
+
registry_files += ex.registry_files
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
self._save_registry!(registry_mapper, registry_files) if on_config
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def _config_options(name:, on_reconfig:, on_config:)
|
|
66
|
+
{}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def _save_registry!(registry_mapper, registry_files)
|
|
70
|
+
old_configs = registry_mapper.lines
|
|
71
|
+
unless (old_configs = old_configs - registry_files).empty?
|
|
72
|
+
self.debug_block(desc: { code: :deleting_old_configs }) do
|
|
73
|
+
old_configs.each { |file| PathMapper.new(file).delete! }
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
registry_mapper.override!(registry_files.join("\n"))
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module Superhosting
|
|
2
|
+
module Helper
|
|
3
|
+
module File
|
|
4
|
+
def safe_link!(path_to, path)
|
|
5
|
+
self.debug_operation(desc: { code: :symlink, data: { path_to: path_to, path: path } }) do |&blk|
|
|
6
|
+
if ::File.exist? path
|
|
7
|
+
blk.call(code: :ok)
|
|
8
|
+
else
|
|
9
|
+
self.with_dry_run do |dry_run|
|
|
10
|
+
::File.symlink(path_to, path) unless dry_run
|
|
11
|
+
blk.call(code: :created)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def safe_unlink!(path)
|
|
18
|
+
if ::File.exist? path
|
|
19
|
+
self.debug_operation(desc: { code: :symlink, data: { path: path } }) do |&blk|
|
|
20
|
+
self.with_dry_run do |dry_run|
|
|
21
|
+
::File.unlink(path) unless dry_run
|
|
22
|
+
blk.call(code: :deleted)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def chown_r!(user, group, path)
|
|
29
|
+
self.debug_operation(desc: { code: :chown_r, data: { user: user, group: group, path: path } }) do |&blk|
|
|
30
|
+
self.with_dry_run do |dry_run|
|
|
31
|
+
FileUtils.chown_R(user, group, path) unless dry_run
|
|
32
|
+
blk.call(code: :ok)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def chown!(user, group, path)
|
|
38
|
+
self.debug_operation(desc: { code: :chown, data: { user: user, group: group, path: path } }) do |&blk|
|
|
39
|
+
self.with_dry_run do |dry_run|
|
|
40
|
+
FileUtils.chown(user, group, path) unless dry_run
|
|
41
|
+
blk.call(code: :ok)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def chmod!(mode, path)
|
|
47
|
+
self.debug_operation(desc: { code: :chmod, data: { mode: mode, path: path } }) do |&blk|
|
|
48
|
+
self.with_dry_run do |dry_run|
|
|
49
|
+
FileUtils.chmod(mode, path) unless dry_run
|
|
50
|
+
blk.call(code: :ok)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Superhosting
|
|
2
|
+
module Helper
|
|
3
|
+
module I18n
|
|
4
|
+
def i18n_initialize
|
|
5
|
+
::I18n.load_path << "#{::File.dirname(::File.dirname(__FILE__))}/config/net_status.yml"
|
|
6
|
+
::I18n.reload!
|
|
7
|
+
::I18n.locale = :en
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
Superhosting::Helper::I18n.send(:extend, Superhosting::Helper::I18n)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
module Superhosting
|
|
2
|
+
module Helper
|
|
3
|
+
module Logger
|
|
4
|
+
def __logger
|
|
5
|
+
Thread.current[:logger]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def __logger=(val)
|
|
9
|
+
Thread.current[:logger] = val
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def with_logger(logger: nil)
|
|
13
|
+
old = self.__logger
|
|
14
|
+
self.__logger = nil if logger.is_a? FalseClass
|
|
15
|
+
yield
|
|
16
|
+
ensure
|
|
17
|
+
self.__logger = old
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def __dry_run
|
|
21
|
+
Thread.current[:dry_run]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def __dry_run=(val)
|
|
25
|
+
Thread.current[:dry_run] = val
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def with_dry_run
|
|
29
|
+
old = __dry_run
|
|
30
|
+
yield old
|
|
31
|
+
ensure
|
|
32
|
+
__dry_run = old
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def storage
|
|
36
|
+
Thread.current[:dry_storage] ||= {}
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def __debug
|
|
40
|
+
Thread.current[:debug]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def info(msg=nil, indent: true, desc: nil, **kwargs, &b)
|
|
44
|
+
unless self.__logger.nil?
|
|
45
|
+
msg = indent ? with_indent(msg) : msg.chomp
|
|
46
|
+
msg = kwargs if msg.empty? # TODO
|
|
47
|
+
self.__logger.info(msg, &b)
|
|
48
|
+
end
|
|
49
|
+
{} # net_status
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def debug(msg=nil, indent: true, desc: nil, &b)
|
|
53
|
+
unless self.__logger.nil?
|
|
54
|
+
unless desc.nil?
|
|
55
|
+
(desc[:data] ||= {})[:msg] = msg
|
|
56
|
+
msg = t(desc: desc)
|
|
57
|
+
end
|
|
58
|
+
msg = indent ? with_indent(msg) : msg.chomp
|
|
59
|
+
self.__logger.debug(msg, &b)
|
|
60
|
+
end
|
|
61
|
+
{} # net_status
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def debug_operation(desc: nil, &b)
|
|
65
|
+
old = self.indent
|
|
66
|
+
|
|
67
|
+
status = :failed
|
|
68
|
+
diff = nil
|
|
69
|
+
resp = b.call do |resp|
|
|
70
|
+
status = resp[:code] || :ok
|
|
71
|
+
diff = resp[:diff]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
resp
|
|
75
|
+
rescue Exception => e
|
|
76
|
+
raise
|
|
77
|
+
ensure
|
|
78
|
+
desc[:code] = :"#{desc[:code]}.#{status}"
|
|
79
|
+
self.debug(desc: desc)
|
|
80
|
+
self.debug(diff, indent: false) if !diff.nil? and self.__debug
|
|
81
|
+
self.indent = old
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def debug_block(desc: nil, operation: false, &b)
|
|
85
|
+
old = self.indent
|
|
86
|
+
|
|
87
|
+
self.debug(desc: desc)
|
|
88
|
+
self.indent_step
|
|
89
|
+
|
|
90
|
+
status = :failed
|
|
91
|
+
resp = yield
|
|
92
|
+
status = :ok
|
|
93
|
+
|
|
94
|
+
resp
|
|
95
|
+
rescue Exception => e
|
|
96
|
+
raise
|
|
97
|
+
ensure
|
|
98
|
+
self.debug(desc: { code: status })
|
|
99
|
+
self.indent = old
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def t(desc: {}, context: nil)
|
|
103
|
+
code = desc[:code]
|
|
104
|
+
data = desc[:data]
|
|
105
|
+
::I18n.t [:debug, context, code].join('.'), [:debug, code].join('.'), **data, raise: true
|
|
106
|
+
rescue ::I18n::MissingTranslationData => e
|
|
107
|
+
raise NetStatus::Exception, { code: :missing_translation, data: { code: code } }
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def indent
|
|
111
|
+
@@indent ||= self.indent_reset
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def indent=(val)
|
|
115
|
+
@@indent = val
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def indent_reset
|
|
119
|
+
self.indent = 0
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def indent_step
|
|
123
|
+
self.indent += 1
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def indent_step_back
|
|
127
|
+
self.indent -= 1
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def with_indent(msg)
|
|
131
|
+
ind = "#{' ' * 4 * self.indent }"
|
|
132
|
+
"#{ind}#{msg.to_s.sub("\n", "\n#{ind}")}"
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|