Skip to content

Instantly share code, notes, and snippets.

@marzzz21
Created August 25, 2016 10:44
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/fb3a10251343d061e865d8ce55153bfd to your computer and use it in GitHub Desktop.
Save marzzz21/fb3a10251343d061e865d8ce55153bfd to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
require_relative 'workerpool'
require_relative 'common'
require_relative 'mirrordatabase'
require_relative 'watcher'
class MirrorSyncDaemon
VERSION = "1.1.0"
PID_FILE = '/var/run/mirrorsync.pid'
LOG_FILE = DAEMON_LOG
attr_reader :quit
#--------------------------------------------------------------------------
def run!
check_pid #check_status
daemonize
write_pid
trap_signals
redirect_output
log "Running mirror sync"
init_db
init_workers
init_watcher
while !quit
sleep(2)
end
log "Killing all sub processes"
kill_all_sub_processes
log "Exiting mirror sync"
end
. . .
require 'minitest/autorun'
require_relative '../lib/mirrorsyncdaemon'
class MirrorSyncDaemonTest < Mini::Test
def test_check_status_checks_PID_FILE
@workerpool = Minitest::Mock.new
@common = Minitest::Mock.new
@mirrordatabase = Minitest::Mock.new
@watcher = Minitest::Mock.new
mirrorsyncdaemon = MirrorSyncDaemon.new
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment