Skip to content

Instantly share code, notes, and snippets.

@marzzz21
Created September 13, 2016 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marzzz21/4dc391aaf0483490db1c81d38550af90 to your computer and use it in GitHub Desktop.
Save marzzz21/4dc391aaf0483490db1c81d38550af90 to your computer and use it in GitHub Desktop.
MirrorSyncDaemon
#run
#check_status
deletes the PID_FILE if it exists but contains invalid PID
does nothing and continues with the script if PID_FILE does not exist
#check_pid_status
Process(65987) is already running.
exits with exit code:1 if process is already running
Process with pid=65987 is already running but is owned by a different user
exits with exit code:1 if process is already running and is owned by a different user
#daemonize
RUBY_VERSION < 1.9
should fork the current process
should set the forked process as a session leader
should set the working directory to root(/)
RUBY_VERSION > 1.9
should invoke Process.daemon skipping the if block
#write_pid
writes the pid on the PID_FILE if it doesn't exist
raises Errno::EEXIST if PID_FILE already exists, delete it, retry in writing the PID_FILE
#trap_signals
trap_signals
traps the :USR1 signal
#redirect_output
creates the LOG_FILE
reassociates the I/O stream of stderr to the LOG_FILE, and stdout to stderr
syncs both stdout and stderr
#init_db
fetches current syncing mirrors and updates their end sync
#init_workers
creates a WorkerPool with a size based on the defined worker count
logs the error and exits with code 1 when get_worker_count raises an error
Finished in 0.01912 seconds (files took 0.12714 seconds to load)
17 examples, 0 failures
/home/mihaelkeehl/rise-chef-repo/cookbooks/mirror/files/default/scripts/bundle/ruby/2.3.0/gems/rspec-mocks-3.5.0/lib/rspec/mocks/space.rb:51:in `raise_lifecycle_message': The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported. (RSpec::Mocks::OutsideOfExampleError)
from /home/mihaelkeehl/rise-chef-repo/cookbooks/mirror/files/default/scripts/bundle/ruby/2.3.0/gems/rspec-mocks-3.5.0/lib/rspec/mocks/space.rb:11:in `proxy_for'
from /home/mihaelkeehl/rise-chef-repo/cookbooks/mirror/files/default/scripts/bundle/ruby/2.3.0/gems/rspec-mocks-3.5.0/lib/rspec/mocks/test_double.rb:111:in `__mock_proxy'
from /home/mihaelkeehl/rise-chef-repo/cookbooks/mirror/files/default/scripts/bundle/ruby/2.3.0/gems/rspec-mocks-3.5.0/lib/rspec/mocks/test_double.rb:74:in `method_missing'
from /home/mihaelkeehl/rise-chef-repo/cookbooks/mirror/files/default/scripts/lib/mirrorsyncdaemon.rb:54:in `block in init_workers'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment