From 144c2f8f90d481febac720a67ca88c1e7b378a53 Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Tue, 19 Jul 2022 15:08:21 +0100 Subject: [PATCH] Remove DReSA-specific production config #709 --- Gemfile | 13 +++------- Gemfile.lock | 10 -------- config/logrotate.conf | 31 ----------------------- config/schedule.example.yml | 6 ----- config/schedule.rb | 36 -------------------------- config/unicorn.rb | 20 --------------- scripts/pgsql_backup.sh | 43 ------------------------------- scripts/pgsql_restore.sh | 50 ------------------------------------- scripts/update_tess.sh | 29 +++++++++++++++++++++ update_tess.sh | 47 ---------------------------------- 10 files changed, 33 insertions(+), 252 deletions(-) delete mode 100644 config/unicorn.rb delete mode 100644 scripts/pgsql_backup.sh delete mode 100644 scripts/pgsql_restore.sh create mode 100755 scripts/update_tess.sh delete mode 100644 update_tess.sh diff --git a/Gemfile b/Gemfile index 3ec3defd1..4448a9840 100644 --- a/Gemfile +++ b/Gemfile @@ -161,12 +161,6 @@ source 'https://rails-assets.org' do gem 'rails-assets-moment', '~> 2.15.0' end -group :test do - gem 'fakeredis', git: 'https://github.com/artygus/fakeredis/', ref: 'f68bd4f' - gem 'minitest', '5.14.4' - gem 'rails-controller-testing' -end - group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' @@ -189,7 +183,8 @@ group :development do gem 'binding_of_caller' end -group :production do - gem 'unicorn' - gem 'passenger' +group :test do + gem 'fakeredis', git: 'https://github.com/artygus/fakeredis/', ref: 'f68bd4f' + gem 'minitest', '5.14.4' + gem 'rails-controller-testing' end diff --git a/Gemfile.lock b/Gemfile.lock index 8b8ab0cc9..2673362d0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -305,7 +305,6 @@ GEM activerecord kaminari-core (= 1.2.1) kaminari-core (1.2.1) - kgio (2.11.4) kt-paperclip (7.0.1) activemodel (>= 4.2.0) activesupport (>= 4.2.0) @@ -411,9 +410,6 @@ GEM parallel (1.21.0) parser (3.0.3.1) ast (~> 2.4.1) - passenger (6.0.12) - rack - rake (>= 0.8.1) pg (1.2.3) pr_geohash (1.0.0) private_address_check (0.5.0) @@ -488,7 +484,6 @@ GEM rake (>= 12.2) thor (~> 1.0) rainbow (3.0.0) - raindrops (0.20.0) rake (13.0.6) rb-fsevent (0.11.0) rb-inotify (0.10.1) @@ -698,9 +693,6 @@ GEM unicode-display_width (2.1.0) unicode-types (1.7.0) unicode_utils (1.4.0) - unicorn (6.1.0) - kgio (~> 2.6) - raindrops (~> 0.7) validate_email (0.1.6) activemodel (>= 3.0) mail (>= 2.2.5) @@ -774,7 +766,6 @@ DEPENDENCIES money-rails omniauth-rails_csrf_protection omniauth_openid_connect - passenger pg private_address_check progress_bar (~> 1.1.0) @@ -813,7 +804,6 @@ DEPENDENCIES tzinfo tzinfo-data uglifier (>= 1.3.0) - unicorn validate_url (~> 1.0.2) web-console webmock (~> 3.4.2) diff --git a/config/logrotate.conf b/config/logrotate.conf index 9c1e3678a..90d2af589 100644 --- a/config/logrotate.conf +++ b/config/logrotate.conf @@ -1,35 +1,4 @@ # configuration for logrotate - -"shared/log/logrotate.log" { - monthly - size 10M - missingok - notifempty - rotate 3 - copytruncate -} - -"shared/log/cron.log" { - weekly - size 10M - missingok - notifempty - rotate 4 - copytruncate -} - -"shared/log/unicorn.*.log" { - daily - size 50M - missingok - notifempty - rotate 3 - compress - delaycompress - copytruncate - nodateext -} - "log/*.log" { daily size 50M diff --git a/config/schedule.example.yml b/config/schedule.example.yml index 42a4cc874..e3a5715fd 100644 --- a/config/schedule.example.yml +++ b/config/schedule.example.yml @@ -8,9 +8,3 @@ subscriptions: ingestions: every: day at: '3am' -backups: - every: saturday - at: '12:30am' -logrotate: - every: day - at: '11pm' diff --git a/config/schedule.rb b/config/schedule.rb index 341c3e379..521c5e145 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -14,20 +14,6 @@ schedules ||= {} end -# check input parameters -set(:db_user, 'tess_user') if !defined?(db_user) -set :db_name, "tess_#{environment}" -set :bkup_script, "#{path}/scripts/pgsql_backup.sh" -set :bkup_folder, "#{path}/shared/backups" - -# set log file -FileUtils.mkdir_p("#{path}/shared/log") -set :log_folder, "#{path}/shared/log" -FileUtils.touch("#{log_folder}/cron.log") -unless ENV["RAILS_LOG_TO_STDOUT"] - set :output, "#{log_folder}/cron.log" -end - # Generate a new sitemap... if !schedules['sitemap'].nil? every :"#{schedules['sitemap']['every']}", at: "#{schedules['sitemap']['at']}" do @@ -60,25 +46,3 @@ rake "tess:automated_ingestion" end end - -# run database backups -if !schedules['backups'].nil? - every :"#{schedules['backups']['every']}", at: "#{schedules['backups']['at']}" do - command "#{bkup_script} #{db_user} #{db_name} #{bkup_folder} --exclude-schema=audit" - end -else - every :saturday, at: '12:30am' do - command "#{bkup_script} #{db_user} #{db_name} #{bkup_folder} --exclude-schema=audit" - end -end - -# run log rotation -if !schedules['logrotate'].nil? - every :"#{schedules['logrotate']['every']}", at: "#{schedules['logrotate']['at']}" do - command "/usr/sbin/logrotate -f #{path}/config/logrotate.conf -s #{log_folder}/logrotate.log" - end -else - every :day, at: '11pm' do - command "/usr/sbin/logrotate -f #{path}/config/logrotate.conf -s #{log_folder}/logrotate.log" - end -end diff --git a/config/unicorn.rb b/config/unicorn.rb deleted file mode 100644 index fb73f0d68..000000000 --- a/config/unicorn.rb +++ /dev/null @@ -1,20 +0,0 @@ -# set path to application -app_dir = File.expand_path("../..", __FILE__) -shared_dir = "#{app_dir}/shared" -working_directory app_dir - - -# Set unicorn options -worker_processes 2 -preload_app true -timeout 30 - -# Set up socket location -listen "#{shared_dir}/sockets/unicorn.sock", :backlog => 64 - -# Logging -stderr_path "#{shared_dir}/log/unicorn.stderr.log" -stdout_path "#{shared_dir}/log/unicorn.stdout.log" - -# Set master PID location -pid "#{shared_dir}/pids/unicorn.pid" diff --git a/scripts/pgsql_backup.sh b/scripts/pgsql_backup.sh deleted file mode 100644 index d26df07d6..000000000 --- a/scripts/pgsql_backup.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh - -# get username -if [ -z $1 ] -then - echo "Enter the username:" - read USERNAME -else - USERNAME=$1 -fi - -# get database name -if [ -z $2 ] -then - echo "Enter the database name:" - read DBNAME -else - DBNAME=$2 -fi - -# get schema file name -if [ -z $3 ] -then - echo "Enter the backup folder name:" - read FOLDER -else - FOLDER=$3 -fi - -# extra params on data file -if [ -z $4 ] -then - echo "Extra params on data file:" - read EXTRA -else - EXTRA=$4 -fi - -# run postgresql dumps for schema and data -pg_dump --host=localhost --username=$USERNAME --schema-only $DBNAME > $FOLDER/$DBNAME.$(date +%Y%m%d-%H%M%S).schema.sql -pg_dump --host=localhost --username=$USERNAME --data-only --disable-triggers $EXTRA $DBNAME > $FOLDER/$DBNAME.$(date +%Y%m%d-%H%M%S).data.sql - -# --- end of file --- # diff --git a/scripts/pgsql_restore.sh b/scripts/pgsql_restore.sh deleted file mode 100644 index 9679b3eec..000000000 --- a/scripts/pgsql_restore.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/sh - -# Description: Restore a PostgreSQL database from schema and data dump files -# -# Author: Fabio Agostinho Boris -# github.com/fabioboris -# -# Creation: 2013-05-08 - -# get username -if [ -z $1 ] -then - echo "Enter the username:" - read USERNAME -else - USERNAME=$1 -fi - -# get new database name -if [ -z $2 ] -then - echo "Enter the new database name:" - read DBNAME -else - DBNAME=$2 -fi - -# get schema file name -if [ -z $3 ] -then - echo "Enter the schema file name:" - read SCHEMA -else - SCHEMA=$3 -fi - -# get data file name -if [ -z $4 ] -then - echo "Enter the data file name:" - read DATA -else - DATA=$4 -fi - -echo "drop database $DBNAME;" | psql --host=localhost --username=$USERNAME template1 -echo "create database $DBNAME with encoding 'utf8';" | psql --host=localhost --username=$USERNAME template1 - -psql --host=localhost --username=$USERNAME $DBNAME < $SCHEMA -psql --host=localhost --username=$USERNAME $DBNAME < $DATA diff --git a/scripts/update_tess.sh b/scripts/update_tess.sh new file mode 100755 index 000000000..bd76f0b12 --- /dev/null +++ b/scripts/update_tess.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# echo "Usage: update.sh " +# exit 0 +if [ -z $1 ] +then + ENV=$1 +else + ENV="development" +fi + +export RAILS_ENV=$ENV + +# rebuild rails environment +git pull +bundle install --deployment +bundle exec rake db:migrate +bundle exec rake sunspot:solr:reindex +bundle exec rake assets:cleans +bundle exec rake assets:precompile +bundle exec rake tmp:clear +# update scheduled tasks +whenever --update-crontab --set environment="$ENV" + +# restart services +touch tmp/restart.txt +pkill -f sidekiq +bundle exec sidekiq -d -e "$ENV" -L /tmp/sidekiq.log + diff --git a/update_tess.sh b/update_tess.sh deleted file mode 100644 index 15558abb5..000000000 --- a/update_tess.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh - -# echo "Usage: update.sh " -# exit 0 -if [ -z $1 ] -then - ENV=$1 -else - ENV="development" -fi - -# stop services -sudo service nginx stop -sudo service unicorn_tess stop - -# backup database -sudo sh ./scripts/pgsql_backup.sh postgres tess_$ENV ./shared/backups --exclude-schema=audit - -# rebuild rails environment -#git pull origin master -bundle install -bundle exec rake db:migrate RAILS_ENV="$ENV" -bundle exec rake assets:clean RAILS_ENV="$ENV" -bundle exec rake assets:precompile RAILS_ENV="$ENV" -bundle exec rake sunspot:solr:reindex RAILS_ENV="$ENV" -# run tests -bundle exec rake db:migrate RAILS_ENV=test -bundle exec rake db:setup RAILS_ENV=test -bundle exec rake db:test:prepare -bundle exec rails test - -# restart sidekiq -sudo touch tmp/restart.txt -pkill -f sidekiq -bundle exec sidekiq -d -e "$ENV" -L /tmp/sidekiq.log - - -# update scheduled tasks -whenever --update-crontab --set environment="$ENV" - -# restart logrotate -sudo service logrotate restart - -# start services -sudo service unicorn_tess start -sudo service nginx start -#-- end of file --#