lib/smartcloud/machine.rb in smartcloud-0.1.0 vs lib/smartcloud/machine.rb in smartcloud-0.2.0.beta1
- old
+ new
@@ -4,10 +4,73 @@
module Smartcloud
class Machine < Smartcloud::Base
def initialize
end
+ def create(*args)
+ args.flatten!
+
+ name = args.shift
+ FileUtils.mkdir name
+ FileUtils.cp_r "#{Smartcloud.config.root_path}/lib/smartcloud/templates/dotsmartcloud/.", "#{name}"
+ puts "New machine #{name} has been created."
+ end
+
+ def start
+ Smartcloud::User.create_htpasswd_files
+ Smartcloud::Docker.install
+ Smartcloud::Engine.install
+ end
+
+ def stop
+ Smartcloud::Engine.uninstall
+ Smartcloud::Docker.uninstall
+ end
+
+ def grid(*args)
+ args.flatten!
+ name = "Smartcloud::Grids::#{args.shift.capitalize}"
+ action = args.shift.to_sym
+
+ args.empty? ? Object.const_get(name).public_send(action) : Object.const_get(name).public_send(action, args)
+
+ # if ARGV[1] == 'runner'
+ # if ARGV[2] == 'up'
+ # Smartcloud::Grids::Runner.up
+ # elsif ARGV[2] == 'down'
+ # Smartcloud::Grids::Runner.down
+ # end
+ # elsif ARGV[1] == 'mysql'
+ # if ARGV[2] == 'up'
+ # Smartcloud::Grids::Mysql.up(ARGV[3])
+ # elsif ARGV[2] == 'down'
+ # Smartcloud::Grids::Mysql.down
+ # end
+ # elsif ARGV[1] == 'nginx'
+ # if ARGV[2] == 'up'
+ # Smartcloud::Grids::Nginx.up(ARGV[3])
+ # elsif ARGV[2] == 'down'
+ # Smartcloud::Grids::Nginx.down
+ # end
+ # elsif ARGV[1] == 'solr'
+ # if ARGV[2] == 'up'
+ # Smartcloud::Grids::Solr.up(ARGV[3])
+ # elsif ARGV[2] == 'down'
+ # Smartcloud::Grids::Solr.down
+ # elsif ARGV[2] == 'create_core'
+ # Smartcloud::Grids::Solr.create_core(ARGV[3])
+ # elsif ARGV[2] == 'destroy_core'
+ # Smartcloud::Grids::Solr.destroy_core(ARGV[3])
+ # end
+ # end
+ end
+
+ def ssh
+ ssh = Smartcloud::SSH.new
+ ssh.login
+ end
+
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
@@ -60,27 +123,67 @@
# Change action = %(action_mwl)s
# sudo fail2ban-client reload
# sudo fail2ban-client status
end
- # def create(name)
- # FileUtils.mkdir_p name
- # FileUtils.cp_r "#{Smartcloud.config.root_path}/lib/smartcloud/templates/machine/.", "#{name}"
- # puts "Please fill details in your config folder before proceeding."
- # end
- #
- # def run(*args)
- # end
- #
- # def install_docker
- # end
- #
- # def uninstall_docker
- # end
- #
- # def install_engine
- # end
- #
- # def uninstall_engine
- # end
+ def self.smartcloud_dir?
+ File.file?("./bin/smartcloud.sh")
+ end
+
+ 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
+
+ private
+
+ def sync_pull
+ system("rsync -azumv --delete --include=*/ --include={#{sync_pull_files_list}} --exclude=* -e ssh #{Smartcloud.credentials.machine[:username]}@#{Smartcloud.credentials.machine[:host]}:~/.smartcloud/ .")
+ end
+
+ def sync_push
+ system("rsync -azumv --delete --include=*/ --include={#{sync_push_files_list}} --exclude={#{excluded_sync_files_list}} --exclude={#{sync_pull_files_list}} -e ssh ./ #{Smartcloud.credentials.machine[:username]}@#{Smartcloud.credentials.machine[:host]}:~/.smartcloud")
+ end
+
+ def excluded_sync_files_list
+ files = [
+ 'config/credentials.yml',
+ 'config/users.yml'
+ ]
+ files.join(',')
+ end
+
+ def sync_pull_files_list
+ files = [
+ 'grids/grid-mysql/data/***',
+ 'grids/grid-nginx/certificates/***',
+ 'grids/grid-runner/apps/***',
+ 'grids/grid-solr/data/***',
+ ]
+ files.join(',')
+ end
+
+ def sync_push_files_list
+ files = [
+ 'grids/grid-mysql/data/.keep',
+ 'grids/grid-nginx/certificates/.keep',
+ 'grids/grid-runner/apps/containers/.keep',
+ 'grids/grid-runner/apps/repositories/.keep',
+ 'grids/grid-solr/data/.keep',
+ 'grids/grid-solr/data/README.txt',
+ 'grids/grid-solr/data/solr.xml',
+ 'grids/grid-solr/data/zoo.cfg',
+ 'grids/grid-solr/data/configsets/***',
+ 'grids/grid-solr/data/lib/***',
+ ]
+ files.join(',')
+ end
end
end
\ No newline at end of file