#!/usr/bin/env ruby require 'rbbt-util' require 'rbbt/util/simpleopt' $0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands options = SOPT.setup < -h--help Print this help -e--environment* Execution environment: production or development -Ho--Host* Host name -B--Bind* Bind IP -p--port* TCP port -s--server* Server type: thin, webrick, unicorn, etc -f--finder Start server with finder functionality -fs--file_server Activate file serving for resources -R--Rserve_session* Rserve session to use, otherwise start new one -wd--workdir* Change the working directory of the workflow --views* Directory with view templates --stream Activate streaming of workflow tasks --options* Additional options for server (e.g. option1=value1;option2=value2) EOF if options[:help] if defined? rbbt_usage rbbt_usage else puts SOPT.usage end exit 0 end if options[:workdir] require 'rbbt/workflow' Workflow.workdir = options[:workdir] end options[:Port] = options["port"] options[:server] = options["server"] options[:Host] = options["Host"] options[:Bind] = options["Bind"] options[:Host] ||= "0.0.0.0" options[:Bind] ||= "0.0.0.0" app = ARGV.shift ENV["RServe-session"] = options[:RServe_session] || app app_dir = Rbbt.etc.app_dir.exists? ? Path.setup(Rbbt.etc.app_dir.read.strip) : Rbbt.apps.find app_dir = app_dir[app] server = options[:server] || 'puma' Misc.in_dir(app_dir) do require 'rack' ENV["RBBT_FINDER"] = "true" if options[:finder] ENV["RACK_ENV"] = options[:environment] if options.include?(:environment) ENV["RBBT_VIEWS_DIR"] = options[:views] if options.include?(:views) ENV["RBBT_REST_FILE_SERVER"] = "true" if options[:file_server] if options[:stream] #raise "No streaming available for any server other than puma" unless options[:server] =~ /^puma/ raise "No streaming available for any server other than unicorn" unless options[:server] =~ /^unicorn/ ENV["RBBT_WORKFLOW_TASK_STREAM"] = 'true' end config_ru_file = File.exist?('./config.ru') ? './config.ru' : Rbbt.share['config.ru'].find if options[:options] options[:options].split(";").each do |pair| name, _sep, value = pair.partition("=") name = name[1..-1].to_sym if name[0] == ':' value = value.to_i if value =~ /^\d+$/ options[name] = value end end case server when 'passenger' system ENV, "env RBBT_LOG=0 passenger start -R '#{config_ru_file}' -p #{options[:port] || "2887"}" when 'puma_alt' system ENV, "puma '#{config_ru_file}' -p #{options[:Port] || "2887"} -w 3 -t 8:32 --preload" else options[:config] = config_ru_file Rack::Server.start(options) end end #!/usr/bin/env ruby require 'rbbt-util' require 'rbbt/util/simpleopt'