diff --git a/.ruby-version b/.ruby-version index be94e6f..a0891f5 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.2.2 +3.3.4 diff --git a/Gemfile.lock b/Gemfile.lock index 3c69a17..27324d3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,67 +1,81 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (7.1.4.1) - actionpack (= 7.1.4.1) - actionview (= 7.1.4.1) - activejob (= 7.1.4.1) - activesupport (= 7.1.4.1) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actioncable (7.2.2) + actionpack (= 7.2.2) + activesupport (= 7.2.2) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (7.2.2) + actionpack (= 7.2.2) + activejob (= 7.2.2) + activerecord (= 7.2.2) + activestorage (= 7.2.2) + activesupport (= 7.2.2) + mail (>= 2.8.0) + actionmailer (7.2.2) + actionpack (= 7.2.2) + actionview (= 7.2.2) + activejob (= 7.2.2) + activesupport (= 7.2.2) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.4.1) - actionview (= 7.1.4.1) - activesupport (= 7.1.4.1) + actionpack (7.2.2) + actionview (= 7.2.2) + activesupport (= 7.2.2) nokogiri (>= 1.8.5) racc - rack (>= 2.2.4) + rack (>= 2.2.4, < 3.2) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.4.1) - actionpack (= 7.1.4.1) - activerecord (= 7.1.4.1) - activestorage (= 7.1.4.1) - activesupport (= 7.1.4.1) + useragent (~> 0.16) + actiontext (7.2.2) + actionpack (= 7.2.2) + activerecord (= 7.2.2) + activestorage (= 7.2.2) + activesupport (= 7.2.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.4.1) - activesupport (= 7.1.4.1) + actionview (7.2.2) + activesupport (= 7.2.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.1.4.1) - activesupport (= 7.1.4.1) + activejob (7.2.2) + activesupport (= 7.2.2) globalid (>= 0.3.6) - activemodel (7.1.4.1) - activesupport (= 7.1.4.1) - activerecord (7.1.4.1) - activemodel (= 7.1.4.1) - activesupport (= 7.1.4.1) + activemodel (7.2.2) + activesupport (= 7.2.2) + activerecord (7.2.2) + activemodel (= 7.2.2) + activesupport (= 7.2.2) timeout (>= 0.4.0) - activestorage (7.1.4.1) - actionpack (= 7.1.4.1) - activejob (= 7.1.4.1) - activerecord (= 7.1.4.1) - activesupport (= 7.1.4.1) + activestorage (7.2.2) + actionpack (= 7.2.2) + activejob (= 7.2.2) + activerecord (= 7.2.2) + activesupport (= 7.2.2) marcel (~> 1.0) - activesupport (7.1.4.1) + activesupport (7.2.2) base64 + benchmark (>= 0.3) bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) - mutex_m - tzinfo (~> 2.0) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) base64 (0.2.0) + benchmark (0.3.0) bigdecimal (3.1.8) - bootsnap (1.18.3) + bootsnap (1.18.4) msgpack (~> 1.2) builder (3.3.0) byebug (11.1.3) @@ -76,7 +90,7 @@ GEM core_docs (0.9.11) yard (~> 0.9.11) crass (1.0.6) - date (3.3.4) + date (3.4.0) debugging (2.1.0) paint (>= 0.9, < 3.0) drb (2.2.1) @@ -99,10 +113,10 @@ GEM interactive_editor (0.0.12) spoon (~> 0.0.6) io-console (0.7.2) - irb (1.14.0) + irb (1.14.1) rdoc (>= 4.0.0) reline (>= 0.4.2) - irbtools (4.0.11) + irbtools (4.1.0) clipboard (>= 1.4, < 3.0) code (>= 0.9.4, < 2.0) coderay (~> 1.1) @@ -112,7 +126,7 @@ GEM fancy_irb (~> 2.1) hirb (~> 0.7, >= 0.7.3) interactive_editor (~> 0.0, >= 0.0.12) - irb (>= 1.12.0, < 1.15) + irb (>= 1.13.0, < 1.15) looksee (~> 5.0) methodfinder (~> 2.2, >= 2.2.5) object_shadow (~> 1.1) @@ -124,7 +138,8 @@ GEM listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.22.0) + logger (1.6.1) + loofah (2.23.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) looksee (5.0.0) @@ -139,9 +154,8 @@ GEM mini_mime (1.1.5) mini_portile2 (2.8.7) minitest (5.25.1) - msgpack (1.7.2) - mutex_m (0.2.0) - net-imap (0.4.14) + msgpack (1.7.3) + net-imap (0.5.0) date net-protocol net-pop (0.1.2) @@ -150,13 +164,14 @@ GEM timeout net-smtp (0.5.0) net-protocol + nio4r (2.7.4) nokogiri (1.16.7) mini_portile2 (~> 2.8.2) racc (~> 1.4) object_shadow (1.1.1) os (1.1.4) paint (2.3.0) - pg (1.5.6) + pg (1.5.9) psych (5.1.2) stringio racc (1.8.1) @@ -165,11 +180,22 @@ GEM rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rails (0.9.5) - actionmailer (>= 0.6.1) - actionpack (>= 1.4.0) - activerecord (>= 1.6.0) - rake (>= 0.4.15) + rackup (2.2.0) + rack (>= 3) + rails (7.2.2) + actioncable (= 7.2.2) + actionmailbox (= 7.2.2) + actionmailer (= 7.2.2) + actionpack (= 7.2.2) + actiontext (= 7.2.2) + actionview (= 7.2.2) + activejob (= 7.2.2) + activemodel (= 7.2.2) + activerecord (= 7.2.2) + activestorage (= 7.2.2) + activesupport (= 7.2.2) + bundler (>= 1.15.0) + railties (= 7.2.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -177,27 +203,41 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) + railties (7.2.2) + actionpack (= 7.2.2) + activesupport (= 7.2.2) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) rake (13.2.1) rb-fsevent (0.11.2) rb-inotify (0.11.1) ffi (~> 1.0) rdoc (6.7.0) psych (>= 4.0.0) - reline (0.5.9) + reline (0.5.10) io-console (~> 0.5) ruby_engine (2.0.3) ruby_version (1.0.3) + securerandom (0.3.1) spoon (0.0.6) ffi stringio (3.1.1) + thor (1.3.2) timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.5.0) + unicode-display_width (2.6.0) + useragent (0.16.10) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) wirb (2.2.2) paint (>= 0.9, < 3.0) - yard (0.9.36) - zeitwerk (2.6.16) + yard (0.9.37) + zeitwerk (2.7.1) PLATFORMS ruby @@ -212,4 +252,4 @@ DEPENDENCIES rails BUNDLED WITH - 2.1.4 + 2.5.22 diff --git a/bin/data_sync b/bin/data_sync new file mode 100755 index 0000000..eff4fe8 --- /dev/null +++ b/bin/data_sync @@ -0,0 +1,39 @@ +#!/bin/bash + +OPTIONS="--defer-constraints --disable-user-triggers --no-sequences" + +# guaguas (54499) +# sumar (36105) +# mataro (86518) +# alcobendas (51099) +# barcelona (86160) +# metro madrid (33249) +# IMI (45047) + +# all tables +pgsync $OPTIONS + +# Manually add new entities here +entities="54499 36105 86518 51099 86160 33249 45047" + +for entity_id in $entities; do + # tenders + pgsync $OPTIONS tenders "WHERE contractor_entity_id = ${entity_id}" + + # contracts + pgsync $OPTIONS contracts "WHERE contractor_entity_id = ${entity_id}" + + # documents + pgsync $OPTIONS documents "WHERE documentable_type = 'Tender' and documentable_id IN (SELECT id from tenders WHERE contractor_entity_id = ${entity_id})" + pgsync $OPTIONS documents "WHERE documentable_type = 'Tender' and documentable_id IN (SELECT id from tenders WHERE contractor_entity_id = ${entity_id})" +done + +# refresh views +bin/rails dbviews:refresh_search +bin/rails dbviews:refresh_analysis + +# refresh elasticsearch +bin/rails chewy:reset + +# refresh internal contracts +bin/rails seed:update_internal_contracts diff --git a/bin/dev b/bin/dev new file mode 100755 index 0000000..740456d --- /dev/null +++ b/bin/dev @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +if ! command -v foreman &> /dev/null +then + echo "Installing foreman..." + gem install foreman +fi + +if [[ $1 = "--sidekiq" ]] || [[ $1 = "-s" ]]; then + foreman start -f Procfile_with_sidekiq.dev +else + foreman start -f Procfile.dev +fi diff --git a/bin/prepare_experiment.rb b/bin/prepare_experiment.rb new file mode 100644 index 0000000..6abd5a8 --- /dev/null +++ b/bin/prepare_experiment.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require "csv" + +# This file dumps in a CSV the questions and answers from the database +# This CSV will be used later to run the experiment (run_experiment.rb) +# Where an experiment is a variation of the parameters used to generate the answer, the prompt and the weights +# that needs to be measured + +CSV.open("base.csv", "wb") do |csv| + csv << ["id", "question", "answer", "prompt", "weights"] + QuestionAnswer.order(id: :asc).each do |qa| + csv << [qa.id, qa.question, qa.answer, qa.prompt, qa.weights] + end +end diff --git a/bin/production_deploy.sh b/bin/production_deploy.sh new file mode 100755 index 0000000..14796af --- /dev/null +++ b/bin/production_deploy.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +curl -k -XPOST -H "Authorization: Token token="$DEPLOY_BOT_TOKEN $PRODUCTION_DEPLOY_URL diff --git a/bin/run_experiment.rb b/bin/run_experiment.rb new file mode 100644 index 0000000..05990ed --- /dev/null +++ b/bin/run_experiment.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require "csv" + +# This file loads the base CSV generated in prepare_experiment.rb, and runs the experiment +# updating the CSV with the new answers and prompts + +if ARGV.size != 1 + raise "Error: the name of the experiment results file is required. It should include the .csv extension" +end + +# Base is generated in prepare_experiment.rb with the current answers and prompts +base_csv = CSV.read("base.csv", headers: true) + +CSV.open(ARGV[0], "wb") do |csv| + csv << ["id","question", "answer", "prompt", "weights", "experiment_answer", "experiment_prompt"] + base_csv.each do |row| + + qa = QuestionAnswer.find(row["id"]) + + responder = Assistant::AnswerQuestionWithOpenAI.new(qa.question) + experiment_prompt, _, experiment_answer = responder.call + + csv << [row["id"], row["question"], row["answer"], row["prompt"], row["weights"], experiment_answer, experiment_prompt] + end +end diff --git a/bin/setup b/bin/setup index 3cd5a9d..ec47b79 100755 --- a/bin/setup +++ b/bin/setup @@ -5,7 +5,7 @@ require "fileutils" APP_ROOT = File.expand_path("..", __dir__) def system!(*args) - system(*args, exception: true) + system(*args) || abort("\n== Command #{args} failed ==") end FileUtils.chdir APP_ROOT do diff --git a/bin/spring b/bin/spring new file mode 100755 index 0000000..fb2ec2e --- /dev/null +++ b/bin/spring @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. + +unless defined?(Spring) + require 'rubygems' + require 'bundler' + + lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) + spring = lockfile.specs.detect { |spec| spec.name == "spring" } + if spring + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem 'spring', spring.version + require 'spring/binstub' + end +end diff --git a/bin/staging_deploy.sh b/bin/staging_deploy.sh new file mode 100755 index 0000000..4b98d3b --- /dev/null +++ b/bin/staging_deploy.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +curl -k -XPOST -H "Authorization: Token token="$DEPLOY_BOT_TOKEN $STAGING_DEPLOY_URL diff --git a/bin/update b/bin/update index 58bfaed..e6daa86 100755 --- a/bin/update +++ b/bin/update @@ -18,11 +18,14 @@ chdir APP_ROOT do system('bundle check') || system!('bundle install') # Install JavaScript dependencies if using Yarn - # system('bin/yarn') + system('bin/yarn') puts "\n== Updating database ==" system! 'bin/rails db:migrate' + puts "\n== Removing compiled assets ==" + system! 'bin/rails assets:clobber' + puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' diff --git a/config/application.rb b/config/application.rb index 02ff5fa..a0a6231 100644 --- a/config/application.rb +++ b/config/application.rb @@ -26,7 +26,7 @@ class Application < Rails::Application # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. # Common ones are `templates`, `generators`, or `middleware`, for example. - config.autoload_lib(ignore: %w(assets tasks)) + config.autoload_lib(ignore: %w[assets tasks]) # Configuration for the application, engines, and railties goes here. # diff --git a/config/environments/development.rb b/config/environments/development.rb index 11a6de1..0a45c01 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -14,7 +14,7 @@ # Show full error reports. config.consider_all_requests_local = true - # Enable server timing + # Enable server timing. config.server_timing = true # Enable/disable caching. By default caching is disabled. @@ -24,9 +24,7 @@ config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store - config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{2.days.to_i}" - } + config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -48,13 +46,12 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true - # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. - # config.action_view.annotate_rendered_view_with_filenames = true + config.action_view.annotate_rendered_view_with_filenames = true - # Raise error when a before_action's only/except options reference missing actions + # Raise error when a before_action's only/except options reference missing actions. config.action_controller.raise_on_missing_callback_actions = true end diff --git a/config/environments/production.rb b/config/environments/production.rb index 396f85a..4cfef67 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -37,6 +37,9 @@ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = true + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } + # Log to STDOUT by default config.logger = ActiveSupport::Logger.new(STDOUT) .tap { |logger| logger.formatter = ::Logger::Formatter.new } @@ -45,7 +48,7 @@ # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] - # Info include generic and useful information about system operation, but avoids logging too much + # "info" includes generic and useful information about system operation, but avoids logging too much # information to avoid inadvertent exposure of personally identifiable information (PII). If you # want to log everything, set the level to "debug". config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") @@ -63,6 +66,9 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + # Only use :id for inspections in production. + config.active_record.attributes_for_inspect = [ :id ] + # Enable DNS rebinding protection and other `Host` header attacks. # config.hosts = [ # "example.com", # Allow requests from example.com diff --git a/config/environments/test.rb b/config/environments/test.rb index d349c35..999db70 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -18,10 +18,7 @@ config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. - config.public_file_server.enabled = true - config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{1.hour.to_i}" - } + config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -49,6 +46,6 @@ # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true - # Raise error when a before_action's only/except options reference missing actions + # Raise error when a before_action's only/except options reference missing actions. config.action_controller.raise_on_missing_callback_actions = true end diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb new file mode 100644 index 0000000..0c5dd99 --- /dev/null +++ b/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin Ajax requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins "example.com" +# +# resource "*", +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index c2d89e2..c010b83 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -4,5 +4,5 @@ # Use this to limit dissemination of sensitive information. # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. Rails.application.config.filter_parameters += [ - :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn + :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn ] diff --git a/config/initializers/new_framework_defaults_7_2.rb b/config/initializers/new_framework_defaults_7_2.rb new file mode 100644 index 0000000..b549c4a --- /dev/null +++ b/config/initializers/new_framework_defaults_7_2.rb @@ -0,0 +1,70 @@ +# Be sure to restart your server when you modify this file. +# +# This file eases your Rails 7.2 framework defaults upgrade. +# +# Uncomment each configuration one by one to switch to the new default. +# Once your application is ready to run with all new defaults, you can remove +# this file and set the `config.load_defaults` to `7.2`. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. +# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html + +### +# Controls whether Active Job's `#perform_later` and similar methods automatically defer +# the job queuing to after the current Active Record transaction is committed. +# +# Example: +# Topic.transaction do +# topic = Topic.create(...) +# NewTopicNotificationJob.perform_later(topic) +# end +# +# In this example, if the configuration is set to `:never`, the job will +# be enqueued immediately, even though the `Topic` hasn't been committed yet. +# Because of this, if the job is picked up almost immediately, or if the +# transaction doesn't succeed for some reason, the job will fail to find this +# topic in the database. +# +# If `enqueue_after_transaction_commit` is set to `:default`, the queue adapter +# will define the behaviour. +# +# Note: Active Job backends can disable this feature. This is generally done by +# backends that use the same database as Active Record as a queue, hence they +# don't need this feature. +#++ +# Rails.application.config.active_job.enqueue_after_transaction_commit = :default + +### +# Adds image/webp to the list of content types Active Storage considers as an image +# Prevents automatic conversion to a fallback PNG, and assumes clients support WebP, as they support gif, jpeg, and png. +# This is possible due to broad browser support for WebP, but older browsers and email clients may still not support +# WebP. Requires imagemagick/libvips built with WebP support. +#++ +# Rails.application.config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp] + +### +# Enable validation of migration timestamps. When set, an ActiveRecord::InvalidMigrationTimestampError +# will be raised if the timestamp prefix for a migration is more than a day ahead of the timestamp +# associated with the current time. This is done to prevent forward-dating of migration files, which can +# impact migration generation and other migration commands. +# +# Applications with existing timestamped migrations that do not adhere to the +# expected format can disable validation by setting this config to `false`. +#++ +# Rails.application.config.active_record.validate_migration_timestamps = true + +### +# Controls whether the PostgresqlAdapter should decode dates automatically with manual queries. +# +# Example: +# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.select_value("select '2024-01-01'::date") #=> Date +# +# This query used to return a `String`. +#++ +# Rails.application.config.active_record.postgresql_adapter_decode_dates = true + +### +# Enables YJIT as of Ruby 3.3, to bring sizeable performance improvements. If you are +# deploying to a memory constrained environment you may want to set this to `false`. +#++ +# Rails.application.config.yjit = true diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..03c166f --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,34 @@ +# This configuration file will be evaluated by Puma. The top-level methods that +# are invoked here are part of Puma's configuration DSL. For more information +# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. + +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. +# +# The ideal number of threads per worker depends both on how much time the +# application spends waiting for IO operations and on how much you wish to +# to prioritize throughput over latency. +# +# As a rule of thumb, increasing the number of threads will increase how much +# traffic a given process can handle (throughput), but due to CRuby's +# Global VM Lock (GVL) it has diminishing returns and will degrade the +# response time (latency) of the application. +# +# The default is set to 3 threads as it's deemed a decent compromise between +# throughput and latency for the average Rails application. +# +# Any libraries that use a connection pool or another resource pool should +# be configured to provide at least as many connections as the number of +# threads. This includes Active Record's `pool` parameter in `database.yml`. +threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch("PORT", 3000) + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart + +# Specify the PID file. Defaults to tmp/pids/server.pid in development. +# In other environments, only set the PID file if requested. +pidfile ENV["PIDFILE"] if ENV["PIDFILE"]