class SmartMachine::Machine

Public Class Methods

new() click to toggle source
# File lib/smart_machine/machine.rb, line 6
def initialize
end

Public Instance Methods

apps(*args) click to toggle source
# File lib/smart_machine/machine.rb, line 89
def apps(*args)
        args.flatten!

        if args.delete("--local")
                exec "smartmachine runner apps #{args.join(" ")}"
        else
                ssh = SmartMachine::SSH.new
                ssh.run "smartmachine runner apps #{args.join(" ")}"
        end
end
create(*args) click to toggle source
# File lib/smart_machine/machine.rb, line 9
def create(*args)
        args.flatten!

        raise "Please specify a machine name" if args.empty?

        name = args.shift
        pathname = File.expand_path "./#{name}"

        self.setup_dotsmartmachine(pathname)

        puts "New machine #{name} has been created."
end
getting_started() click to toggle source
# File lib/smart_machine/machine.rb, line 127
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
grids(*args) click to toggle source
# File lib/smart_machine/machine.rb, line 78
def grids(*args)
        args.flatten!

        if args.delete("--local")
                exec "smartmachine runner grids #{args.join(" ")}"
        else
                ssh = SmartMachine::SSH.new
                ssh.run "smartmachine runner grids #{args.join(" ")}"
        end
end
in_local_machine_dir?() click to toggle source
# File lib/smart_machine/machine.rb, line 183
def in_local_machine_dir?
        File.file?("./config/master.key")
end
init_local(*args) click to toggle source
# File lib/smart_machine/machine.rb, line 22
def init_local(*args)
        args.flatten!

        pathname = File.expand_path "~/.smartmachine"

        if args.delete("--force")
                puts "Removing all the data to reinitialize."
                FileUtils.rmtree(pathname)
        end

        if Dir.exist?(pathname)
                puts "SmartMachine Local already initialized. If you want to delete all the data and reinitialize, please use the --force option."
                return
        end

        self.setup_dotsmartmachine(pathname)

        puts "SmartMachine Local Initialised."
end
installer(*args) click to toggle source
# File lib/smart_machine/machine.rb, line 42
def installer(*args)
        args.flatten!

        action = args.shift

        if args.empty? || args.include?("docker")
                docker = SmartMachine::Docker.new
                docker.public_send(action)
        end

        if args.empty? || args.include?("engine")
                engine = SmartMachine::Engine.new
                engine.public_send(action)
        end

        if args.empty? || args.include?("buildpacker")
                buildpacker = SmartMachine::Buildpacker.new
                buildpacker.public_send(action)
        end

        if args.empty? || args.include?("prereceiver")
                prereceiver = SmartMachine::Grids::Prereceiver.new
                prereceiver.public_send(action)
        end

        if args.empty? || args.include?("scheduler")
                scheduler = SmartMachine::Grids::Scheduler.new
                scheduler.public_send(action)
        end

        if args.empty? || args.include?("elasticsearch")
                elasticsearch = SmartMachine::Grids::Elasticsearch.new
                elasticsearch.public_send(action)
        end
end
logs(*args) click to toggle source
# File lib/smart_machine/machine.rb, line 111
def logs(*args)
        args.flatten!

        if args.delete("--local")
                exec "docker logs #{args.join(' ')}"
        else
                ssh = SmartMachine::SSH.new
                ssh.run "docker logs #{args.join(' ')}"
        end
end
ps(*args) click to toggle source
# File lib/smart_machine/machine.rb, line 100
def ps(*args)
        args.flatten!

        if args.delete("--local")
                exec "docker ps #{args.join(' ')}"
        else
                ssh = SmartMachine::SSH.new
                ssh.run "docker ps #{args.join(' ')}"
        end
end
securing_your_server() click to toggle source
# File lib/smart_machine/machine.rb, line 144
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="root@example.com"

        # adduser example_user
        # adduser example_user sudo

        # mkdir -p ~/.ssh && sudo chmod -R 700 ~/.ssh/
        # scp ~/.ssh/id_rsa.pub example_user@203.0.113.10:~/.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
setup_dotsmartmachine(pathname) click to toggle source
# File lib/smart_machine/machine.rb, line 187
def setup_dotsmartmachine(pathname)
        FileUtils.mkdir pathname
        FileUtils.cp_r "#{SmartMachine.config.root_path}/lib/smart_machine/templates/dotsmartmachine/.", pathname
        FileUtils.chdir pathname do
                credentials = SmartMachine::Credentials.new
                credentials.create
                system("git init && git add . && git commit -m 'initial commit'")
        end  
end
ssh() click to toggle source
# File lib/smart_machine/machine.rb, line 122
def ssh
        ssh = SmartMachine::SSH.new
        ssh.login
end