class SyncWrap::Iyyov
Provision the Iyyov job scheduler and process monitor via jruby_gem_install. The installation setup and configuration templates assume use of a jobs.d directory, as supported in Iyyov 1.3.0.
Attributes
Public Class Methods
# File lib/syncwrap/components/iyyov.rb, line 34 def initialize( opts = {} ) @iyyov_version = '1.3.0' super end
Public Instance Methods
Given name(-instance), check for name.pid in service_dir and extract the version number from the associated cmdline. If this is running out of installed gem directory (Iyyov itself, standard Iyyov daemons) then cmdline should reference the gem version. Returns [pid, version] or nil if not found running
# File lib/syncwrap/components/iyyov.rb, line 71 def capture_running_version( name, instance = nil ) sdir = service_dir( name, instance ) code, out = capture( " pid=$(< #{sdir}/#{name}.pid) if [[ $(< /proc/$pid/cmdline) =~ -(([0-9]+)(\\.[0-9A-Za-z]+)+)[-/] ]]; then echo $pid ${BASH_REMATCH[1]} exit 0 fi exit 91 ", user: run_user, accept[[0,1,91] ) # Above accepts exit 1 as from $(< missing-file), since it would # be a race to pre-check. Note '\\' escape is for this # ruby here-doc. if code == 0 pid, ver = out.strip.split( ' ' ) [ pid.to_i, ver ] else nil end end
Deploy iyyov gem, init.d script or systemd unit, and at least an empty jobs.rb.
# File lib/syncwrap/components/iyyov.rb, line 42 def install # Shorten if the desired iyyov version is already running _,ver = capture_running_version( 'iyyov' ) if ver != iyyov_version install_run_dir #as root install_iyyov_gem #as root install_iyyov_init #as root iyyov_restart unless state[ :imaging ] #as root true elsif state[ :hashdot_updated ] && !state[ :imaging ] iyyov_restart true end # FIXME: There is a potential race condition brewing here. If # Iyyov is restarted, then job changes (i.e. jobs.d files) are # immediately made before Iyyov is done reloading, then those # changes may not be detected. Thus job upgrades may not occur. # This might be best fixed in Iyyov itself. iyyov_stop if state[ :imaging ] false end
Ensure install of same gem version as init.d script or unit file
# File lib/syncwrap/components/iyyov.rb, line 135 def install_iyyov_gem jruby_gem_install( 'iyyov', version: iyyov_version ) end
Install iyyov daemon init.d script or service unit
# File lib/syncwrap/components/iyyov.rb, line 140 def install_iyyov_init if systemd? changes = rput( 'etc/systemd/system/iyyov.service', user: :root ) systemctl( 'daemon-reload' ) unless changes.empty? systemctl( 'enable', 'iyyov.service' ) else rput( 'etc/init.d/iyyov', user: :root, erb_vars: { lsb: distro.kind_of?( Debian ) } ) # Add to init.d dist_install_init_service( 'iyyov' ) end end
Create iyyov run directory and make sure there is at minimum an empty jobs file. Avoid touching it if already present.
# File lib/syncwrap/components/iyyov.rb, line 120 def install_run_dir # Run as root for merging with the other install fragments. sudo <<-SH mkdir -p #{iyyov_run_dir} mkdir -p #{iyyov_run_dir}/jobs.d SH chown_run_user( '-R', iyyov_run_dir ) sudo <<-SH if [ ! -e #{iyyov_run_dir}/jobs.rb ]; then su #{run_user} -c "touch #{iyyov_run_dir}/jobs.rb" fi SH end
Update remote (run_dir/) iyyov/jobs.rb. If force is true, touch root jobs.rb even if it was not changed: forcing an iyyov config reload. Returns any changes in the rput change format, including any forced mtime update.
# File lib/syncwrap/components/iyyov.rb, line 97 def iyyov_install_jobs( force = false ) changes = [] if force || !state[ :iyyov_root_jobs_installed ] changes += rput( 'var/iyyov/jobs.rb', iyyov_run_dir, user: run_user ) state[ :iyyov_root_jobs_installed ] = true end if force && changes.empty? rudo "touch #{iyyov_run_dir}/jobs.rb" changes << [ '.f..T......', "#{iyyov_run_dir}/jobs.rb" ] end changes end
# File lib/syncwrap/components/iyyov.rb, line 114 def iyyov_run_dir "#{run_dir}/iyyov" end
Reload server configuration
# File lib/syncwrap/components/iyyov.rb, line 172 def reload dist_service( 'iyyov', 'reload' ) end
# File lib/syncwrap/components/iyyov.rb, line 162 def restart dist_service( 'iyyov', 'restart' ) end
# File lib/syncwrap/components/iyyov.rb, line 154 def start dist_service( 'iyyov', 'start' ) end
Output the server status (useful via CLI with –verbose)
# File lib/syncwrap/components/iyyov.rb, line 167 def status dist_service( 'iyyov', 'status' ) end
# File lib/syncwrap/components/iyyov.rb, line 158 def stop dist_service( 'iyyov', 'stop' ) end