smartmachine 0.8.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +661 -0
- data/README.md +147 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/smartmachine +3 -0
- data/lib/smart_machine/apps/app.rb +165 -181
- data/lib/smart_machine/apps/container.rb +120 -0
- data/lib/smart_machine/apps/manager.rb +182 -0
- data/lib/smart_machine/base.rb +24 -6
- data/lib/smart_machine/buildpackers/buildpacker.rb +95 -0
- data/lib/smart_machine/{engine/buildpacks → buildpackers}/rails/Dockerfile +3 -3
- data/lib/smart_machine/buildpackers/rails.rb +221 -0
- data/lib/smart_machine/commands/app.rb +112 -0
- data/lib/smart_machine/commands/buildpacker.rb +53 -0
- data/lib/smart_machine/commands/credentials.rb +17 -0
- data/lib/smart_machine/commands/docker.rb +23 -0
- data/lib/smart_machine/commands/engine.rb +27 -0
- data/lib/smart_machine/commands/grid.rb +33 -0
- data/lib/smart_machine/commands/grid_commands/elasticsearch.rb +68 -0
- data/lib/smart_machine/commands/grid_commands/minio.rb +65 -0
- data/lib/smart_machine/commands/grid_commands/mysql.rb +71 -0
- data/lib/smart_machine/commands/grid_commands/nginx.rb +53 -0
- data/lib/smart_machine/commands/grid_commands/prereceiver.rb +96 -0
- data/lib/smart_machine/commands/grid_commands/redis.rb +65 -0
- data/lib/smart_machine/commands/grid_commands/scheduler.rb +15 -0
- data/lib/smart_machine/commands/grid_commands/sub_thor.rb +15 -0
- data/lib/smart_machine/commands/machine.rb +24 -0
- data/lib/smart_machine/commands/syncer.rb +23 -0
- data/lib/smart_machine/commands/utilities.rb +37 -0
- data/lib/smart_machine/commands.rb +66 -0
- data/lib/smart_machine/configuration.rb +79 -0
- data/lib/smart_machine/credentials.rb +93 -95
- data/lib/smart_machine/docker.rb +144 -143
- data/lib/smart_machine/engine/Dockerfile +7 -5
- data/lib/smart_machine/engine.rb +104 -79
- data/lib/smart_machine/grids/elasticsearch.rb +70 -89
- data/lib/smart_machine/grids/minio.rb +79 -68
- data/lib/smart_machine/grids/mysql.rb +207 -202
- data/lib/smart_machine/grids/nginx.rb +176 -135
- data/lib/smart_machine/grids/prereceiver/Dockerfile +2 -2
- data/lib/smart_machine/grids/prereceiver/pre-receive +17 -0
- data/lib/smart_machine/grids/prereceiver.rb +169 -169
- data/lib/smart_machine/grids/redis.rb +75 -57
- data/lib/smart_machine/grids/scheduler/Dockerfile +1 -1
- data/lib/smart_machine/logger.rb +26 -26
- data/lib/smart_machine/machine.rb +128 -194
- data/lib/smart_machine/scp.rb +15 -0
- data/lib/smart_machine/ssh.rb +69 -40
- data/lib/smart_machine/syncer.rb +133 -0
- data/lib/smart_machine/templates/dotsmartmachine/Gemfile +7 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/elasticsearch.yml +5 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/environment.rb +0 -9
- data/lib/smart_machine/templates/dotsmartmachine/config/minio.yml +13 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/mysql/schedule.rb +3 -3
- data/lib/smart_machine/templates/dotsmartmachine/config/mysql.yml +13 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/prereceiver.yml +7 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/redis.yml +15 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/users.yml +1 -1
- data/lib/smart_machine/templates/dotsmartmachine/gitignore-template +47 -0
- data/lib/smart_machine/templates/dotsmartmachine/{grids/elasticsearch/data → vendor}/.keep +0 -0
- data/lib/smart_machine/version.rb +30 -6
- data/lib/smart_machine.rb +42 -16
- metadata +97 -47
- data/CHANGELOG.rdoc +0 -0
- data/MIT-LICENSE +0 -21
- data/README.rdoc +0 -87
- data/bin/buildpacker +0 -8
- data/bin/prereceiver +0 -8
- data/bin/scheduler +0 -18
- data/bin/smartmachine +0 -81
- data/bin/smartrunner +0 -33
- data/lib/smart_machine/apps/rails.rb +0 -250
- data/lib/smart_machine/apps.rb +0 -14
- data/lib/smart_machine/boot.rb +0 -32
- data/lib/smart_machine/buildpacker.rb +0 -106
- data/lib/smart_machine/gem_version.rb +0 -17
- data/lib/smart_machine/grids.rb +0 -18
- data/lib/smart_machine/sync.rb +0 -120
- data/lib/smart_machine/templates/dotsmartmachine/grids/elasticsearch/logs/.keep +0 -0
- data/lib/smart_machine/templates/dotsmartmachine/grids/minio/data/.keep +0 -0
- data/lib/smart_machine/templates/dotsmartmachine/grids/mysql/backups/.keep +0 -0
- data/lib/smart_machine/templates/dotsmartmachine/grids/mysql/data/.keep +0 -0
- data/lib/smart_machine/templates/dotsmartmachine/grids/prereceiver/pre-receive +0 -17
- data/lib/smart_machine/templates/dotsmartmachine/grids/redis/data/.keep +0 -0
- data/lib/smart_machine/user.rb +0 -38
@@ -1,197 +1,131 @@
|
|
1
1
|
require "net/ssh"
|
2
2
|
|
3
|
-
# The main SmartMachine Machine driver
|
4
3
|
module SmartMachine
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
# /etc/hosts
|
135
|
-
# 127.0.0.1 localhost.localdomain localhost
|
136
|
-
# 203.0.113.10 hostname.example.com hostname
|
137
|
-
# 2600:3c01::a123:b456:c789:d012 hostname.example.com hostname
|
138
|
-
# Add DNS records for IPv4 and IPv6 for ip addresses and their fully qualified domain names FQDN
|
139
|
-
|
140
|
-
# dpkg-reconfigure tzdata
|
141
|
-
# date
|
142
|
-
end
|
143
|
-
|
144
|
-
def securing_your_server
|
145
|
-
# sudo apt install unattended-upgrades
|
146
|
-
|
147
|
-
# sudo nano /etc/apt/apt.conf.d/20auto-upgrades
|
148
|
-
# APT::Periodic::Update-Package-Lists "1";
|
149
|
-
# APT::Periodic::Download-Upgradeable-Packages "1";
|
150
|
-
# APT::Periodic::AutocleanInterval "7";
|
151
|
-
# APT::Periodic::Unattended-Upgrade "1";
|
152
|
-
|
153
|
-
# sudo apt install apticron
|
154
|
-
# /etc/apticron/apticron.conf
|
155
|
-
# EMAIL="root@example.com"
|
156
|
-
|
157
|
-
# adduser example_user
|
158
|
-
# adduser example_user sudo
|
159
|
-
|
160
|
-
# mkdir -p ~/.ssh && sudo chmod -R 700 ~/.ssh/
|
161
|
-
# scp ~/.ssh/id_rsa.pub example_user@203.0.113.10:~/.ssh/authorized_keys
|
162
|
-
# sudo chmod -R 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
|
163
|
-
|
164
|
-
# sudo nano /etc/ssh/sshd_config
|
165
|
-
# PermitRootLogin no
|
166
|
-
# PasswordAuthentication no
|
167
|
-
# echo 'AddressFamily inet' | sudo tee -a /etc/ssh/sshd_config
|
168
|
-
# sudo systemctl restart sshd
|
169
|
-
|
170
|
-
# sudo apt-get update && sudo apt-get upgrade -y
|
171
|
-
# sudo apt-get install fail2ban
|
172
|
-
# sudo apt-get install sendmail
|
173
|
-
# sudo ufw allow ssh
|
174
|
-
# sudo ufw enable
|
175
|
-
# sudo cp /etc/fail2ban/fail2ban.conf /etc/fail2ban/fail2ban.local
|
176
|
-
# sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
|
177
|
-
# Change destmail, sendername, sender
|
178
|
-
# Change action = %(action_mwl)s
|
179
|
-
# sudo fail2ban-client reload
|
180
|
-
# sudo fail2ban-client status
|
181
|
-
end
|
182
|
-
|
183
|
-
def in_local_machine_dir?
|
184
|
-
File.file?("./config/master.key")
|
185
|
-
end
|
186
|
-
|
187
|
-
def setup_dotsmartmachine(pathname)
|
188
|
-
FileUtils.mkdir pathname
|
189
|
-
FileUtils.cp_r "#{SmartMachine.config.root_path}/lib/smart_machine/templates/dotsmartmachine/.", pathname
|
190
|
-
FileUtils.chdir pathname do
|
191
|
-
credentials = SmartMachine::Credentials.new
|
192
|
-
credentials.create
|
193
|
-
system("git init && git add . && git commit -m 'initial commit'")
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
4
|
+
class Machine < SmartMachine::Base
|
5
|
+
def initialize
|
6
|
+
end
|
7
|
+
|
8
|
+
# Create a new smartmachine
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
# >> Machine.create("qw21334q")
|
12
|
+
# => "New machine qw21334q has been created."
|
13
|
+
#
|
14
|
+
# Arguments:
|
15
|
+
# name: (String)
|
16
|
+
# dev: (Boolean)
|
17
|
+
def create(name:, dev:)
|
18
|
+
raise "Please specify a machine name" if name.blank?
|
19
|
+
|
20
|
+
pathname = File.expand_path "./#{name}"
|
21
|
+
|
22
|
+
if Dir.exist?(pathname)
|
23
|
+
puts "A machine with this name already exists. Please use a different name."
|
24
|
+
return
|
25
|
+
end
|
26
|
+
|
27
|
+
FileUtils.mkdir pathname
|
28
|
+
FileUtils.cp_r "#{SmartMachine.config.gem_dir}/lib/smart_machine/templates/dotsmartmachine/.", pathname
|
29
|
+
FileUtils.chdir pathname do
|
30
|
+
credentials = SmartMachine::Credentials.new
|
31
|
+
credentials.create
|
32
|
+
|
33
|
+
File.write("Gemfile", File.open("Gemfile",&:read).gsub("replace_ruby_version", "#{SmartMachine.ruby_version}"))
|
34
|
+
File.write(".ruby-version", SmartMachine.ruby_version)
|
35
|
+
if dev
|
36
|
+
File.write("Gemfile", File.open("Gemfile",&:read).gsub("\"~> replace_smartmachine_version\"", "path: \"../\""))
|
37
|
+
else
|
38
|
+
File.write("Gemfile", File.open("Gemfile",&:read).gsub("replace_smartmachine_version", "#{SmartMachine.version}"))
|
39
|
+
end
|
40
|
+
system("mv gitignore-template .gitignore")
|
41
|
+
|
42
|
+
# Here BUNDLE_GEMFILE is needed as it may be already set due to usage of bundle exec (which may not be correct in this case)
|
43
|
+
bundle_gemfile = "#{pathname}/Gemfile"
|
44
|
+
system("BUNDLE_GEMFILE='#{bundle_gemfile}' bundle install && BUNDLE_GEMFILE='#{bundle_gemfile}' bundle binstubs smartmachine")
|
45
|
+
|
46
|
+
system("git init && git add . && git commit -m 'initial commit by SmartMachine #{SmartMachine.version}'")
|
47
|
+
end
|
48
|
+
|
49
|
+
puts "New machine #{name} has been created."
|
50
|
+
end
|
51
|
+
|
52
|
+
def initial_setup
|
53
|
+
getting_started
|
54
|
+
securing_your_server
|
55
|
+
end
|
56
|
+
|
57
|
+
def run_on_machine(commands:)
|
58
|
+
commands = Array(commands).flatten
|
59
|
+
ssh = SmartMachine::SSH.new
|
60
|
+
status = ssh.run commands
|
61
|
+
|
62
|
+
status[:exit_code] == 0
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def getting_started
|
68
|
+
# apt install locales-all
|
69
|
+
|
70
|
+
# puts 'You may be prompted to make a menu selection when the Grub package is updated on Ubuntu. If prompted, select keep the local version currently installed.'
|
71
|
+
# apt update && apt upgrade
|
72
|
+
|
73
|
+
# hostnamectl set-hostname SmartMachine.credentials.machine[:name]
|
74
|
+
|
75
|
+
# The value you assign as your system’s FQDN should have an “A” record in DNS pointing to your Linode’s IPv4 address. For IPv6, you should also set up a DNS “AAAA” record pointing to your Linode’s IPv6 address.
|
76
|
+
# Add DNS records for IPv4 and IPv6 for ip addresses and their fully qualified domain names FQDN
|
77
|
+
# /etc/hosts
|
78
|
+
# 203.0.113.10 SmartMachine.credentials.machine[:name].example.com SmartMachine.credentials.machine[:name]
|
79
|
+
# 2600:3c01::a123:b456:c789:d012 SmartMachine.credentials.machine[:name].example.com SmartMachine.credentials.machine[:name]
|
80
|
+
|
81
|
+
# dpkg-reconfigure tzdata
|
82
|
+
# date
|
83
|
+
end
|
84
|
+
|
85
|
+
def securing_your_server
|
86
|
+
# apt install unattended-upgrades
|
87
|
+
# dpkg-reconfigure --priority=low unattended-upgrades
|
88
|
+
|
89
|
+
# nano /etc/apt/apt.conf.d/20auto-upgrades
|
90
|
+
# APT::Periodic::Update-Package-Lists "1";
|
91
|
+
# APT::Periodic::Download-Upgradeable-Packages "1";
|
92
|
+
# APT::Periodic::AutocleanInterval "7";
|
93
|
+
# APT::Periodic::Unattended-Upgrade "1";
|
94
|
+
|
95
|
+
# apt install apticron
|
96
|
+
# /usr/lib/apticron/apticron.conf
|
97
|
+
# EMAIL="root@example.com"
|
98
|
+
|
99
|
+
# adduser example_user
|
100
|
+
# adduser example_user sudo
|
101
|
+
|
102
|
+
# mkdir -p ~/.ssh && sudo chmod -R 700 ~/.ssh/
|
103
|
+
# scp ~/.ssh/id_rsa.pub example_user@203.0.113.10:~/.ssh/authorized_keys
|
104
|
+
# sudo chmod -R 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
|
105
|
+
|
106
|
+
# sudo nano /etc/ssh/sshd_config
|
107
|
+
# PermitRootLogin no
|
108
|
+
# PasswordAuthentication no
|
109
|
+
# echo 'AddressFamily inet' | sudo tee -a /etc/ssh/sshd_config
|
110
|
+
# sudo systemctl restart sshd
|
111
|
+
|
112
|
+
# sudo apt update && sudo apt upgrade -y
|
113
|
+
|
114
|
+
# sudo apt install ufw
|
115
|
+
# sudo ufw default allow outgoing
|
116
|
+
# sudo ufw default deny incoming
|
117
|
+
# sudo ufw allow SmartMachine.credentials.machine[:port]/tcp
|
118
|
+
# sudo ufw enable
|
119
|
+
# sudo ufw logging on
|
120
|
+
|
121
|
+
# sudo apt install fail2ban
|
122
|
+
# sudo apt install sendmail
|
123
|
+
# sudo cp /etc/fail2ban/fail2ban.conf /etc/fail2ban/fail2ban.local
|
124
|
+
# sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
|
125
|
+
# Change destmail, sendername, sender
|
126
|
+
# Change action = %(action_mwl)s
|
127
|
+
# sudo fail2ban-client reload
|
128
|
+
# sudo fail2ban-client status
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SmartMachine
|
2
|
+
class SCP < SmartMachine::Base
|
3
|
+
def initialize
|
4
|
+
@address = SmartMachine.credentials.machine[:address]
|
5
|
+
@port = SmartMachine.credentials.machine[:port]
|
6
|
+
@username = SmartMachine.credentials.machine[:username]
|
7
|
+
@password = SmartMachine.credentials.machine[:password]
|
8
|
+
end
|
9
|
+
|
10
|
+
def upload!(local_path:, remote_path:)
|
11
|
+
system("scp -q -P #{@port} #{local_path} #{@username}@#{@address}:#{remote_path}")
|
12
|
+
$?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/smart_machine/ssh.rb
CHANGED
@@ -1,43 +1,72 @@
|
|
1
1
|
require "net/ssh"
|
2
2
|
|
3
|
-
# The main SmartMachine SSH driver
|
4
3
|
module SmartMachine
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
4
|
+
class SSH < SmartMachine::Base
|
5
|
+
def initialize
|
6
|
+
end
|
7
|
+
|
8
|
+
def run(*commands)
|
9
|
+
commands.flatten!
|
10
|
+
status = {}
|
11
|
+
|
12
|
+
Net::SSH.start(SmartMachine.credentials.machine[:address], SmartMachine.credentials.machine[:username], { port: SmartMachine.credentials.machine[:port], password: SmartMachine.credentials.machine[:password] }) do |ssh|
|
13
|
+
commands.each do |command|
|
14
|
+
|
15
|
+
puts "\e[1m" + "$ " + command + "\e[0m"
|
16
|
+
|
17
|
+
channel = ssh.open_channel do |channel|
|
18
|
+
|
19
|
+
channel.on_open_failed do |channel, code, description|
|
20
|
+
raise "could not open channel (#{description}, ##{code})"
|
21
|
+
end
|
22
|
+
|
23
|
+
ssh.listen_to(STDIN) do |stdin|
|
24
|
+
input = stdin.readpartial(1024)
|
25
|
+
channel.send_data(input) unless input.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
channel.request_pty :modes => { Net::SSH::Connection::Term::ECHO => 0 } do |channel, success|
|
29
|
+
raise "could not obtain pty" unless success
|
30
|
+
|
31
|
+
channel.exec command do |channel, success|
|
32
|
+
raise "could not execute command: #{command.inspect}" unless success
|
33
|
+
|
34
|
+
if status
|
35
|
+
channel.on_request("exit-status") do |ch2, data|
|
36
|
+
status[:exit_code] = data.read_long
|
37
|
+
end
|
38
|
+
|
39
|
+
channel.on_request("exit-signal") do |ch2, data|
|
40
|
+
status[:exit_signal] = data.read_long
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
channel.on_data do |ch2, data|
|
45
|
+
$stdout.print data
|
46
|
+
|
47
|
+
if (data[/\[sudo\]|Password/i])
|
48
|
+
channel.send_data "#{SmartMachine.credentials.machine[:password]}\n"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
channel.on_extended_data do |ch2, type, data|
|
53
|
+
$stderr.print data
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
channel.wait
|
60
|
+
|
61
|
+
break if status[:exit_code] != 0
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
status
|
66
|
+
end
|
67
|
+
|
68
|
+
def login
|
69
|
+
exec "ssh -p #{SmartMachine.credentials.machine[:port]} #{SmartMachine.credentials.machine[:username]}@#{SmartMachine.credentials.machine[:address]}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module SmartMachine
|
2
|
+
class Syncer < SmartMachine::Base
|
3
|
+
def initialize
|
4
|
+
end
|
5
|
+
|
6
|
+
def sync(initial: false)
|
7
|
+
puts "-----> Syncing SmartMachine"
|
8
|
+
|
9
|
+
push if initial
|
10
|
+
|
11
|
+
pull
|
12
|
+
push
|
13
|
+
|
14
|
+
puts "-----> Syncing SmartMachine Complete"
|
15
|
+
end
|
16
|
+
|
17
|
+
def rsync(*args)
|
18
|
+
exec "rsync #{args.join(' ')}"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def pull
|
24
|
+
puts "-----> Syncer pulling ... "
|
25
|
+
if system("#{rsync_command(pull_files_list)} #{SmartMachine.credentials.machine[:username]}@#{SmartMachine.credentials.machine[:address]}:~/machine/ .")
|
26
|
+
puts "done"
|
27
|
+
else
|
28
|
+
raise "Syncer error while pulling..."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def push
|
33
|
+
puts "-----> Syncer pushing ... "
|
34
|
+
if system("#{rsync_command(push_files_list)} ./ #{SmartMachine.credentials.machine[:username]}@#{SmartMachine.credentials.machine[:address]}:~/machine")
|
35
|
+
puts "done"
|
36
|
+
else
|
37
|
+
raise "Syncer error while pushing..."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def rsync_command(files_list)
|
42
|
+
command = [
|
43
|
+
"rsync -azumv",
|
44
|
+
"-e 'ssh -p #{SmartMachine.credentials.machine[:port]}'",
|
45
|
+
"--rsync-path='smartengine syncer rsync'",
|
46
|
+
"--delete",
|
47
|
+
"--include={#{files_list}}",
|
48
|
+
"--exclude=*"
|
49
|
+
]
|
50
|
+
|
51
|
+
command.join(" ")
|
52
|
+
end
|
53
|
+
|
54
|
+
def pull_files_list
|
55
|
+
files = [
|
56
|
+
'apps/***',
|
57
|
+
|
58
|
+
'bin/***',
|
59
|
+
|
60
|
+
'grids',
|
61
|
+
|
62
|
+
'grids/elasticsearch',
|
63
|
+
'grids/elasticsearch/***',
|
64
|
+
|
65
|
+
'grids/minio',
|
66
|
+
'grids/minio/***',
|
67
|
+
|
68
|
+
'grids/mysql',
|
69
|
+
'grids/mysql/***',
|
70
|
+
|
71
|
+
'grids/nginx',
|
72
|
+
'grids/nginx/certificates/***',
|
73
|
+
|
74
|
+
'grids/prereceiver',
|
75
|
+
'grids/prereceiver/***',
|
76
|
+
|
77
|
+
'grids/redis',
|
78
|
+
'grids/redis/***',
|
79
|
+
|
80
|
+
'grids/scheduler',
|
81
|
+
'grids/scheduler/crontabs/***',
|
82
|
+
|
83
|
+
'grids/solr',
|
84
|
+
'grids/solr/solr/***',
|
85
|
+
]
|
86
|
+
files.join(',')
|
87
|
+
end
|
88
|
+
|
89
|
+
def push_files_list
|
90
|
+
files = [
|
91
|
+
'apps',
|
92
|
+
'apps/containers',
|
93
|
+
'apps/containers/.keep',
|
94
|
+
'apps/repositories',
|
95
|
+
'apps/repositories/.keep',
|
96
|
+
|
97
|
+
'bin',
|
98
|
+
'bin/smartmachine',
|
99
|
+
|
100
|
+
'config',
|
101
|
+
'config/mysql',
|
102
|
+
'config/mysql/schedule.rb',
|
103
|
+
'config/credentials.yml.enc',
|
104
|
+
'config/environment.rb',
|
105
|
+
'config/elasticsearch.yml',
|
106
|
+
'config/minio.yml',
|
107
|
+
'config/mysql.yml',
|
108
|
+
'config/prereceiver.yml',
|
109
|
+
'config/redis.yml',
|
110
|
+
|
111
|
+
'grids',
|
112
|
+
|
113
|
+
'grids/nginx',
|
114
|
+
'grids/nginx/certificates',
|
115
|
+
'grids/nginx/certificates/.keep',
|
116
|
+
'grids/nginx/htpasswd/***',
|
117
|
+
'grids/nginx/fastcgi.conf',
|
118
|
+
'grids/nginx/nginx.tmpl',
|
119
|
+
|
120
|
+
'grids/scheduler',
|
121
|
+
'grids/scheduler/crontabs',
|
122
|
+
'grids/scheduler/crontabs/.keep',
|
123
|
+
|
124
|
+
'grids/solr',
|
125
|
+
'grids/solr/solr',
|
126
|
+
'grids/solr/solr/.keep',
|
127
|
+
|
128
|
+
'tmp/***',
|
129
|
+
]
|
130
|
+
files.join(',')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -1,18 +1,9 @@
|
|
1
1
|
# => NOTE: Ensure that the specified top-level domains are pointing to this server ip address using DNS records.
|
2
2
|
# => Be sure to restart your server when you modify this file.
|
3
3
|
|
4
|
-
# Top-level naked domain to be used for subdomains of apps.
|
5
|
-
SmartMachine.config.apps_domain = "yourdomain.com"
|
6
|
-
|
7
|
-
# domain to be used for git prereceiver
|
8
|
-
SmartMachine.config.git_domain = "git.yourdomain.com"
|
9
|
-
|
10
4
|
# Sysadmin email id.
|
11
5
|
SmartMachine.config.sysadmin_email = "admin@yourdomain.com"
|
12
6
|
|
13
|
-
# letsencrypt test boolean to be used
|
14
|
-
SmartMachine.config.letsencrypt_test = false
|
15
|
-
|
16
7
|
# logger level
|
17
8
|
# DEBUG, INFO, WARN, ERROR, FATAL, UNKNOWN
|
18
9
|
SmartMachine.config.logger_level = "INFO"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
minioone:
|
2
|
+
host: "yourminioone.yourdomain.com"
|
3
|
+
access_key: <%= SmartMachine.credentials.dig(:minioone, :access_key) %>
|
4
|
+
secret_key: <%= SmartMachine.credentials.dig(:minioone, :secret_key) %>
|
5
|
+
browser: on
|
6
|
+
worm: off
|
7
|
+
|
8
|
+
# miniotwo:
|
9
|
+
# host: "yourminiotwo.yourdomain.com"
|
10
|
+
# access_key: <%= SmartMachine.credentials.dig(:miniotwo, :access_key) %>
|
11
|
+
# secret_key: <%= SmartMachine.credentials.dig(:miniotwo, :secret_key) %>
|
12
|
+
# browser: on
|
13
|
+
# worm: off
|
@@ -3,17 +3,17 @@
|
|
3
3
|
|
4
4
|
# Flush logs used to create consistent binlogs to be used for incremental backups
|
5
5
|
every :day, at: '12:00 pm' do
|
6
|
-
|
6
|
+
command "smartmachine runner grids mysql flushlogs"
|
7
7
|
end
|
8
8
|
|
9
9
|
# Create daily backup.
|
10
10
|
# This also flushes the logs before backup
|
11
11
|
every :day, at: '12:00 am' do
|
12
|
-
|
12
|
+
command "smartmachine runner grids mysql backup --daily"
|
13
13
|
end
|
14
14
|
|
15
15
|
# Promote currently latest daily backup to weekly backup.
|
16
16
|
# This is only possible when a daily backup creation has already been completed.
|
17
17
|
every :monday, at: '3:00 am' do
|
18
|
-
|
18
|
+
command "smartmachine runner grids mysql backup --promote-to-weekly"
|
19
19
|
end
|