Class: AstroboaCLI::Command::Server
- Defined in:
- lib/astroboa-cli/command/server.rb
Overview
install and setup astroboa server
Instance Attribute Summary
Attributes inherited from Base
#args, #log, #log_file, #options
Instance Method Summary collapse
-
#check ⇒ Object
server:check.
-
#install ⇒ Object
server:install.
-
#start ⇒ Object
server:start.
-
#stop ⇒ Object
server:stop.
Methods inherited from Base
Methods included from Util
#ask, #astroboa_running?, #check_if_running_with_sudo, #create_postgresql_db, #delete_file_content_between_regex, #delete_file_lines, #dir_writable?, #display, #drop_postgresql_db, #error, #extract_archive_command, #fail, #format_with_bang, #gem_available?, #get_password, #get_postgresql_config, #get_server_conf_file, #get_server_configuration, #has_executable, #has_executable_with_version, #has_version_in_grep, #jruby_ok?, #jruby_version_ok?, #linux?, #load_pg_library, #longest, #mac_os_x?, #output_with_bang, #postgres_connectivity?, #process_os_command, #render_template_to_file, #repository?, #repository_in_repos_config?, #repository_in_server_config?, #ruby_ok?, #ruby_version_ok?, #running_with_sudo?, #runs_with_jruby?, #shell, #strip_text_nodes, #unzip_file, #windows?, #write_xml
Constructor Details
This class inherits a constructor from AstroboaCLI::Command::Base
Instance Method Details
#check ⇒ Object
server:check
checks if astroboa server is properly installed and displays the installation paths It also displays if astroboa is running
227 228 229 230 |
# File 'lib/astroboa-cli/command/server.rb', line 227 def check astroboa_installed? display astroboa_running? ? 'astroboa is running' : 'astroboa is not running' end |
#install ⇒ Object
server:install
Installs and setups astroboa server. Use the install command only for the initial installation. If you want to upgrade see ‘astroboa-cli help server:upgrade’ Before you run the install command check the following requirements: + You should have already installed java 1.7 and ruby 1.9.x or later + You are running this command from ruby version 1.9.x or later + You should have the unzip command. It is required for unzipping the downloaded packages + If you choose a database other than derby then the database should be already installed and running and you should know the db admin user and password
-i, –install_dir INSTALLATION_DIRECTORY # The full path to the directory into which to install astroboa # Default is ‘/opt/astroboa’ in linux and ‘$HOME/astroboa’ in mac os x and windows -r, –repo_dir REPOSITORIES_DIRECTORY # The full path of the directory that will contain the repositories configuration and data # Default is $installation_dir/repositories -d, –database DATABASE_VENDOR # Select which database to use for data persistense # Supported databases are: derby, postgres-8.2, postgres-8.3, postgres-8.4, postgres-9.0, postgres-9.1, postgres-9.2, postgres-9.3 # Default is derby -s, –database_server DATABASE_SERVER_IP # Specify the database server ip or FQDN (e.g 192.168.1.100 or postgres.localdomain.vpn) # Default is localhost # Not required if db is derby (it will be ignored) -u, –database_admin DB_ADMIN_USER # The user name of the database administrator # If not specified it will default to ‘postgres’ for postgresql db # Not required if db is derby (it will be ignored)
For security reasons (to avoid leaving the password in command history) there is no command option for specifing the password of the database administrator. But do not worry, the password will be asked from you during the installation process A db password is required only if you choose postgres as your database. If you require to do an unattended, non-interactive installation (e.g. run astroboa-cli from chef or puppet) then you can call astroboa-cli like this: $ echo “postgres_admin_password” | astroboa-cli server:install -d postgres-9.3 Take care that the db password is saved for later use (repositories creation / deletion) in astroboa server config (~/.astoboa-conf.yml in mac and /etc/astroboa/astroboa-conf.yml in linux). This file is created to be readable / writable only by root in linux and only by the user that does the installation in mac os x.
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/astroboa-cli/command/server.rb', line 44 def install @torquebox_download_url = 'http://www.astroboa.org/releases/astroboa/latest/torquebox-dist-2.0.3-bin.zip' @torquebox_package = @torquebox_download_url.split("/").last @torquebox_version_download_url = 'http://www.astroboa.org/releases/astroboa/latest/TORQUEBOX-VERSION' @torquebox_version_file = @torquebox_version_download_url.split("/").last @astroboa_ear_download_url = 'http://www.astroboa.org/releases/astroboa/latest/astroboa.ear' @astroboa_ear_package = @astroboa_ear_download_url.split("/").last @astroboa_setup_templates_download_url = 'http://www.astroboa.org/releases/astroboa/latest/astroboa-setup-templates.zip' @astroboa_setup_templates_package = @astroboa_setup_templates_download_url.split("/").last @schemas_download_url = 'http://www.astroboa.org/releases/astroboa/latest/schemas.zip' @schemas_package = @schemas_download_url.split("/").last @astroboa_version_download_url = 'http://www.astroboa.org/releases/astroboa/latest/ASTROBOA-VERSION' @astroboa_version_file = @astroboa_version_download_url.split("/").last @install_dir = [:install_dir] ||= mac_os_x? || windows? ? File.join(Dir.home, 'astroboa') : '/opt/astroboa' @install_dir = File. @install_dir # if provided path was not absolute expand it @repo_dir = [:repo_dir] ||= File.join(@install_dir, "repositories") @repo_dir = File. @repo_dir # if provided path was not absolute expand it display <<-MSG.gsub(/^ {4}/, '') Starting astroboa server installation Server will be installed in: #{@install_dir} Repository Data and config will be stored in: #{@repo_dir} MSG @database = [:database] ||= 'derby' =<<-MSG.gsub(/^ {4}/, '') The selected database '#{@database}' is not supported. Supported databases are: derby, postgres-8.2, postgres-8.3, postgres-8.4, postgres-9.0, postgres-9.1, postgres-9.2, postgres-9.3 MSG error unless %W(derby postgres-8.2 postgres-8.3 postgres-8.4 postgres-9.0 postgres-9.1 postgres-9.2 postgres-9.3).include?(@database) if @database.split("-").first == "postgres" @database_admin = [:database_admin] ||= "postgres" @database_admin_password = get_password("Please enter the password for postgresql admin user '#{@database_admin}': ") else @database_admin = "sa" @database_admin_password = "" end @database_server = [:database_server] ||= "localhost" display "repository database is '#{@database}' accessed with user: '#{@database_admin}'" display "Database server IP or FQDN is: #{@database_server}" if @database.split("-").first == "postgres" # check if all requirement are fulfilled before proceeding with the installation check_installation_requirements download_server_components install_server_components save_server_configuration create_central_identity_repository set_astroboa_owner cleanup_installation # export_environment_variables end |
#start ⇒ Object
server:start
starts astroboa server in the foreground or as a background process.
If you start it as a foreground process you can stop it by using Ctrl+c If you start is as a background process use ‘astroboa-cli server:stop’ to gracefully stop astroboa
It is recommented to use this command only during development and install astroboa as a service in production systems. If you install astroboa as a service it will be automatically started every time your system starts.
To find how to install and start / stop astroboa as a service see: ‘astroboa-cli help service:install’ ‘astroboa-cli help service:start’ ‘astroboa-cli help service:stop’
-b, –background # Starts astroboa in the background. Use ‘astroboa-cli server:stop’ to gracefully stop it -j, –jvm_options JVM_OPTIONS # java options for starting the astroboa jvm
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/astroboa-cli/command/server.rb', line 122 def start error 'astroboa is already running' if astroboa_running? astroboa_installed? server_config = get_server_configuration # Astroboa runs inside torquebox (a special version of JBOSS AS 7) which requires jruby # Torquebox comes with the required jruby installed. # If the env variable 'JRUBY_HOME' exists torquebox does not use ts own jruby but that pointed by the env variable # So we unset the variable (just in case it is set) to enforce torquebox to use its own jruby ENV.delete('JRUBY_HOME') # set jruby opts so that jruby runs in 1.9 mode ENV['JRUBY_OPTS'] = '--1.9' # don't send the gemfile from the current app ENV.delete('BUNDLE_GEMFILE') # append java options to the environment variable ENV['APPEND_JAVA_OPTS'] = [:jvm_options] command = File.join(server_config['install_dir'], 'torquebox', 'jboss', 'bin', 'standalone.sh') jboss_log_file = File.join(server_config['install_dir'], 'torquebox', 'jboss', 'standalone', 'log', 'server.log') # We should always run astroboa as the user that owns the astroboa installation # otherwise problems with file permissions may be encountered. # If the current process owner is not the astroboa owner then we check if process owner # is the super user (i.e astroboa-cli is run with sudo). # If process owner is super user we change the process owner # to be the astroboa user (we can do that since process run with sudo privileges) and we run astroboa. # If process owner is not super user we give a notice that astroboa-cli should be executed with sudo and exit. user = ENV['USER'] if mac_os_x? || linux? user = ENV['USERNAME'] if windows? install_dir = server_config['install_dir'] astroboa_uid = File.stat(install_dir).uid astroboa_user = Etc.getpwuid(astroboa_uid).name process_uid = Process.uid process_user = Etc.getpwuid(process_uid).name if astroboa_uid != process_uid display "You are running astroboa-cli as user: #{process_user} and astroboa should run as user: #{astroboa_user}" display "We need sudo privileges in order to do this. Lets check..." if process_uid != 0 error <<-MSG.gsub(/^ {8}/, '') You are not running with sudo privileges. Please run astroboa-cli with sudo If you installed ruby with rbenv you need to install 'rbenv-sudo' plugin and then run 'rbenv sudo astroboa-cli server:start' For 'rbenv-sudo' check ruby installation instructions at https://github.com/betaconcept/astroboa-cli MSG else Process::UID.change_privilege(astroboa_uid) display "Running with sudo: OK" if user != 'root' display "You are root: OK" if user == 'root' end end if [:background] ENV['JBOSS_PIDFILE'] = '/var/run/astroboa/astroboa.pid' ENV['LAUNCH_JBOSS_IN_BACKGROUND'] = 'true' display "Astroboa is starting in the background..." display "You can check the log file with 'tail -f #{jboss_log_file}'" display "When server startup has finished access astroboa console at: http://localhost:8080/console" exec %(#{command} > /dev/null 2>&1 &) #exec %(#{command} &), :pgroup => true, [:in, :out, :err] => '/dev/null' else display "Astroboa is starting in the foreground..." display "When server startup has finished access astroboa console at: http://localhost:8080/console" exec %(#{command}) end end |
#stop ⇒ Object
server:stop
stops astroboa server if it is already running. It is recommented to use this command only during development and install astroboa as a service in production systems. To find how to install and start / stop astroboa as a service see: ‘astroboa-cli help service:install’ ‘astroboa-cli help service:start’ ‘astroboa-cli help service:stop’
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/astroboa-cli/command/server.rb', line 206 def stop error 'Astroboa is not running' unless astroboa_running? server_config = get_server_configuration jboss_cli_command = File.join(server_config['install_dir'], 'torquebox', 'jboss', 'bin', 'jboss-cli.sh') shutdown_command = "#{jboss_cli_command} --connect --command=:shutdown" output = `#{shutdown_command}` if mac_os_x? output = `su - astroboa -c "#{shutdown_command}"` if linux? command_status = $?.to_i if command_status == 0 && output =~ /success/ display "Astroboa has been successfully stopped" else error "Failed to shutdown Astroboa. Message is: #{output}" end end |