Class: Flare::Tools::Cli::Deploy
- Inherits:
-
SubCommand
- Object
- SubCommand
- Flare::Tools::Cli::Deploy
- Includes:
- IndexServerConfig, Util::Conversion, Util::FileSystem
- Defined in:
- lib/flare/tools/cli/deploy.rb
Constant Summary
Constants included from IndexServerConfig
IndexServerConfig::Entity, IndexServerConfig::FLARE_INDEX_SERVER, IndexServerConfig::FLARE_INDEX_SERVERS
Constants included from Util::Constant
Util::Constant::DefalutBwlimit, Util::Constant::DefaultIndexServerName, Util::Constant::DefaultIndexServerPort, Util::Constant::DefaultNodePort, Util::Constant::DefaultTimeout, Util::Constant::STATUS_NG, Util::Constant::STATUS_OK
Constants inherited from SubCommand
SubCommand::S_NG, SubCommand::S_OK
Constants included from Util::Interruption
Util::Interruption::InterruptionTargets
Instance Attribute Summary
Attributes included from Option
Instance Method Summary collapse
- #execute(config, args) ⇒ Object
-
#initialize ⇒ Deploy
constructor
A new instance of Deploy.
- #output_scripts(basedir, datadir, name, exec) ⇒ Object
- #setup ⇒ Object
Methods included from Util::Logging
#debug, #error, #fatal, #info, logger, #puts, set_logger, #trace, #warn
Methods included from Util::FileSystem
Methods included from Util::Conversion
Methods inherited from SubCommand
desc, #execute_subcommand, myname, #myname, to_s, to_sym, usage
Methods included from Util::Interruption
included, #initialize_interruption, #interrupt, #interrupt_, interrupt_all, #interrupted?, #interruptible, #interruptible?
Methods included from Option
#option_init, #parse_options, #set_option_dry_run, #set_option_force, #set_option_global, #set_option_index_server
Constructor Details
#initialize ⇒ Deploy
Returns a new instance of Deploy.
71 72 73 74 75 76 77 78 79 |
# File 'lib/flare/tools/cli/deploy.rb', line 71 def initialize super @deploy_index = false @delete = false @flarei = "/usr/local/bin/flarei" @flared = "/usr/local/bin/flared" @iconf = {} @dconf = {} end |
Instance Method Details
#execute(config, args) ⇒ Object
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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/flare/tools/cli/deploy.rb', line 110 def execute(config, args) parse_index_server(config, args) if @deploy_index hostname = config[:index_server_hostname] port = config[:index_server_port] hostname_port = "#{hostname}:#{port}" basedir = Dir.pwd+"/"+hostname_port datadir = basedir+"/data" delete_all(basedir) if @delete && FileTest.exist?(basedir) if FileTest.exist?(basedir) warn "directory already exists: #{basedir}" else Dir.mkdir(basedir) end conf = Flare::Util::FlareiConf.new({ 'server-name' => hostname, 'server-port' => port, 'data-dir' => datadir, }.merge(@iconf)) open(basedir+"/flarei.conf", "w") {|f| f.puts conf} Dir.mkdir(datadir) unless FileTest.exist?(datadir) output_scripts(basedir, datadir, "flarei", @flarei) end args.each do |host| hostname, port, balance, partition = host.split(':', 4) hostname_port = "#{hostname}:#{port}" basedir = Dir.pwd+"/"+hostname_port datadir = basedir+"/data" info "generateing ... #{hostname_port}" delete_all(basedir) if @delete && FileTest.exist?(basedir) if FileTest.exist?(basedir) warn "directory already exists: #{basedir}" else Dir.mkdir(basedir) end if @dconf.has_key?("index-servers") @dconf['index-server-name'] = nil @dconf['index-server-port'] = nil end conf = Flare::Util::FlaredConf.new({ 'index-server-name' => config[:index_server_hostname], 'index-server-port' => config[:index_server_port], 'server-name' => hostname, 'server-port' => port, 'data-dir' => datadir, }.merge(@dconf)) open(basedir+"/flared.conf", "w") {|f| f.puts conf} Dir.mkdir(datadir) unless FileTest.exist?(datadir) output_scripts(basedir, datadir, "flared", @flared) end return 0 end |
#output_scripts(basedir, datadir, name, exec) ⇒ Object
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 |
# File 'lib/flare/tools/cli/deploy.rb', line 81 def output_scripts(basedir, datadir, name, exec) starting = "/sbin/start-stop-daemon --start --quiet --pidfile #{datadir}/#{name}.pid --exec #{exec}" starting += " -- -f #{basedir}/#{name}.conf --daemonize" stopping = "/sbin/start-stop-daemon --stop --retry=TERM/30/KILL/5 --quiet --pidfile #{datadir}/#{name}.pid --exec #{exec}" start = basedir+"/start.sh" open(start, "w") do |f| f.puts "#!/bin/sh" f.puts starting end File.chmod(0744, start) stop = basedir+"/stop.sh" open(stop, "w") do |f| f.puts "#!/bin/sh" f.puts stopping end File.chmod(0744, stop) restart = basedir+"/restart.sh" open(restart, "w") do |f| f.puts "#!/bin/sh" f.puts stopping f.puts "sleep 5" f.puts starting end File.chmod(0744, restart) end |
#setup ⇒ Object
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 |
# File 'lib/flare/tools/cli/deploy.rb', line 24 def setup super set_option_index_server @optp.on('--deploy-index', "deploy the index server") {@deploy_index = true} @optp.on('--delete', "delete existing contents before deploying") {@delete = true} @optp.on('--flarei=PATH', "a path for flarei executable") {|v| @flarei = v} @optp.on('--flared=PATH', "a path for flared executable") {|v| @flared = v} @optp.separator('flarei/flared options:') @optp.on('--back-log=BACKLOG', "back log parameter for listen()" ) {|v| @iconf["back-log"] = v} @optp.on('--thread-pool-size=SIZE', "thread pool size" ) {|v| @iconf["thread_pool_size"] = @dconf["thread_pool_size"] = v} @optp.on('--daemonize=BOOL', "daemonize" ) {|v| @iconf["daemonize"] = @dconf["daemonize"] = v} @optp.on('--data-dir=PATH', "data directory" ) {|v| @iconf["data-dir"] = @dconf["data-dir"] = v} @optp.on('--log-facility=NAME', "log facility" ) {|v| @iconf["log-facility"] = @dconf["log-facility"] = v} @optp.on('--max-connection=SIZE', "max connection" ) {|v| @iconf["max-connection"] = @dconf["max-connection"] = v} @optp.on('--net-read-timeout=MILLISECOND', "read timeout for server connections") {|v| @iconf["net-read-timeout"] = @dconf["net-read-timeout"] = v} @optp.on('--stack-size=KB', "stack size" ) {|v| @iconf["stack-size"] = @dconf["stack-size"] = v} @optp.separator('flarei options:') @optp.on('--monitor-threshold=COUNT', "monitor threshold" ) {|v| @iconf["monitor-threshold"] = v} @optp.on('--monitor-interval=SECOND', "monitor interval" ) {|v| @iconf["monitor-interval"] = v} @optp.on('--monitor-read-timeout=MILLISECOND', "monitor read timeout in millisecond") {|v| @iconf["monitor-read-timeout"] = v} @optp.on('--partition-type=NAME', "partition type(modular)" ) {|v| @iconf["partition-type"] = v} @optp.on('--key-hash-algorithm=NAME' "hash algorithm for key distribution") {|v| @iconf["key-hash-algorithm"] = v} @optp.separator('flared options:') @optp.on('--proxy-concurrency=SIZE', "proxy concurrency" ) {|v| @dconf["proxy-concurrency"] = v} @optp.on('--mutex-slot=SIZE', "mutex slot size" ) {|v| @dconf["mutex-slot"]= v} @optp.on('--reconstruction-interval=MICROSEC', "reconstruction interval" ) {|v| @dconf["reconstruction-interval"] = v} @optp.on('--reconstruction-bwlimit=BYTES', "reconstruction bandwitdh limit" ) {|v| @dconf["reconstruction-bwlimit"] = v} @optp.on('--storage-ap=SIZE', "alignment power" ) {|v| @dconf["storage-ap"] = v} @optp.on('--storage-bucket-size=SIZE', "storage bucket size" ) {|v| @dconf["storage-bucket-size"] = v} @optp.on('--storage-cache-size=SIZE', "storage cache size" ) {|v| @dconf["storage-cache-size"] = v} @optp.on('--storage-compress=NAME', "storage compress type(deflate|bz2|tcbs)") {|v| @dconf["storage-compress"] = v} @optp.on('--storage-large', "strage large" ) {@dconf["storage-large"] = true} @optp.on('--storage-type=NAME', "storage type" ) {|v| @dconf["storage-type"] = v} @optp.on('--proxy-prior-netmask=SIZE', "proxy priority mask (ex. 24 for 255.255.255.0)") {|v| @dconf["proxy-prior-netmask"] = v} @optp.on('--max-total-thread-queue=SIZE', "max total thread queue" ) {|v| @dconf["max-total-thread-queue"] = v} @optp.on('--index-servers=NAME', "index servers" ) {|v| @dconf["index-servers"] = v} @optp.on('--noreply-window-limit=SIZE', "noreply window limit (experimental)") {|v| @dconf["noreply-window-limit"] = v} @optp.on('--mysql-replication', "MySQL replication (experimental)" ) {@dconf["mysql-replication"] = true} @optp.on('--mysql-replication-port=PORT', "MySQL replication port (experimental)") {|v| @dconf["mysql-replication-port"] = v} @optp.on('--mysql-replication-id=ID', "MySQL replication ID (experimental)") {|v| @dconf["mysql-replication-id"] = v} @optp.on('--mysql-replication-db=NAME', "MySQL replication DB (experimental)") {|v| @dconf["mysql-replication-db"] = v} @optp.on('--mysql-replication-table=NAME', "MySQL replication table (experimental)") {|v| @dconf["mysql-replication-table"] = v} @optp.on('--proxy-cache-size=SIZE', "proxy cache entry size (experimental)") {|v| @dconf["proxy-cache-size"] = v} @optp.on('--proxy-cache-expire=SECOND', "cache life-time in second (experimental)") {|v| @dconf["proxy-cache-expire"] = v} end |