Class: SmartCloud::Machine

Inherits:
Base
  • Object
show all
Defined in:
lib/smart_cloud/machine.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

configure_logger_for, included, #logger, logger_for

Constructor Details

#initializeMachine

Returns a new instance of Machine.



6
7
# File 'lib/smart_cloud/machine.rb', line 6

def initialize
end

Class Method Details

.local?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/smart_cloud/machine.rb', line 145

def self.local?
	File.file?("./config/master.key")
end

.remote?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/smart_cloud/machine.rb', line 149

def self.remote?
	File.directory?("#{SmartCloud.config.user_home_path}/.smartcloud")
end

Instance Method Details

#app(*args) ⇒ Object



57
58
59
60
61
62
# File 'lib/smart_cloud/machine.rb', line 57

def app(*args)
	args.flatten!

	ssh = SmartCloud::SSH.new
	ssh.run "smartcloud run app #{args.join(" ")}"
end

#create(*args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/smart_cloud/machine.rb', line 9

def create(*args)
	args.flatten!

	name = args.shift
	FileUtils.mkdir name
	FileUtils.cp_r "#{SmartCloud.config.root_path}/lib/smartcloud/templates/dotsmartcloud/.", "#{name}"
	FileUtils.chdir "#{name}" do
		credentials = SmartCloud::Credentials.new
		credentials.create
	end
	puts "New machine #{name} has been created."
end

#getting_startedObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/smart_cloud/machine.rb', line 89

def getting_started
	# 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.'

	# apt-get update && apt-get upgrade

	# hostnamectl set-hostname example_hostname

	# /etc/hosts
	# 127.0.0.1 localhost.localdomain localhost
	# 203.0.113.10 hostname.example.com hostname
	# 2600:3c01::a123:b456:c789:d012 hostname.example.com hostname
	# Add DNS records for IPv4 and IPv6 for ip addresses and their fully qualified domain names FQDN

	# dpkg-reconfigure tzdata
	# date
end

#grid(*args) ⇒ Object



50
51
52
53
54
55
# File 'lib/smart_cloud/machine.rb', line 50

def grid(*args)
	args.flatten!

	ssh = SmartCloud::SSH.new
	ssh.run "smartcloud run grid #{args.join(" ")}"
end

#run(*args) ⇒ Object

Works only for class methods of the class as no instance of the class is created



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/smart_cloud/machine.rb', line 70

def run(*args)
	args.flatten!

	controller_type = args.shift.pluralize

	if controller_type == "grids"
		controller_name = args.shift
	elsif  controller_type == "apps"
		controller_name = "app"
	else
		raise "Invalid run command. Please try again."
	end

	controller = "SmartCloud::#{controller_type.capitalize}::#{controller_name.capitalize}"
	action = args.shift.to_sym

	args.empty? ? Object.const_get(controller).public_send(action) : Object.const_get(controller).public_send(action, args)
end

#securing_your_serverObject



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
135
136
137
138
139
140
141
142
143
# File 'lib/smart_cloud/machine.rb', line 106

def securing_your_server
	# sudo apt install unattended-upgrades

	# sudo nano /etc/apt/apt.conf.d/20auto-upgrades
	# APT::Periodic::Update-Package-Lists "1";
	# APT::Periodic::Download-Upgradeable-Packages "1";
	# APT::Periodic::AutocleanInterval "7";
	# APT::Periodic::Unattended-Upgrade "1";

	# sudo apt install apticron
	# /etc/apticron/apticron.conf
	# EMAIL="[email protected]"

	# adduser example_user
	# adduser example_user sudo

	# mkdir -p ~/.ssh && sudo chmod -R 700 ~/.ssh/
	# scp ~/.ssh/id_rsa.pub [email protected]:~/.ssh/authorized_keys
	# sudo chmod -R 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys

	# sudo nano /etc/ssh/sshd_config
	# PermitRootLogin no
	# PasswordAuthentication no
	# echo 'AddressFamily inet' | sudo tee -a /etc/ssh/sshd_config
	# sudo systemctl restart sshd

	# sudo apt-get update && sudo apt-get upgrade -y
	# sudo apt-get install fail2ban
	# sudo apt-get install sendmail
	# sudo ufw allow ssh
	# sudo ufw enable
	# sudo cp /etc/fail2ban/fail2ban.conf /etc/fail2ban/fail2ban.local
	# sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
	# Change destmail, sendername, sender
	# Change action = %(action_mwl)s
	# sudo fail2ban-client reload
	# sudo fail2ban-client status
end

#sshObject



64
65
66
67
# File 'lib/smart_cloud/machine.rb', line 64

def ssh
	ssh = SmartCloud::SSH.new
	ssh.
end

#startObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/smart_cloud/machine.rb', line 22

def start
	SmartCloud::Docker.new.install

	engine = SmartCloud::Engine.new
	engine.install

	ssh = SmartCloud::SSH.new
	ssh.run "smartcloud buildpacker install"
	ssh.run "smartcloud prereceiver install"

	elasticsearch = SmartCloud::Grids::Elasticsearch.new
	elasticsearch.install
end

#stopObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/smart_cloud/machine.rb', line 36

def stop
	elasticsearch = SmartCloud::Grids::Elasticsearch.new
	elasticsearch.uninstall

	ssh = SmartCloud::SSH.new
	ssh.run "smartcloud prereceiver uninstall"
	ssh.run "smartcloud buildpacker uninstall"

	engine = SmartCloud::Engine.new
	engine.uninstall

	SmartCloud::Docker.new.uninstall
end

#sync(first_sync = false) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/smart_cloud/machine.rb', line 153

def sync(first_sync = false)
	puts "-----> Syncing smartcloud ... "
	return sync_push if first_sync

	unless block_given?
		sync_pull && sync_push
	else
		sync_pull
		yield
		sync_push
	end
end