<commit_before>require 'capistrano'
require 'capistrano/version'

module CapistranoUnicorn
  class CapistranoIntegration
    def self.load_into(capistrano_config)
      capistrano_config.load do
        # Check if remote file exists
        #
        def remote_file_exists?(full_path)
          'true' ==  capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
        end

        # Check if process is running
        #
        def remote_process_exists?(pid_file)
          capture("ps -p $(cat #{pid_file}) ; true").strip.split("\n").size == 2
        end

        # Get unicorn master process PID
        #
        def unicorn_get_pid
          if remote_file_exists?(unicorn_pid) && remote_process_exists?(unicorn_pid)
            capture("cat #{unicorn_pid}")
          end
        end

        # Send a signal to unicorn master process
        #
        def unicorn_send_signal(pid, signal)
          run "#{try_sudo} kill -s #{signal} #{pid}"
        end

        # Set unicorn vars
        #
        before [ 'unicorn:start', 'unicorn:stop', 'unicorn:shutdown', 
                 'unicorn:restart', 'unicorn:reload', 'unicorn:add_worker',  
                 'unicorn:remove_worker' ] do
          _cset(:unicorn_pid, "#{fetch(:current_path)}/tmp/pids/unicorn.pid")
          _cset(:app_env, (fetch(:rails_env) rescue 'production'))
          _cset(:unicorn_env, (fetch(:app_env)))
          _cset(:unicorn_bin, "unicorn")
        end

        #
        # Unicorn rake tasks
        #
        namespace :unicorn do
          desc 'Start Unicorn master process'
          task :start, :roles => :app, :except => {:no_release => true} do
            if remote_file_exists?(unicorn_pid)
              if remote_process_exists?(unicorn_pid)
                logger.important("Unicorn is already running!", "Unicorn")
                next
              else
                run "rm #{unicorn_pid}"
              end
            end

            primary_config_path = "#{current_path}/config/unicorn.rb"<commit_msg>Lazy load current_path for capistrano/multistage<commit_after>require 'capistrano'
require 'capistrano/version'

module CapistranoUnicorn
  class CapistranoIntegration
    def self.load_into(capistrano_config)
      capistrano_config.load do
        # Check if remote file exists
        #
        def remote_file_exists?(full_path)
          'true' ==  capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
        end

        # Check if process is running
        #
        def remote_process_exists?(pid_file)
          capture("ps -p $(cat #{pid_file}) ; true").strip.split("\n").size == 2
        end

        # Get unicorn master process PID
        #
        def unicorn_get_pid
          if remote_file_exists?(unicorn_pid) && remote_process_exists?(unicorn_pid)
            capture("cat #{unicorn_pid}")
          end
        end

        # Send a signal to unicorn master process
        #
        def unicorn_send_signal(pid, signal)
          run "#{try_sudo} kill -s #{signal} #{pid}"
        end

        # Set unicorn vars
        #
        before [ 'unicorn:start', 'unicorn:stop', 'unicorn:shutdown', 
                 'unicorn:restart', 'unicorn:reload', 'unicorn:add_worker',  
                 'unicorn:remove_worker' ] do
          _cset(:unicorn_pid) { "#{fetch(:current_path)}/tmp/pids/unicorn.pid" }
          _cset(:app_env) { (fetch(:rails_env) rescue 'production') }
          _cset(:unicorn_env) { fetch(:app_env) }
          _cset(:unicorn_bin, "unicorn")
        end

        #
        # Unicorn rake tasks
        #
        namespace :unicorn do
          desc 'Start Unicorn master process'
          task :start, :roles => :app, :except => {:no_release => true} do
            if remote_file_exists?(unicorn_pid)
              if remote_process_exists?(unicorn_pid)
                logger.important("Unicorn is already running!", "Unicorn")
                next
              else
                run "rm #{unicorn_pid}"
              end
            end

            primary_config_path = "#{current_path}/config/unicorn.rb"
{'fraction_non_alphanumeric': 0.10801564027370479, 'fraction_numerical': 0.0004887585532746823, 'mean_word_length': 2.0139911634756995, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6953237', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1202, 'n_words': 269}