Обслуживание RoR приложения на сервере

В этой заметке будет описано резервное копирование и мониторинг приложения.

sudo apt-get install monit

sudo nano /etc/monit/monitrc

  set httpd port 2812 and
      allow admin:monit


sudo nano /etc/monit/conf.d/keys

#== Nginx ==#
check process nginx with pidfile /var/run/nginx.pid
  start program = "/etc/init.d/nginx start"
  stop program = "/etc/init.d/nginx stop"
  if cpu > 60% for 2 cycles then alert
  if cpu > 80% for 5 cycles then restart
  if memory usage > 80% for 5 cycles then restart
  if failed host 127.0.0.1 port 80 protocol http
    then restart
  if 3 restarts within 5 cycles then timeout

#== Postgresql ==#
check process postgresql
  with pidfile "/var/run/postgresql/9.4-main.pid"
  start program = "/usr/sbin/service postgresql start"
  stop  program = "/usr/sbin/service postgresql stop"
  if failed host localhost port 5432 protocol pgsql then restart
  if cpu > 80% then restart
  if memory usage > 80% for 2 cycles then restart
  if 5 restarts within 5 cycles then timeout

Backup:

На сервере:

gem install backup

backup generate:model -t kalibr_backup --databases='postgresql' --storages='local' --compressor='gzip'

mcedit Backup/models/kalibr_backup.rb



# encoding: utf-8

##
# Backup Generated: kalibr_backup
# Once configured, you can run the backup with the following command:
#
# $ backup perform -t kalibr_backup [-c <path_to_configuration_file>]
#
# For more information about Backup's components, see the documentation at:
# http://meskyanichi.github.io/backup
#
Model.new(:kalibr_backup, 'Description for kalibr_backup') do

  ##
  # PostgreSQL [Database]
  #
  database PostgreSQL do |db|
    # To dump all databases, set `db.name = :all` (or leave blank)
    db.name               = "DATABASE"
    db.username           = "USER"
    db.password           = "PASS_HERE"
    db.host               = "localhost"
    db.port               = 5432
    #db.socket             = "/tmp/pg.sock"
    # When dumping all databases, `skip_tables` and `only_tables` are ignored.
    #db.skip_tables        = ["skip", "these", "tables"]
    #db.only_tables        = ["only", "these", "tables"]
    db.additional_options = ["-xc", "-E=utf8"]
  end

  ##
  # Local (Copy) [Storage]
  #
  store_with Local do |local|
    local.path       = "~/backups/"
    local.keep       = 15
  end

  ##
  # Gzip [Compressor]
  #
  compress_with Gzip

end



backup check

backup perform -t kalibr_backup


gem install whenever

mkdir ~/Backup/config
cd ~/Backup
wheneverize .
mcedit ./config/schedule.rb


every 1.day, at: '6.30 am' do
  command 'backup perform -t kalibr_backup'
end

whenever --update-crontab

crontab -l
Поделиться Комментарии