Manual install of cobudget-api


The server will be set up to use blue/green deployments. This will done by making two directories, incidentally named blue and green and set a symbolic link current that points to the current release in production.
A new release can then be prepared in the directory not currently in use and the change can happen almost instantanously.
Rollback to the previous version can happen equally fast (if there are no incompatible database changes).

First time install

Create directories, adjust permissions and clone the cobudget-api github repo.
cd /opt
sudo mkdir cobudget-api
sudo chown ubuntu cobudget-api
cd cobudget-api
mkdir green
git clone blue
ln -s /opt/cobudget-api/blue current
Get the env and start files and copy to the installed dir
git clone
cp aws-deploy/env aws-deploy/start /opt/cobudget-api/current
Now edit the env and env-vars file. The database variable could be
Install missing Postgresql dev files and install all packages
sudo apt-get install postgresql-common libpq-dev
/usr/local/lib/ruby-2.4.0/bin/bundle install

Brief notes on new deployment

  • Remove the unused blue of green dir
  • Clone the api repo into the unused blue or green dir
  • Copy env , env-vars , start and config/database.yml to the new dir
If there's a DB update, dumb the DB before the update, do the update and dump it again after. Just to be sure.
export PATH=$PATH:/usr/local/lib/ruby-2.4.0/bin
. ./env
pg_dump -h -U cobudget -d cobudget_prod >cobudget-prod-<yymmdd>-before-update
bundle exec rake db:migrate
pg_dump -h -U cobudget -d cobudget_prod >cobudget-prod-<yymmdd>-after-update
And finally, change the symlink and restart the service
rm current; ln -s /opt/cobudget-api/blue/ current
sudo systemctl restart cobudget-api

Running with systemd

Copy the systemd config files
sudo cp aws-deploy/cobudget-* /etc/systemd/system
Get systemd to read the file, start the server and enable for automatic start at boot
sudo systemctl daemon-reload
sudo systemctl start cobudget-api
sudo systemctl start cobudget-dj
sudo systemctl start cobudget-digestemail.timer
sudo systemctl enable cobudget-api
sudo systemctl enable cobudget-dj
sudo systemctl enable cobudget-digestemail.timer
You can check if the server has started with
sudo systemctl status cobudget-api.service
sudo systemctl status cobudget-dj.service
sudo systemctl status cobudget-digestemail.timer
Copy link
On this page
First time install
Brief notes on new deployment
Running with systemd