- 1st, add production origin to git.
- Next, ssh to remote and do a git init
- Then on local git:
- git pull production master
- git push production master
ln -s /home/username/rails/production /home/username/rails/current
mkdir -p ~/rails/shared/config
mkdir -p ~/rails/shared/log
mkdir -p ~/rails/shared/vendor/bundle
mkdir -p ~/rails/shared/log
mkdir -p ~/rails/shared/tmp/pids
mkdir -p ~/rails/shared/tmp/cache
mkdir -p ~/rails/shared/tmp/sockets
- upload secrets.yml, elasticsearch.yml to ~/rails/shared/config/
- make sure not to commit config/secrets.yml into git, remove it if you have done so, use this:
git rm --cached config/secrets.yml# back this file 1st to somewhere ele
# add this to gitignore
config/secrets.yml
- Next, add user to /etc/group, find for line with "sudo" and add the user at the end of the line, separated by comma.
- Next, setting up ruby on rails, install rvm first. Then:
rvm install 2.3.3
rvm use 2.3.3
gem install bundler
gem install puma
- Next, goto rails root directory:
cd ~/rails/current
rvm 2.3.3 do bundle install --deployment --without development test
- Then run load schema, seeds and then migration
export RAILS_ENV=production
rvm 2.3.3 do bin/rake db:schema:load
rvm 2.3.3 do bin/rake db:migrate
rvm 2.3.3 do bin/rake db:seed
- then setup cronjob to restart instance every nightly:
crontab -e
0 1 * * * bash -lc 'cd /home/username/rails/current && rvm 2.3.3 do bundle exec pumactl -P tmp/pids/puma.pid phased-restart'
- then setup rc.local to auto start instance when rebooted / booted (follow instruction in file)
- then setup nginx to proxy application onto rails backend
mkdir -p ~/log
- create the file nginx-[domainname].conf to /etc/nginx/sites-enabled
service nginx restart
-
and finally, setup /etc/logrotate.d/rails to auto clean up your log/production.log
-
that is all :), simply git commit, then git push production master, and the .git/hook/post-receive will do it's job