This is an automated script to help you setup new server and deploy Rails application along with database dump.
Ubuntu 16.04 or newer
- Execute within your rails app directory:
git clone git@github.com:Freika/rails_server.git server
- Open file
server/hosts
and replace values with your own. User and database passwords should be encrypted. Don't forget to provideyandex_disk_access_token
for backups, use this guide. It requires to allow access to Yandex Disk REST API AND Yandex Disk WebDAB API. - Update
server/roles/nginx/templates/nginx_virtual_host
with your domain. - Place you postgres database dump at
server/app_name.sql
. Dump must be created with following command:pg_dump --no-owner app_name > app_name.sql -U DB_USERNAME
- Update IP address of your server in
config/deploy/production.rb
and set user value todeploy
. - Install roles from ansible-galaxy:
ansible-galaxy install manala.git manala.zsh mashimom.oh-my-zsh pgolm.monit geerlingguy.passenger DavidWittman.redis rvm_io.rvm1-ruby ANXS.postgresql kamaln7.swapfile
Create file hosts
in root directory of ansible script. Here is an example:
[rails]
IP_ADDRESS # Your server IP address
[rails:vars]
app_name=APP_NAME # Your application name
user_password=PASSWORD # Password for user deploy, encrypted in md5
monit_user=MONIT_USERNAME # Username for monit
monit_password=MONIT_PASSWORD # Password for monit, plain text
ruby_version=2.3.1 # Ruby version
gmail_user=user@gmail.com # Gmail account email for monit notifications
gmail_password=GMAIL_PASSWORD # Gmail account password for monit notifications
monit_allowed_ip=0.0.0.0 # Allowed IP for monit sign in
postgres_password=00000000 # Your app database password (for database.yml)
Run
ansible-playbook server/python.yml server/server.yml server/app.yml -i server/hosts
This script goes through full server configuration process. For now it does next things (in order of applying):
- Installs Python2 in order to allow Ansible do all the work
- Installs pip, python packet manager
- Creates
deploy
user which is our main user for application deployments - Configures
zsh
andoh-my-zsh
for bothroot
anddeploy
users - Installs
vim
andhtop
- Installs
monit
for server state monitoring and notifications (RAM, HDD, etc) - Installs
nginx
withpassenger
to serve your Rails applications - Installs
Redis
- Installs
Ruby
- Installs
PostgreSQL
- Configures Nginx to server your Rails application
- Creates PostgreSQL database and user for your Rails application
- Uploads database dump and restores it on server
- Setups daily DB backups with uploading to Yandex Disk
Run cap production deploy
to start deployment process. If it failed because if not found active support 5, just run it one more time.
Just run steps from 2 to 5 from Usage. You'll also want to update files from Preparation as appropriate.
- Setup Fail2ban