Class: Mimas::CLI::Commands::Provision

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/mimas/commands/provision.rb

Constant Summary

Constants included from Template

Template::BASE_DIRECTORY

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Methods included from Terminal::Printer

#ask, #say

Methods included from SSH

#ssh

Methods included from Template

#copy_file, lookup_paths, #read_file, #template

Constructor Details

This class inherits a constructor from Mimas::CLI::Commands::BaseCommand

Instance Method Details

#call(server_name:, **options) ⇒ Object



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
# File 'lib/mimas/commands/provision.rb', line 18

def call(server_name:, **options)
  server = Config.current.servers[server_name.to_sym]
  sudo_user = options[:user]
  skip_ruby = options[:skip_ruby]

  server.harden

  say "Waiting for server to come back online ..."
  sleep 30

  connection_retries = 0
  begin
    connection_retries += 1
    Net::SSH.start(server.host, sudo_user, **server.ssh_options)&.close
  rescue
    sleep 5
    retry if connection_retries < 5
    say "Unable to re-connect to server."
    say "Wait for the server to come online, then run `bin/mimas setup`"
  end

  server.setup_deploy_user(sudo_user: sudo_user)
  server.install_caddy(sudo_user: sudo_user)

  unless skip_ruby
    server.install_server_software(sudo_user: sudo_user)
    server.install_ruby
  end

  say ""
  say "Your server is provisioned and ready to serve websites."
end