Class: AstroboaCLI::Command::Service

Inherits:
Base
  • Object
show all
Defined in:
lib/astroboa-cli/command/service.rb

Overview

setup astroboa as a system service (daemon) that automatically starts on boot

Constant Summary collapse

LAUNCHD_CONFIG =
'/Library/LaunchDaemons/com.betaconcept.astroboa.plist'

Instance Attribute Summary

Attributes inherited from Base

#args, #log, #log_file, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, namespace

Methods included from Util

#ask, #astroboa_running?, #check_if_running_with_sudo, #create_postgresql_db, #create_postgresql_db_with_jdbc, #delete_file_content_between_regex, #delete_file_lines, #dir_writable?, #display, #drop_postgresql_db, #drop_postgresql_db_with_jdbc, #error, #extract_archive_command, #fail, #format_with_bang, #gem_available?, #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?, #longest, #mac_os_x?, #output_with_bang, #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?, #save_server_configuration, #shell, #strip_text_nodes, #unzip_file, #windows?, #write_xml

Constructor Details

This class inherits a constructor from AstroboaCLI::Command::Base

Instance Method Details

#checkObject

service:check

checks if astroboa is setup as a system service and whether astroboa service is running



93
94
95
96
# File 'lib/astroboa-cli/command/service.rb', line 93

def check
  check_launchd_service if mac_os_x?
  display "We do not yet support checking the status of astroboa service in linux and windows" if windows? || linux?
end

#setupObject

service:setup

Setups astroboa as a system service (daemon). It requires that you have already installed astroboa using ‘astroboa-cli server:install’. Astroboa service will automatically start on system boot.

To start and stop astroboa when it is installed as a system service use ‘astroboa-cli service:start’ and ‘astroboa-cli service:stop’

IMPORTANT NOTICE: When astroboa runs as a service the internallly installed JRUBY version and GEMS are used instead of the JRUBY used to run astroboa-cli. When astroboa is started through ‘server:start’ command, the same JRUBY version and GEMS used by astroboa-cli will be used. This behaviour shields the production server from the ruby setup that the astroboa-cli user might have and even allows to test newer ruby versions and gems during development (run astroboa with server:start) and use more stable ones during production (setup astroboa as a service and run it through service:start).

In MAC OS X astroboa is setup as a system launchd daemon. Therefore, you must be authorized to use ‘sudo’ in order to use the ‘service:setup’ command. If you want to disable astroboa service from automatically running on each boot then change the ‘RunAtLoad’ key to ‘false’ in ‘/Library/LaunchDaemons/com.betaconcept.astroboa.plist’

In linux astroboa is setup as an upstart service (requires ubuntu or debian or a linux distro that supports upstart)



32
33
34
35
36
37
# File 'lib/astroboa-cli/command/service.rb', line 32

def setup
  error "Astroboa is running. Please first stop astoboa using 'astroboa-cli server:stop' and run the command again" if astroboa_running?
  install_launchd_service if mac_os_x?
  install_upstart_service if linux?
  display "We do not yet support installing astroboa as a service in windows" if windows?
end

#startObject

service:start

Starts astroboa service

To install astroboa as a system service you should run ‘astroboa-cli service:setup’

In MAC OS X you may also start the service by running: ‘launchctl start com.betaconcept.astroboa’

In Linux you may also start the service by running: ‘service astroboa start’



65
66
67
68
# File 'lib/astroboa-cli/command/service.rb', line 65

def start
  error "Astroboa is already running" if astroboa_running?
  start_launchd_service if mac_os_x?
end

#stopObject

service:stop

Stops astroboa service

To setup astroboa as a system service you should run ‘astroboa-cli service:setup’

In MAC OS X you may also stop the service by running: ‘launchctl unload /Library/LaunchDaemons/com.betaconcept.astroboa.plist’ DO NOT use ‘launchctl stop com.betaconcept.astroboa’ because launchd will keep restarting the service. If you use ‘launchctl unload /Library/LaunchDaemons/com.betaconcept.astroboa.plist’ to stop the service then you may restart it by using astroboa-cli service:start or run ‘launchctl load /Library/LaunchDaemons/com.betaconcept.astroboa.plist’ and then ‘launchctl start com.betaconcept.astroboa’ In any case we recommend to use the commands provided by astroboa-cli that do all the necessary checks and remove the launchd complexity!

In Linux you may also stop the service by running: ‘service astroboa stop’



84
85
86
87
# File 'lib/astroboa-cli/command/service.rb', line 84

def stop
  error "Astroboa is not running" unless astroboa_running?
  stop_launchd_service if mac_os_x?
end

#unsetObject

service:unset

unsets astroboa from being a system service (daemon).

In MAC OS X it will unload astroboa from launchd and then remove astroboa from the list of system daemons (those that are loaded everytime the system boots).

In LINUX it will unconfigure astroboa as an upstart service



47
48
49
50
51
52
# File 'lib/astroboa-cli/command/service.rb', line 47

def unset
  error "Astroboa is running. Please first stop astoboa using 'astroboa-cli service:stop' and run the command again" if astroboa_running?
  unset_launchd_service if mac_os_x?
  unset_upstart_service if linux?
  display "We do not yet support installing astroboa as a service in windows" if windows?
end