class SyncWrap::IyyovDaemon
Provision a gem installed, Iyyov launched and monitored jruby daemon using a standard set of conventions. Can be used directly in the common case, or sub-classed as needed.
Two :sync_paths files are searched for deployment: a config.rb and a jobs.d/<name>.rb. If concrete or .erb variants of these are not found than an (empty) default/config.rb and a generic default/daemon.rb.erb is used. Again, these will work in the common case.
Host component dependencies: <Distro>, JRubyVM, RunUser, Iyyov
Attributes
Name of the gem (set if different than name)
An optional secondary instance name, useful if running more than one of 'name' on a host (default: nil)
The daemon process name, also used for service_dir (along with any instance) and as the default gem_name. (required)
The (gem) version String (required)
Public Class Methods
# File lib/syncwrap/components/iyyov_daemon.rb, line 48 def initialize( opts = {} ) @gem_version = nil @gem_name = nil @daemon_name = nil @instance = nil super raise "IyyovDaemon#name property not set" unless name raise "IyyovDaemon#version property not set" unless version end
Public Instance Methods
# File lib/syncwrap/components/iyyov_daemon.rb, line 60 def gem_name @gem_name || @name end
# File lib/syncwrap/components/iyyov_daemon.rb, line 64 def install standard_install end
Protected Instance Methods
# File lib/syncwrap/components/iyyov_daemon.rb, line 134 def config_source sconf = "var/#{name_instance}/config.rb" unless find_source( sconf ) sconf = "var/#{name}/config.rb" unless find_source( sconf ) sconf = 'var/iyyov/default/config.rb' end end sconf end
# File lib/syncwrap/components/iyyov_daemon.rb, line 115 def daemon_service_dir service_dir( name, instance ) end
# File lib/syncwrap/components/iyyov_daemon.rb, line 123 def job_source sjob = "var/iyyov/jobs.d/#{name_instance}.rb" unless find_source( sjob ) sjob = "var/iyyov/jobs.d/#{name}.rb" unless find_source( sjob ) sjob = "var/iyyov/default/daemon.rb.erb" end end sjob end
# File lib/syncwrap/components/iyyov_daemon.rb, line 119 def name_instance [ name, instance ].compact.join( '-' ) end
# File lib/syncwrap/components/iyyov_daemon.rb, line 111 def rput_service_config rput( config_source, "#{daemon_service_dir}/config.rb", user: run_user ) end
# File lib/syncwrap/components/iyyov_daemon.rb, line 70 def standard_install create_service_dir( name, instance ) conf_changes = rput_service_config pid, ver = capture_running_version( name, instance ) gem_install( gem_name, version: version ) if ver != version # The job_source may contain more than just this daemon # (i.e. additional tasks, etc.) Even if this is the # default/daemon.rb.erb, it might have just been changed to # that. So go ahead an rput in any case. job_changes = rput( job_source, "#{iyyov_run_dir}/jobs.d/#{name_instance}.rb", user: run_user ) job_changes += iyyov_install_jobs # If we found a daemon pid then kill if either: # # (1) the version is the same but there was a config change or # hashdot was updated (i.e. new jruby version). In this case # Iyyov should be up to restart the daemon. # # (2) We are :imaging, in which case we want a graceful # shutdown. In this case Iyyov should have already been kill # signalled itself and will not restart the daemon. # # In all cases there is the potential that the process has # already stopped (i.e. crashed, etc) between above pid capture # and the kill. Ignore kill failures. if pid && ( ( ver == version && ( !conf_changes.empty? || state[ :hashdot_updated ] ) ) || state[ :imaging ] ) rudo( "kill #{pid} || true" ) end conf_changes + job_changes end