All pastes #567736 Raw Edit

sdf

public ruby v1 · immutable
·published 2007-06-15 03:21 UTC
rendered paste body
#!/usr/bin/env ruby# This program reads an xml file and scans the configured directory to preform either a purge# or encrypt action or both.### Setup the environmentrequire 'thread'require 'rubygems'require 'xmlsimple'require 'lib/logger'CONFIG_INFO = XmlSimple.xml_in('conf/adeptraSecure.xml', { 'KeyAttr' => 'name' })[Socket.gethostname.downcase] or raise("Hostname \"#{Socket.gethostname.downcase}\" XML section doesnt exist or is incorrect")$LOG = Logger.new(CONFIG_INFO[0]['log'], 'daily') require 'lib/gnupg'require 'lib/threadpool'require 'lib/searchfile'require 'lib/appcommon'require 'lib/memory_profiler'# Start the garbage collection information log.  This will help track down issues IE memory leaks.#MemoryProfiler.start(:log => File.dirname(CONFIG_INFO[0]['log']) + '/gc_memory.log')# Detach from the TTY#AppCommon.daemonize# Create array where timer thread code blocks will be storedtimer_threads_encrypt =  []timer_threads_purge = []# Create object for thread poolencrypt_pool = ThreadPool.new(CONFIG_INFO[0]['maxEncryptThreads'].to_i)purge_pool = ThreadPool.new(CONFIG_INFO[0]['maxPurgeThreads'].to_i)# Create gnupg objectgnupg = GnuPG.new(                  :binary=> CONFIG_INFO[0]['gpgbin'],                  :homedir=> CONFIG_INFO[0]['gpghome'],                  :recipient=> CONFIG_INFO[0]['keyname']                 )# Loop through XML application config, build out timer threads for encryption processingdef test(encrypt, timer_threads_encrypt, encrypt_pool)    next if encrypt['encryptionEnabled'][0].downcase == 'false'    timer_threads_encrypt << Thread.new(encrypt) do        while true            if encrypt_pool.pool_count.empty?                if encrypt['recursiveScan'][0].downcase == 'false'                    SearchFile.match_recursive(encrypt['directory'][0],encrypt['encryptFilesOlderThan'][0].to_i).each do |run|                        encrypt_pool.dispatch(run) do |run|                            $LOG.info("ADD-QUEUE -> encrypt #{run}")                            gnupg.encryptfile(run)                            $LOG.info("COMPLETED -> encrypt #{run}")                        end                    end                    SearchFile.match(encrypt['directory'][0],encrypt['encryptFilesOlderThan'][0].to_i).each do |run|                        encrypt_pool.dispatch(run) do |run|                            $LOG.info("ADD-QUEUE -> encrypt #{run}")                            gnupg.encryptfile(run)                            $LOG.info("COMPLETED -> encrypt #{run}")                        end                    end                end            end                        #Go back to sleep until we need to start processing again            sleep(encrypt['encryptRunEvery'][0].to_i * 60)        end    endendCONFIG_INFO[0]['application'].each { |encrypt| test(encrypt, timer_threads_encrypt, encrypt_pool) }# Loop through XML application config, build out timer threads for purging processing#CONFIG_INFO[0]['application'].each do |purge|#    next if purge['purgingEnabled'][0].downcase == 'false'#    timer_threads_purge << Thread.new(purge) do#        while true#            if purge_pool.pool_count.empty?#                if purge['recursiveScan'][0].downcase == 'true'#                    SearchFile.match_recursive(purge['directory'][0],purge['purgeFilesOlderThan'][0].to_i).each do |run|#                        purge_pool.dispatch(run) do |run|#                            $LOG.info("ADD-QUEUE -> purge #{run}")#                            #remove process here#                            $LOG.info("COMPLETED -> purge #{run}")#                        end#                    end#                end#            end#            #Go back to sleep until we need to start processing again#            sleep(purge['purgeRunEvery'][0].to_i * 60)#        end#    end#end# Start main timer threadstimer_threads_encrypt.each { |aThread|  aThread.join } #unless timer_threads_encrypt.empty?timer_threads_purge.each { |bThread|  bThread.join } #unless timer_threads_encrypt.empty?